[ONOS-3494] Add test case for TCPFlags Criterion

Change-Id: I2575e52dc316039e528ff6216cec7c1d3195fe81
diff --git a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
index d86744d..56a6ff6 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
@@ -42,6 +42,7 @@
 import org.onosproject.net.PortNumber;
 
 import com.google.common.testing.EqualsTester;
+
 /**
  * Unit tests for the Criteria class and its subclasses.
  */
@@ -135,6 +136,24 @@
     Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
     Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
 
+
+    int tcpFlags1 =
+        Criterion.TCPFlags.NS.getValue() |
+        Criterion.TCPFlags.CWR.getValue() |
+        Criterion.TCPFlags.ECE.getValue() |
+        Criterion.TCPFlags.URG.getValue() |
+        Criterion.TCPFlags.ACK.getValue() |
+        Criterion.TCPFlags.PSH.getValue() |
+        Criterion.TCPFlags.RST.getValue() |
+        Criterion.TCPFlags.SYN.getValue();
+
+    int tcpFlags2 = tcpFlags1 |
+        Criterion.TCPFlags.FIN.getValue();
+
+    Criterion matchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
+    Criterion sameAsmatchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
+    Criterion matchTcpFlags2 = Criteria.matchTcpFlags(tcpFlags2);
+
     Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
     Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
     Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
@@ -174,28 +193,28 @@
     private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
     private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
     Criterion matchIpv6TargetAddr1 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
     Criterion sameAsMatchIpv6TargetAddr1 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
     Criterion matchIpv6TargetAddr2 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
 
     private static final String LL_MAC1 = "00:00:00:00:00:01";
     private static final String LL_MAC2 = "00:00:00:00:00:02";
     private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
     private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
     Criterion matchSrcLlAddr1 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
     Criterion sameAsMatchSrcLlAddr1 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
     Criterion matchSrcLlAddr2 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
     Criterion matchTargetLlAddr1 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
     Criterion sameAsMatchTargetLlAddr1 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
     Criterion matchTargetLlAddr2 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
 
     MplsLabel mpls1 = MplsLabel.mplsLabel(1);
     MplsLabel mpls2 = MplsLabel.mplsLabel(2);
@@ -219,13 +238,13 @@
         Criterion.IPv6ExthdrFlags.HOP.getValue() |
         Criterion.IPv6ExthdrFlags.UNREP.getValue();
     int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
-        Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
+            Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
     Criterion matchIpv6ExthdrFlags1 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
     Criterion sameAsMatchIpv6ExthdrFlags1 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
     Criterion matchIpv6ExthdrFlags2 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
 
     Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
     Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
@@ -242,8 +261,8 @@
     Criterion matchOchSignal2 =
             Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
 
-    final OduSignalId odu1 = oduSignalId(1, 80, new byte [] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
-    final OduSignalId odu2 = oduSignalId(3, 8, new byte [] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+    final OduSignalId odu1 = oduSignalId(1, 80, new byte[]{1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
+    final OduSignalId odu2 = oduSignalId(3, 8, new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
     Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1);
     Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1);
     Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2);
@@ -259,9 +278,9 @@
      * it to the proper type.
      *
      * @param criterion Criterion object to convert
-     * @param type Enumerated type value for the Criterion class
-     * @param clazz Desired Criterion class
-     * @param <T> The type the caller wants returned
+     * @param type      Enumerated type value for the Criterion class
+     * @param clazz     Desired Criterion class
+     * @param <T>       The type the caller wants returned
      * @return converted object
      */
     @SuppressWarnings("unchecked")
@@ -297,6 +316,7 @@
         assertThatClassIsImmutable(IPCriterion.class);
         assertThatClassIsImmutable(TcpPortCriterion.class);
         assertThatClassIsImmutable(UdpPortCriterion.class);
+        assertThatClassIsImmutable(TcpFlagsCriterion.class);
         assertThatClassIsImmutable(SctpPortCriterion.class);
         assertThatClassIsImmutable(IcmpTypeCriterion.class);
         assertThatClassIsImmutable(IcmpCodeCriterion.class);
@@ -395,8 +415,8 @@
         Criterion matchEthDst = Criteria.matchEthDst(mac1);
         EthCriterion ethCriterion =
                 checkAndConvert(matchEthDst,
-                        Criterion.Type.ETH_DST,
-                        EthCriterion.class);
+                                Criterion.Type.ETH_DST,
+                                EthCriterion.class);
         assertThat(ethCriterion.mac(), is(equalTo(mac1)));
     }
 
@@ -461,8 +481,8 @@
         Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
         VlanIdCriterion vlanIdCriterion =
                 checkAndConvert(matchVlanId,
-                        Criterion.Type.VLAN_VID,
-                        VlanIdCriterion.class);
+                                Criterion.Type.VLAN_VID,
+                                VlanIdCriterion.class);
         assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
     }
 
@@ -487,8 +507,8 @@
         Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
         VlanPcpCriterion vlanPcpCriterion =
                 checkAndConvert(matchVlanPcp,
-                        Criterion.Type.VLAN_PCP,
-                        VlanPcpCriterion.class);
+                                Criterion.Type.VLAN_PCP,
+                                VlanPcpCriterion.class);
         assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
     }
 
@@ -513,8 +533,8 @@
         Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
         IPDscpCriterion ipDscpCriterion =
                 checkAndConvert(matchIPDscp,
-                        Criterion.Type.IP_DSCP,
-                        IPDscpCriterion.class);
+                                Criterion.Type.IP_DSCP,
+                                IPDscpCriterion.class);
         assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
     }
 
