Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / TunIPv4SrcConvertorTest.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
10
11 import static org.mockito.Mockito.when;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Matchers;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
21 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
22 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.IpConverter;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.src.grouping.TunIpv4SrcValuesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValueBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4SrcKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.src.grouping.NxmNxTunIpv4SrcBuilder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37
38 /**
39  * Test for {@link TunIPv4SrcConvertor}.
40  */
41 @RunWith(MockitoJUnitRunner.class)
42 public class TunIPv4SrcConvertorTest {
43     @Mock
44     private Extension extension;
45     @Mock
46     private MatchEntry matchEntry;
47
48     private static final Ipv4Address IPV4_ADDRESS = Ipv4Address.getDefaultInstance("1.2.3.4");
49
50     private TunIPv4SrcConvertor tunIPv4DstConvertor;
51
52     @Before
53     public void setUp() throws Exception {
54         final NxmNxTunIpv4SrcBuilder nxmNxTunIpv4SrcBuilder = new NxmNxTunIpv4SrcBuilder()
55                 .setIpv4Address(IPV4_ADDRESS);
56         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
57                 new NxAugMatchNodesNodeTableFlowBuilder();
58         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunIpv4Src(nxmNxTunIpv4SrcBuilder.build());
59
60         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
61         when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
62             .thenReturn(extensionAugmentation);
63
64         tunIPv4DstConvertor = new TunIPv4SrcConvertor();
65     }
66
67     @Test
68     public void testConvert() throws Exception {
69         final MatchEntry converted = tunIPv4DstConvertor.convert(extension);
70         Assert.assertEquals(IpConverter.ipv4AddressToLong(IPV4_ADDRESS),
71                 ((TunIpv4SrcCaseValue) converted.getMatchEntryValue()).getTunIpv4SrcValues().getValue().longValue());
72     }
73
74     @Test
75     public void testConvert1() throws Exception {
76         final TunIpv4SrcValuesBuilder tunIpv4SrcValuesBuilder = new TunIpv4SrcValuesBuilder()
77                 .setValue(IpConverter.ipv4AddressToLong(IPV4_ADDRESS));
78         final TunIpv4SrcCaseValueBuilder tunIpv4SrcCaseValueBuilder = new TunIpv4SrcCaseValueBuilder()
79                 .setTunIpv4SrcValues(tunIpv4SrcValuesBuilder.build());
80
81         final TunIpv4SrcCaseValue tunIpv4SrcCaseValue = tunIpv4SrcCaseValueBuilder.build();
82
83         when(matchEntry.getMatchEntryValue()).thenReturn(tunIpv4SrcCaseValue);
84
85         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIPv4DstConvertor
86                 .convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
87         Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
88                 .getNxmNxTunIpv4Src().getIpv4Address());
89         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
90
91         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIPv4DstConvertor
92                 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
93         Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
94                 .getNxmNxTunIpv4Src().getIpv4Address());
95         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
96
97         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIPv4DstConvertor
98                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
99         Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
100                 .getNxmNxTunIpv4Src().getIpv4Address());
101         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
102
103         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = tunIPv4DstConvertor
104                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
105         Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
106                 .getNxmNxTunIpv4Src().getIpv4Address());
107         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
108     }
109 }