Use Java declarations instead of Google Collections
[netvirt.git] / vpnservice / aclservice / impl / src / test / java / org / opendaylight / netvirt / aclservice / utils / AclServiceOFFlowBuilderTest.java
index 091a609ddb41d58ca038436c1b38673dca75cf06..a65bf08378dde7074ed1bc38d44a46997f9ba08e 100644 (file)
@@ -8,24 +8,22 @@
 
 package org.opendaylight.netvirt.aclservice.utils;
 
-import static com.google.common.collect.Iterables.filter;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
-
-import com.google.common.collect.Iterables;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-
+import java.util.stream.Collectors;
 import org.junit.Test;
-import org.opendaylight.genius.mdsalutil.MatchFieldType;
-import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
-import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
 import org.opendaylight.genius.mdsalutil.NxMatchInfo;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
+import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
+import org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4;
+import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination;
+import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -35,9 +33,7 @@ public class AclServiceOFFlowBuilderTest {
 
     @Test
     public void testProgramIpFlow_NullMatches() {
-        Matches matches = null;
-        Map<String, List<MatchInfoBase>> flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
-        assertNull(flowMap);
+        assertNull(AclServiceOFFlowBuilder.programIpFlow(null));
     }
 
     @Test
@@ -59,10 +55,14 @@ public class AclServiceOFFlowBuilderTest {
 
         AclServiceTestUtils.verifyGeneralFlows(flowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
 
-        Iterable<MatchInfoBase> icmpv4Matches = filter(flowMatches,
-                (item -> ((MatchInfo) item).getMatchField().equals(MatchFieldType.icmp_v4)));
-        AclServiceTestUtils.verifyMatchValues((MatchInfo) Iterables.get(icmpv4Matches, 0), "1024", "2048");
-        AclServiceTestUtils.verifyMatchValues((MatchInfo) Iterables.get(icmpv4Matches, 1), "4096", "8192");
+        int matches = 0;
+        MatchIcmpv4 check = new MatchIcmpv4((short) 1024, (short) 2048);
+        for (MatchInfoBase flowMatch : flowMatches) {
+            if (check.equals(flowMatch)) {
+                matches++;
+            }
+        }
+        assertEquals(2, matches);
     }
 
     @Test
@@ -85,8 +85,8 @@ public class AclServiceOFFlowBuilderTest {
 
         Map<String, List<MatchInfoBase>> flowMatchesMap = AclServiceOFFlowBuilder.programTcpFlow(builder.build());
 
-        List<MatchInfoBase> srcFlowMatches = new ArrayList<MatchInfoBase>();
-        List<MatchInfoBase> dstFlowMatches = new ArrayList<MatchInfoBase>();
+        List<MatchInfoBase> srcFlowMatches = new ArrayList<>();
+        List<MatchInfoBase> dstFlowMatches = new ArrayList<>();
 
         for (String flowId : flowMatchesMap.keySet()) {
             if (flowId.startsWith("TCP_SOURCE_")) {
@@ -98,20 +98,18 @@ public class AclServiceOFFlowBuilderTest {
         }
 
         AclServiceTestUtils.verifyGeneralFlows(srcFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
-        Iterable<MatchInfoBase> nxSrcMatches = filter(srcFlowMatches,
-            (item -> item instanceof NxMatchInfo) );
-        Iterable<MatchInfoBase> tcpSrcMatches = filter(nxSrcMatches,
-                (item -> ((NxMatchInfo) item).getMatchField().equals(NxMatchFieldType.nx_tcp_src_with_mask)));
+        List<MatchInfoBase> tcpSrcMatches = srcFlowMatches.stream().filter(
+            item -> item instanceof NxMatchInfo && ((NxMatchInfo) item).getMatchField().equals(
+                        NxMatchFieldType.nx_tcp_src_with_mask)).collect(Collectors.toList());
 
-        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) Iterables.getFirst(tcpSrcMatches, null), "1024", "65535");
+        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) tcpSrcMatches.get(0), "1024", "65535");
 
         AclServiceTestUtils.verifyGeneralFlows(dstFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
-        Iterable<MatchInfoBase> nxDstMatches = filter(dstFlowMatches,
-            (item -> item instanceof NxMatchInfo) );
-        Iterable<MatchInfoBase> tcpDstMatches = filter(nxDstMatches,
-                (item -> ((NxMatchInfo) item).getMatchField().equals(NxMatchFieldType.nx_tcp_dst_with_mask)));
+        List<MatchInfoBase> tcpDstMatches = dstFlowMatches.stream().filter(
+            item -> item instanceof NxMatchInfo && ((NxMatchInfo) item).getMatchField().equals(
+                        NxMatchFieldType.nx_tcp_dst_with_mask)).collect(Collectors.toList());
 
-        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) Iterables.getFirst(tcpDstMatches, null), "1024", "65535");
+        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) tcpDstMatches.get(0), "1024", "65535");
     }
 
     @Test