@@ -539,8 +559,8 @@
         Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
         IPEcnCriterion ipEcnCriterion =
                 checkAndConvert(matchIPEcn,
-                        Criterion.Type.IP_ECN,
-                        IPEcnCriterion.class);
+                                Criterion.Type.IP_ECN,
+                                IPEcnCriterion.class);
         assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
     }
 
@@ -565,8 +585,8 @@
         Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
         IPProtocolCriterion ipProtocolCriterion =
                 checkAndConvert(matchIPProtocol,
-                        Criterion.Type.IP_PROTO,
-                        IPProtocolCriterion.class);
+                                Criterion.Type.IP_PROTO,
+                                IPProtocolCriterion.class);
         assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
     }
 
@@ -604,8 +624,8 @@
         Criterion matchIPDst = Criteria.matchIPDst(ip1);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIPDst,
-                        Criterion.Type.IPV4_DST,
-                        IPCriterion.class);
+                                Criterion.Type.IPV4_DST,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(equalTo(ip1)));
     }
 
@@ -617,8 +637,8 @@
         Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIpv6Src,
-                        Criterion.Type.IPV6_SRC,
-                        IPCriterion.class);
+                                Criterion.Type.IPV6_SRC,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(ipv61));
     }
 
@@ -630,8 +650,8 @@
         Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIPv6Dst,
-                        Criterion.Type.IPV6_DST,
-                        IPCriterion.class);
+                                Criterion.Type.IPV6_DST,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
     }
 
@@ -674,8 +694,8 @@
         Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
         TcpPortCriterion tcpPortCriterion =
                 checkAndConvert(matchTcpDst,
-                        Criterion.Type.TCP_DST,
-                        TcpPortCriterion.class);
+                                Criterion.Type.TCP_DST,
+                                TcpPortCriterion.class);
         assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
     }
 
@@ -713,8 +733,8 @@
         Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
         UdpPortCriterion udpPortCriterion =
                 checkAndConvert(matchUdpDst,
-                        Criterion.Type.UDP_DST,
-                        UdpPortCriterion.class);
+                                Criterion.Type.UDP_DST,
+                                UdpPortCriterion.class);
         assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
     }
 
@@ -729,6 +749,19 @@
                 .testEquals();
     }
 
+    // TcpFlagsCriterion class
+
+    /**
+     * Test the equals() method of the TcpFlagsCriterion class.
+     */
+    @Test
+    public void testTcpFlagsCriterionEquals() {
+        new EqualsTester()
+                .addEqualityGroup(matchTcpFlags1, sameAsmatchTcpFlags1)
+                .addEqualityGroup(matchTcpFlags2)
+                .testEquals();
+    }
+
     // SctpPortCriterion class
 
     /**
@@ -752,8 +785,8 @@
         Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
         SctpPortCriterion sctpPortCriterion =
                 checkAndConvert(matchSctpDst,
-                        Criterion.Type.SCTP_DST,
-                        SctpPortCriterion.class);
+                                Criterion.Type.SCTP_DST,
+                                SctpPortCriterion.class);
         assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
     }
 
@@ -911,7 +944,7 @@
     @Test
     public void testMatchIPv6NDTargetAddressMethod() {
         Criterion matchTargetAddress =
-            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+                Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
         IPv6NDTargetAddressCriterion targetAddressCriterion =
                 checkAndConvert(matchTargetAddress,
                                 Criterion.Type.IPV6_ND_TARGET,
@@ -940,11 +973,11 @@
     @Test
     public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
         Criterion matchSrcLlAddr =
-            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+                Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
         IPv6NDLinkLayerAddressCriterion srcLlCriterion =
                 checkAndConvert(matchSrcLlAddr,
-                        Criterion.Type.IPV6_ND_SLL,
-                        IPv6NDLinkLayerAddressCriterion.class);
+                                Criterion.Type.IPV6_ND_SLL,
+                                IPv6NDLinkLayerAddressCriterion.class);
         assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
     }
 
@@ -954,11 +987,11 @@
     @Test
     public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
         Criterion matchTargetLlAddr =
-            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+                Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
         IPv6NDLinkLayerAddressCriterion targetLlCriterion =
                 checkAndConvert(matchTargetLlAddr,
-                        Criterion.Type.IPV6_ND_TLL,
-                        IPv6NDLinkLayerAddressCriterion.class);
+                                Criterion.Type.IPV6_ND_TLL,
+                                IPv6NDLinkLayerAddressCriterion.class);
         assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
     }
 
@@ -988,8 +1021,8 @@
         Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
         MplsCriterion mplsCriterion =
                 checkAndConvert(matchMplsLabel,
-                        Criterion.Type.MPLS_LABEL,
-                        MplsCriterion.class);
+                                Criterion.Type.MPLS_LABEL,
+                                MplsCriterion.class);
         assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
     }
 
@@ -1025,10 +1058,10 @@
      */
     @Test
     public void testTunnelIdCriterionEquals() {
-       new EqualsTester()
-               .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
-               .addEqualityGroup(matchTunnelId2)
-               .testEquals();
+        new EqualsTester()
+                .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
+                .addEqualityGroup(matchTunnelId2)
+                .testEquals();
     }
 
     // IPv6ExthdrFlagsCriterion class
@@ -1039,11 +1072,11 @@
     @Test
     public void testMatchIPv6ExthdrFlagsMethod() {
         Criterion matchExthdrFlags =
-            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+                Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
         IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
                 checkAndConvert(matchExthdrFlags,
-                        Criterion.Type.IPV6_EXTHDR,
-                        IPv6ExthdrFlagsCriterion.class);
+                                Criterion.Type.IPV6_EXTHDR,
+                                IPv6ExthdrFlagsCriterion.class);
         assertThat(exthdrFlagsCriterion.exthdrFlags(),
                    is(equalTo(ipv6ExthdrFlags1)));
     }