Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchResponseConvertorTest.java
index c945cd4c8ad97b0d3dfcca06e27feb419301c4ef..623f6d70569114d18baacba572dce8907786f774 100644 (file)
@@ -5,13 +5,11 @@
  * 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.openflow.md.core.sal.convertor.match;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
@@ -21,7 +19,6 @@ import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
-import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
@@ -38,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthD
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchEntriesGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
@@ -56,12 +54,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 /**
  * Unit test for {@link MatchConvertorImpl}.
  */
 public class MatchResponseConvertorTest {
-    private static final BigInteger DPID = BigInteger.TEN;
+    private static final Uint64 DPID = Uint64.valueOf(10);
     private static final Long IN_PORT = 6L;
     private static final String URI_IN_PORT =
             "openflow:" + DPID + ":" + IN_PORT;
@@ -81,83 +80,77 @@ public class MatchResponseConvertorTest {
 
     @Before
     public void setUp() {
-        OpenflowPortsUtil.init();
         convertorManager = ConvertorManagerFactory.createDefaultManager();
     }
 
     /**
-     * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchEntriesGrouping, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} }.
+     * Test method for {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)} }.
      */
     @Test
     public void testFromOFMatchToSALMatch() {
         List<MatchEntry> entries = createDefaultMatchEntry();
 
         int[] vids = {
-                // Match packet with VLAN tag regardless of its value.
-                -1,
+            // Match packet with VLAN tag regardless of its value.
+            -1,
 
-                // Match untagged frame.
-                0,
+            // Match untagged frame.
+            0,
 
-                // Match packet with VLAN tag and VID equals the specified value.
-                1, 20, 4095,
+            // Match packet with VLAN tag and VID equals the specified value.
+            1, 20, 4095,
         };
 
         for (int vid : vids) {
-            List<MatchEntry> MatchEntry =
-                    new ArrayList<MatchEntry>(entries);
-            MatchEntry.add(toOfVlanVid(vid));
+            List<MatchEntry> matchEntry = new ArrayList<>(entries);
+            matchEntry.add(toOfVlanVid(vid));
             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match ofMatch =
-                    createOFMatch(MatchEntry);
+                    createOFMatch(matchEntry);
 
             final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
             data.setDatapathId(DPID);
             final MatchBuilder builder = convert(ofMatch, data);
             checkDefault(builder);
             VlanMatch vlanMatch = builder.getVlanMatch();
-            int expectedVid = (vid < 0) ? 0 : vid;
+            int expectedVid = vid < 0 ? 0 : vid;
             Boolean expectedCfi = vid != 0;
-            assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().
-                    getValue().intValue());
+            assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
             assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
             assertEquals(null, vlanMatch.getVlanPcp());
         }
     }
 
     /**
-     * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} }.
+     * Test method for {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)} }.
      */
     @Test
     public void testFromOFMatchV10ToSALMatch() {
         int[] vids = {
-                // Match untagged frame.
-                DL_VLAN_NONE,
+            // Match untagged frame.
+            DL_VLAN_NONE,
 
-                // Match packet with VLAN tag and VID equals the specified value.
-                1, 20, 4095,
-        };
-        short[] dscps = {
-                0, 1, 20, 40, 62, 63,
+            // Match packet with VLAN tag and VID equals the specified value.
+            1, 20, 4095,
         };
+        short[] dscps = { 0, 1, 20, 40, 62, 63, };
 
         FlowWildcardsV10Builder wcBuilder = new FlowWildcardsV10Builder();
         for (int vid : vids) {
             for (short dscp : dscps) {
                 short tos = (short) (dscp << 2);
                 MatchV10Builder builder = new MatchV10Builder();
-                builder.setDlSrc(MAC_SRC).setDlDst(MAC_DST).setDlVlan(vid).
-                        setDlVlanPcp(VLAN_PCP).setDlType(ETHTYPE_IPV4).
-                        setInPort(IN_PORT.intValue()).
-                        setNwSrc(IPV4_SRC).setNwDst(IPV4_DST).setNwTos(tos);
-                wcBuilder.setAll(false).setNwProto(true).setTpSrc(true).
-                        setTpDst(true);
+                builder.setDlSrc(MAC_SRC).setDlDst(MAC_DST).setDlVlan(vid).setDlVlanPcp(VLAN_PCP)
+                        .setDlType(ETHTYPE_IPV4).setInPort(IN_PORT.intValue()).setNwSrc(IPV4_SRC).setNwDst(IPV4_DST)
+                        .setNwTos(tos);
+                wcBuilder.setAll(false).setNwProto(true).setTpSrc(true).setTpDst(true);
                 if (vid == DL_VLAN_NONE) {
                     wcBuilder.setDlVlanPcp(true);
                 }
 
                 FlowWildcardsV10 wc = wcBuilder.build();
                 MatchV10 ofMatch = builder.setWildcards(wc).build();
-                final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
+                final VersionDatapathIdConvertorData data =
+                        new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
                 data.setDatapathId(DPID);
                 Match match = convert(ofMatch, data).build();
                 checkDefaultV10(match, wc, vid);
@@ -183,18 +176,17 @@ public class MatchResponseConvertorTest {
         assertEquals(null, ethMatch.getEthernetSource().getMask());
         assertEquals(MAC_DST, ethMatch.getEthernetDestination().getAddress());
         assertEquals(null, ethMatch.getEthernetDestination().getMask());
-        assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().
-                getValue().intValue());
+        assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().getValue().intValue());
 
         NodeConnectorId inPort = builder.getInPort();
         assertEquals(URI_IN_PORT, inPort.getValue());
     }
 
-    private static org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match createOFMatch(final List<MatchEntry> entries) {
+    private static org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match
+            createOFMatch(final List<MatchEntry> entries) {
         org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder builder =
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder();
-        return builder.setType(OxmMatchType.class).setMatchEntry(entries).
-                build();
+        return builder.setType(OxmMatchType.class).setMatchEntry(entries).build();
     }
 
     private static List<MatchEntry> createDefaultMatchEntry() {
@@ -259,7 +251,6 @@ public class MatchResponseConvertorTest {
         byte[] mask = null;
         builder.setOxmClass(OpenflowBasicClass.class);
         builder.setOxmMatchField(VlanVid.class);
-        VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
         if (vid == 0) {
             // Match untagged frame.
             cfi = false;
@@ -276,6 +267,7 @@ public class MatchResponseConvertorTest {
         if (hasMask) {
             vlanVidBuilder.setMask(mask);
         }
+        VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
         vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
         builder.setHasMask(hasMask);
         builder.setMatchEntryValue(vlanVidCaseBuilder.build());
@@ -309,8 +301,7 @@ public class MatchResponseConvertorTest {
             assertEquals(null, match.getLayer3Match());
         } else {
             assert ethMatch != null;
-            assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().
-                    getValue().intValue());
+            assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().getValue().intValue());
 
             Ipv4Match ipv4Match = (Ipv4Match) match.getLayer3Match();
             assertEquals(IPV4_SRC.getValue() + "/32",
@@ -332,8 +323,7 @@ public class MatchResponseConvertorTest {
                 expectedVid = vid;
                 expectedCfi = Boolean.TRUE;
             }
-            assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().
-                    getValue().intValue());
+            assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
             assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
 
             if (wc.isDLVLANPCP()) {
@@ -345,13 +335,15 @@ public class MatchResponseConvertorTest {
         }
     }
 
-    private MatchBuilder convert(MatchV10 match, VersionDatapathIdConvertorData data) {
+    private MatchBuilder convert(final MatchV10 match, final VersionDatapathIdConvertorData data) {
         final Optional<MatchBuilder> salMatchOptional = convertorManager.convert(match, data);
 
         return salMatchOptional.orElse(new MatchBuilder());
     }
 
-    private MatchBuilder convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match match, VersionDatapathIdConvertorData data) {
+    private MatchBuilder convert(
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match match,
+            final VersionDatapathIdConvertorData data) {
         final Optional<MatchBuilder> salMatchOptional = convertorManager.convert(match, data);
 
         return salMatchOptional.orElse(new MatchBuilder());