Bug 1254 - OFP test coverage increase 52/8452/3
authorMartin Bobak <mbobak@cisco.com>
Mon, 30 Jun 2014 12:01:49 +0000 (14:01 +0200)
committerMartin Bobak <mbobak@cisco.com>
Mon, 30 Jun 2014 12:54:14 +0000 (14:54 +0200)
- FlowCreatorUtil is final with private constructor instead of being
abstract

Change-Id: I063f114279582598770c03e00c3e947c6ee7a4e8
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtil.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtilTest.java [new file with mode: 0644]

index 30b77fdf02425722aacebdfdc99c6199810218c3..bb07ee6ec5f69fe9977ee78d32298355dd4dce8d 100644 (file)
@@ -19,28 +19,33 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
 
-public abstract class FlowCreatorUtil {
-    
-    public static void setWildcardedFlowMatch(short version,MultipartRequestFlowBuilder flowBuilder){
-        if(version == OFConstants.OFP_VERSION_1_0){
+public final class FlowCreatorUtil {
+
+    private FlowCreatorUtil() {
+        throw new AssertionError("FlowCreatorUtil is not expected to be instantiated.");
+    }
+
+    public static void setWildcardedFlowMatch(short version, MultipartRequestFlowBuilder flowBuilder) {
+        if (version == OFConstants.OFP_VERSION_1_0) {
             flowBuilder.setMatchV10(createWildcardedMatchV10());
         }
-        if(version == OFConstants.OFP_VERSION_1_3){
+        if (version == OFConstants.OFP_VERSION_1_3) {
             flowBuilder.setMatch(createWildcardedMatch());
         }
     }
-    
-    public static void setWildcardedFlowMatch(short version,MultipartRequestAggregateBuilder flowBuilder){
-        if(version == OFConstants.OFP_VERSION_1_0){
-            flowBuilder.setMatchV10(createWildcardedMatchV10());
+
+    public static void setWildcardedFlowMatch(short version, MultipartRequestAggregateBuilder aggregateBuilder) {
+        if (version == OFConstants.OFP_VERSION_1_0) {
+            aggregateBuilder.setMatchV10(createWildcardedMatchV10());
         }
-        if(version == OFConstants.OFP_VERSION_1_3){
-            flowBuilder.setMatch(createWildcardedMatch());
+        if (version == OFConstants.OFP_VERSION_1_3) {
+            aggregateBuilder.setMatch(createWildcardedMatch());
         }
     }
 
     /**
      * Method creates openflow 1.0 format match, that can match all the flow entries.
+     *
      * @return
      */
     public static MatchV10 createWildcardedMatchV10() {
@@ -61,12 +66,10 @@ public abstract class FlowCreatorUtil {
         builder.setNwDst(new Ipv4Address("0.0.0.0"));
         builder.setTpSrc(0);
         builder.setTpDst(0);
-        
         return builder.build();
     }
-    
-    public static Match createWildcardedMatch(){
-        return new MatchBuilder().setType(OxmMatchType.class).build();
 
+    public static Match createWildcardedMatch() {
+        return new MatchBuilder().setType(OxmMatchType.class).build();
     }
 }
diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtilTest.java
new file mode 100644 (file)
index 0000000..8b6135b
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2014 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.openflow.md.util;
+
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.TestCase.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowplugin.openflow.md.OFConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+
+public class FlowCreatorUtilTest {
+
+    private static final MacAddress macAddress = new MacAddress("00:00:00:00:00:00");
+    private static final Ipv4Address ipv4Address = new Ipv4Address("0.0.0.0");
+
+    /**
+     * Test method for {@link FlowCreatorUtil#setWildcardedFlowMatch(short version, MultipartRequestFlowBuilder flowBuilder)}.
+     */
+    @Test
+    public void testSetWildcardedFlowMatch_1_0() {
+        MultipartRequestFlowBuilder multipartRequestFlowBuilder = new MultipartRequestFlowBuilder();
+        FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_0, multipartRequestFlowBuilder);
+        MultipartRequestFlow multipartRequestFlow = multipartRequestFlowBuilder.build();
+        assertMatch(multipartRequestFlow.getMatchV10());
+
+        multipartRequestFlowBuilder = new MultipartRequestFlowBuilder();
+        FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_3, multipartRequestFlowBuilder);
+        multipartRequestFlow = multipartRequestFlowBuilder.build();
+        assertMatch(multipartRequestFlow.getMatch());
+    }
+
+    /**
+     * Test method for {@link FlowCreatorUtil#setWildcardedFlowMatch(short version, MultipartRequestAggregateBuilder aggregateBuilder)}.
+     */
+    @Test
+    public void testSetWildcardedFlowMatch_() {
+        MultipartRequestAggregateBuilder multipartRequestAggregateBuilder = new MultipartRequestAggregateBuilder();
+        FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_0, multipartRequestAggregateBuilder);
+        MultipartRequestAggregate multipartRequestAggregate = multipartRequestAggregateBuilder.build();
+        assertMatch(multipartRequestAggregate.getMatchV10());
+
+        multipartRequestAggregateBuilder = new MultipartRequestAggregateBuilder();
+        FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_3, multipartRequestAggregateBuilder);
+        multipartRequestAggregate = multipartRequestAggregateBuilder.build();
+        assertMatch(multipartRequestAggregate.getMatch());
+
+
+    }
+
+    private void assertMatch(Match match) {
+        assertTrue(match.getType().getClass().isInstance(OxmMatchType.class));
+    }
+
+    private void assertMatch(MatchV10 matchV10) {
+        assertEquals(matchV10.getDlDst(), macAddress);
+        assertEquals(matchV10.getDlSrc(), macAddress);
+
+        assertTrue(matchV10.getNwSrcMask().shortValue() == 0);
+        assertTrue(matchV10.getNwDstMask().shortValue() == 0);
+
+        assertTrue(matchV10.getInPort().intValue() == 0);
+        assertTrue(matchV10.getDlVlan().intValue() == 0);
+        assertTrue(matchV10.getDlVlanPcp().shortValue() == 0);
+        assertTrue(matchV10.getDlType().intValue() == 0);
+
+        assertTrue(matchV10.getNwTos().shortValue() == 0);
+        assertTrue(matchV10.getNwProto().shortValue() == 0);
+
+        assertEquals(matchV10.getNwSrc(), ipv4Address);
+        assertEquals(matchV10.getNwDst(), ipv4Address);
+
+        assertTrue(matchV10.getTpSrc().intValue() == 0);
+        assertTrue(matchV10.getTpDst().intValue() == 0);
+    }
+
+}