@@ -141,8 +139,8 @@ public class AclServiceOFFlowBuilderTest {
                 (short) 1);
 
         Map<String, List<MatchInfoBase>> flowMatchesMap = AclServiceOFFlowBuilder.programUdpFlow(builder.build());
-        List<MatchInfoBase> srcFlowMatches = new ArrayList<MatchInfoBase>();
-        List<MatchInfoBase> dstFlowMatches = new ArrayList<MatchInfoBase>();
+        List<MatchInfoBase> srcFlowMatches = new ArrayList<>();
+        List<MatchInfoBase> dstFlowMatches = new ArrayList<>();
 
         for (String flowId : flowMatchesMap.keySet()) {
             if (flowId.startsWith("UDP_SOURCE_")) {
@@ -155,19 +153,17 @@ public class AclServiceOFFlowBuilderTest {
 
         AclServiceTestUtils.verifyGeneralFlows(srcFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
 
-        Iterable<MatchInfoBase> nxSrcMatches = filter(srcFlowMatches,
-            (item -> item instanceof NxMatchInfo) );
-        Iterable<MatchInfoBase> udpSrcMatches = filter(nxSrcMatches,
-                (item -> ((NxMatchInfo) item).getMatchField().equals(NxMatchFieldType.nx_udp_src_with_mask)));
-        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) Iterables.getFirst(udpSrcMatches, null), "1024", "65535");
+        List<MatchInfoBase> udpSrcMatches = srcFlowMatches.stream().filter(
+            item -> item instanceof NxMatchInfo && ((NxMatchInfo) item).getMatchField().equals(
+                        NxMatchFieldType.nx_udp_src_with_mask)).collect(Collectors.toList());
+        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) udpSrcMatches.get(0), "1024", "65535");
 
         AclServiceTestUtils.verifyGeneralFlows(dstFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
 
-        Iterable<MatchInfoBase> nxDstMatches = filter(dstFlowMatches,
-            (item -> item instanceof NxMatchInfo) );
-        Iterable<MatchInfoBase> udpDstMatches = filter(nxDstMatches,
-                (item -> ((NxMatchInfo) item).getMatchField().equals(NxMatchFieldType.nx_udp_dst_with_mask)));
-        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) Iterables.getFirst(udpDstMatches, null), "1024", "65535");
+        List<MatchInfoBase> udpDstMatches = dstFlowMatches.stream().filter(
+            item -> item instanceof NxMatchInfo && ((NxMatchInfo) item).getMatchField().equals(
+                        NxMatchFieldType.nx_udp_dst_with_mask)).collect(Collectors.toList());
+        AclServiceTestUtils.verifyMatchValues((NxMatchInfo) udpDstMatches.get(0), "1024", "65535");
     }
 
     @Test
@@ -179,9 +175,8 @@ public class AclServiceOFFlowBuilderTest {
 
         List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addDstIpMatches(builder.build());
 
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.eth_type,
-                Integer.toString(NwConstants.ETHTYPE_IPV4));
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.ipv4_destination, "10.1.1.1", "24");
+        assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
+        assertTrue(flowMatches.contains(new MatchIpv4Destination("10.1.1.1", "24")));
     }
 
     @Test
@@ -193,9 +188,8 @@ public class AclServiceOFFlowBuilderTest {
 
         List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addDstIpMatches(builder.build());
 
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.eth_type,
-                Integer.toString(NwConstants.ETHTYPE_IPV4));
-        AclServiceTestUtils.verifyMatchFieldTypeDontExist(flowMatches, MatchFieldType.ipv4_destination);
+        assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
+        AclServiceTestUtils.verifyMatchFieldTypeDontExist(flowMatches, MatchIpv4Destination.class);
     }
 
     @Test
@@ -207,9 +201,8 @@ public class AclServiceOFFlowBuilderTest {
 
         List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addSrcIpMatches(builder.build());
 
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.eth_type,
-                Integer.toString(NwConstants.ETHTYPE_IPV4));
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.ipv4_source, "10.1.1.1", "24");
+        assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
+        assertTrue(flowMatches.contains(new MatchIpv4Source("10.1.1.1", "24")));
     }
 
     @Test
@@ -220,9 +213,8 @@ public class AclServiceOFFlowBuilderTest {
         builder.setAceIpVersion(v4builder.build());
 
         List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addSrcIpMatches(builder.build());
-        AclServiceTestUtils.verifyMatchInfo(flowMatches, MatchFieldType.eth_type,
-                Integer.toString(NwConstants.ETHTYPE_IPV4));
-        AclServiceTestUtils.verifyMatchFieldTypeDontExist(flowMatches, MatchFieldType.ipv4_source);
+        assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
+        AclServiceTestUtils.verifyMatchFieldTypeDontExist(flowMatches, MatchIpv4Source.class);
     }
 
     @Test