Bug-5543 - Bo: Update JUnit tests part 10 94/40694/4
authormiroslav.macko <miroslav.macko@pantheon.tech>
Wed, 22 Jun 2016 11:48:30 +0000 (13:48 +0200)
committerMiroslav Macko <miroslav.macko@pantheon.tech>
Fri, 1 Jul 2016 07:44:18 +0000 (07:44 +0000)
Added tests for openflowplugin-extension-nicira

Change-Id: I5c0da125db63c49293e1f8b04dc63f9bcfb1161f
Signed-off-by: miroslav.macko <miroslav.macko@pantheon.tech>
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4DstConvertorTest.java [new file with mode: 0644]
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4SrcConvertorTest.java [new file with mode: 0644]
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIdConvertorTest.java [new file with mode: 0644]
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpDstConvertorTest.java [new file with mode: 0644]
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpSrcConvertorTest.java [new file with mode: 0644]

diff --git a/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4DstConvertorTest.java b/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4DstConvertorTest.java
new file mode 100644 (file)
index 0000000..0f96599
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.IpConverter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.dst.grouping.TunIpv4DstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4DstKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4DstBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIPv4DstConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIPv4DstConvertorTest {
+    @Mock
+    private Extension extension;
+    @Mock
+    private MatchEntry matchEntry;
+
+    private static final Ipv4Address IPV4_ADDRESS = Ipv4Address.getDefaultInstance("1.2.3.4");
+
+    private TunIPv4DstConvertor tunIPv4DstConvertor;
+
+    @Before
+    public void setUp() throws Exception {
+        final NxmNxTunIpv4DstBuilder nxmNxTunIpv4DstBuilder = new NxmNxTunIpv4DstBuilder()
+                .setIpv4Address(IPV4_ADDRESS);
+        final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+        nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunIpv4Dst(nxmNxTunIpv4DstBuilder.build());
+
+        final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+        when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+        tunIPv4DstConvertor = new TunIPv4DstConvertor();
+    }
+
+    @Test
+    public void testConvert() throws Exception {
+        final MatchEntry matchEntry = tunIPv4DstConvertor.convert(extension);
+        Assert.assertEquals(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS), ((TunIpv4DstCaseValue)matchEntry.getMatchEntryValue()).getTunIpv4DstValues().getValue().longValue());
+    }
+
+    @Test
+    public void testConvert1() throws Exception {
+        final TunIpv4DstValuesBuilder tunIpv4DstValuesBuilder = new TunIpv4DstValuesBuilder()
+                .setValue(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS));
+        final TunIpv4DstCaseValueBuilder tunIpv4DstCaseValueBuilder = new TunIpv4DstCaseValueBuilder()
+                .setTunIpv4DstValues(tunIpv4DstValuesBuilder.build());
+
+        final TunIpv4DstCaseValue tunIpv4DstCaseValue = tunIpv4DstCaseValueBuilder.build();
+
+        when(matchEntry.getMatchEntryValue()).thenReturn(tunIpv4DstCaseValue);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIPv4DstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+    }
+
+}
\ No newline at end of file
diff --git a/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4SrcConvertorTest.java b/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4SrcConvertorTest.java
new file mode 100644 (file)
index 0000000..a99e1e1
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.IpConverter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.src.grouping.TunIpv4SrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4SrcKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.src.grouping.NxmNxTunIpv4SrcBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIPv4SrcConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIPv4SrcConvertorTest {
+    @Mock
+    private Extension extension;
+    @Mock
+    private MatchEntry matchEntry;
+
+    private static final Ipv4Address IPV4_ADDRESS = Ipv4Address.getDefaultInstance("1.2.3.4");
+
+    private TunIPv4SrcConvertor tunIPv4DstConvertor;
+
+    @Before
+    public void setUp() throws Exception {
+        final NxmNxTunIpv4SrcBuilder nxmNxTunIpv4SrcBuilder = new NxmNxTunIpv4SrcBuilder()
+                .setIpv4Address(IPV4_ADDRESS);
+        final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+        nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunIpv4Src(nxmNxTunIpv4SrcBuilder.build());
+
+        final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+        when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+        tunIPv4DstConvertor = new TunIPv4SrcConvertor();
+    }
+
+    @Test
+    public void testConvert() throws Exception {
+        final MatchEntry matchEntry = tunIPv4DstConvertor.convert(extension);
+        Assert.assertEquals(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS), ((TunIpv4SrcCaseValue)matchEntry.getMatchEntryValue()).getTunIpv4SrcValues().getValue().longValue());
+    }
+
+    @Test
+    public void testConvert1() throws Exception {
+        final TunIpv4SrcValuesBuilder tunIpv4SrcValuesBuilder = new TunIpv4SrcValuesBuilder()
+                .setValue(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS));
+        final TunIpv4SrcCaseValueBuilder tunIpv4SrcCaseValueBuilder = new TunIpv4SrcCaseValueBuilder()
+                .setTunIpv4SrcValues(tunIpv4SrcValuesBuilder.build());
+
+        final TunIpv4SrcCaseValue tunIpv4SrcCaseValue = tunIpv4SrcCaseValueBuilder.build();
+
+        when(matchEntry.getMatchEntryValue()).thenReturn(tunIpv4SrcCaseValue);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIPv4DstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+        Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+    }
+
+}
\ No newline at end of file
diff --git a/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIdConvertorTest.java b/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIdConvertorTest.java
new file mode 100644 (file)
index 0000000..aa4c402
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIdConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIdConvertorTest {
+    @Mock
+    private Extension extension;
+    @Mock
+    private MatchEntry matchEntry;
+
+    private TunIdConvertor tunIdConvertor;
+
+    @Before
+    public void setUp() throws Exception {
+        final NxmNxTunIdBuilder nxmNxTunIdBuilder = new NxmNxTunIdBuilder()
+                .setValue(BigInteger.ONE);
+        final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+        nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunId(nxmNxTunIdBuilder.build());
+
+        final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+        when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+        tunIdConvertor = new TunIdConvertor();
+    }
+
+    @Test
+    public void testConvert() throws Exception {
+        final MatchEntry matchEntry = tunIdConvertor.convert(extension);
+        Assert.assertEquals(BigInteger.ONE, ((TunIdCaseValue)matchEntry.getMatchEntryValue()).getTunIdValues().getValue());
+    }
+
+    @Test
+    public void testConvert1() throws Exception {
+        final TunIdValuesBuilder tunIdValuesBuilder = new TunIdValuesBuilder()
+                .setValue(BigInteger.TEN);
+        final TunIdCaseValueBuilder tunIdCaseValueBuilder = new TunIdCaseValueBuilder()
+                .setTunIdValues(tunIdValuesBuilder.build());
+
+        final TunIdCaseValue tunIdCaseValue = tunIdCaseValueBuilder.build();
+
+        when(matchEntry.getMatchEntryValue()).thenReturn(tunIdCaseValue);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIdConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+        Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunId().getValue());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIdConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunId().getValue());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIdConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+        Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunId().getValue());
+        Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+    }
+
+}
\ No newline at end of file
diff --git a/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpDstConvertorTest.java b/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpDstConvertorTest.java
new file mode 100644 (file)
index 0000000..47eb73c
--- /dev/null
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.dst.grouping.UdpDstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDstBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link UdpDstConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class UdpDstConvertorTest {
+    @Mock
+    private Extension extension;
+    @Mock
+    private MatchEntry matchEntry;
+
+    private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+    private UdpDstConvertor udpDstConvertor;
+
+    @Before
+    public void setUp() throws Exception {
+        final NxmOfUdpDstBuilder nxmOfUdpDstBuilder = new NxmOfUdpDstBuilder()
+                .setMask(1)
+                .setPort(DEFAULT_PORT);
+        final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+        nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfUdpDst(nxmOfUdpDstBuilder.build());
+
+        final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+        when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+        udpDstConvertor = new UdpDstConvertor();
+    }
+
+    @Test
+    public void testConvert() throws Exception {
+        final MatchEntry matchEntry = udpDstConvertor.convert(extension);
+        Assert.assertEquals(Integer.valueOf(1), ((UdpDstCaseValue)matchEntry.getMatchEntryValue()).getUdpDstValues().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((UdpDstCaseValue)matchEntry.getMatchEntryValue()).getUdpDstValues().getPort());
+    }
+
+    @Test
+    public void testConvert1() throws Exception {
+        final UdpDstValuesBuilder udpDstValuesBuilder = new UdpDstValuesBuilder()
+                .setMask(2)
+                .setPort(DEFAULT_PORT);
+        final UdpDstCaseValueBuilder udpDstCaseValueBuilder = new UdpDstCaseValueBuilder()
+                .setUdpDstValues(udpDstValuesBuilder.build());
+
+        final UdpDstCaseValue udpDstCaseValue = udpDstCaseValueBuilder.build();
+
+        when(matchEntry.getMatchEntryValue()).thenReturn(udpDstCaseValue);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = udpDstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpDst().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpDst().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = udpDstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpDst().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpDst().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = udpDstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpDst().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpDst().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+    }
+
+}
\ No newline at end of file
diff --git a/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpSrcConvertorTest.java b/extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/UdpSrcConvertorTest.java
new file mode 100644 (file)
index 0000000..ce9d0ca
--- /dev/null
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.src.grouping.UdpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpSrcKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.src.grouping.NxmOfUdpSrcBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link UdpSrcConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class UdpSrcConvertorTest {
+    @Mock
+    private Extension extension;
+    @Mock
+    private MatchEntry matchEntry;
+
+    private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+    private UdpSrcConvertor udpSrcConvertor;
+
+    @Before
+    public void setUp() throws Exception {
+        final NxmOfUdpSrcBuilder nxmOfUdpSrcBuilder = new NxmOfUdpSrcBuilder()
+                .setMask(1)
+                .setPort(DEFAULT_PORT);
+        final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+        nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfUdpSrc(nxmOfUdpSrcBuilder.build());
+
+        final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+        when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+        udpSrcConvertor = new UdpSrcConvertor();
+    }
+
+    @Test
+    public void testConvert() throws Exception {
+        final MatchEntry matchEntry = udpSrcConvertor.convert(extension);
+        Assert.assertEquals(Integer.valueOf(1), ((UdpSrcCaseValue)matchEntry.getMatchEntryValue()).getUdpSrcValues().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((UdpSrcCaseValue)matchEntry.getMatchEntryValue()).getUdpSrcValues().getPort());
+    }
+
+    @Test
+    public void testConvert1() throws Exception {
+        final UdpSrcValuesBuilder udpSrcValuesBuilder = new UdpSrcValuesBuilder()
+                .setMask(2)
+                .setPort(DEFAULT_PORT);
+        final UdpSrcCaseValueBuilder udpSrcCaseValueBuilder = new UdpSrcCaseValueBuilder()
+                .setUdpSrcValues(udpSrcValuesBuilder.build());
+
+        final UdpSrcCaseValue udpSrcCaseValue = udpSrcCaseValueBuilder.build();
+
+        when(matchEntry.getMatchEntryValue()).thenReturn(udpSrcCaseValue);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = udpSrcConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = udpSrcConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+
+        final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = udpSrcConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+        Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+        Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+        Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+    }
+
+}
\ No newline at end of file