Increased unit test coverage for the rest of deserialization factories 02/12102/2
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 21 Oct 2014 10:36:46 +0000 (12:36 +0200)
committermichal rehak <mirehak@cisco.com>
Wed, 22 Oct 2014 12:06:15 +0000 (12:06 +0000)
Change-Id: I6dcf3094071fcb8013084469574dc0af48f293bf
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java [new file with mode: 0644]

index 6dd6558d259ea4aa70a5e2fca7bab5ddb672427e..937f7d8c1f54460937f051cb3e78b2dbe920d1ae 100644 (file)
@@ -57,29 +57,27 @@ public class GetAsyncReplyMessageFactoryTest {
      */
     @Test
     public void testGetAsyncReplyMessage() {
-        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ 
-                                              "00 00 00 05 "+
+        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 07 "+ 
+                                              "00 00 00 00 "+
                                               "00 00 00 07 "+
                                               "00 00 00 00 "+
-                                              "00 00 00 03 "+
-                                              "00 00 00 0A");
+                                              "00 00 00 0F "+
+                                              "00 00 00 00");
         GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb);
 
         BufferHelper.checkHeaderV13(builtByFactory);
-        Assert.assertEquals("Wrong packetInMask",createPacketInMask(), 
-                                                 builtByFactory.getPacketInMask());
-        Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), 
-                                                   builtByFactory.getPortStatusMask());
-        Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), 
-                                                    builtByFactory.getFlowRemovedMask());
+        Assert.assertEquals("Wrong packetInMask",createPacketInMask(), builtByFactory.getPacketInMask());
+        Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), builtByFactory.getPortStatusMask());
+        Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), builtByFactory.getFlowRemovedMask());
     }
-    
+
     private static List<PacketInMask> createPacketInMask() {
         List<PacketInMask> inMasks = new ArrayList<>();
         PacketInMaskBuilder maskBuilder;
         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
         maskBuilder = new PacketInMaskBuilder();
         List<PacketInReason> reasons = new ArrayList<>();
+        reasons.add(PacketInReason.OFPRNOMATCH);
         reasons.add(PacketInReason.OFPRACTION);
         reasons.add(PacketInReason.OFPRINVALIDTTL);
         maskBuilder.setMask(reasons);
@@ -87,13 +85,11 @@ public class GetAsyncReplyMessageFactoryTest {
         // OFPCR_ROLE_SLAVE
         maskBuilder = new PacketInMaskBuilder();
         reasons = new ArrayList<>();
-        reasons.add(PacketInReason.OFPRNOMATCH);
-        reasons.add(PacketInReason.OFPRINVALIDTTL);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-    
+
     private static List<PortStatusMask> createPortStatusMask() {
         List<PortStatusMask> inMasks = new ArrayList<>();
         PortStatusMaskBuilder maskBuilder;
@@ -111,7 +107,7 @@ public class GetAsyncReplyMessageFactoryTest {
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-    
+
     private static List<FlowRemovedMask> createFlowRemovedMask() {
         List<FlowRemovedMask> inMasks = new ArrayList<>();
         FlowRemovedMaskBuilder maskBuilder;
@@ -120,15 +116,15 @@ public class GetAsyncReplyMessageFactoryTest {
         List<FlowRemovedReason> reasons = new ArrayList<>();
         reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
         reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
+        reasons.add(FlowRemovedReason.OFPRRDELETE);
+        reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         // OFPCR_ROLE_SLAVE
         maskBuilder = new FlowRemovedMaskBuilder();
         reasons = new ArrayList<>();
-        reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
-        reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-}
+}
\ No newline at end of file
index a632ba4549882e0588cfe78146f92503d7dfa5fe..6238780614f17d2096f74e1a58cf87fb0aa19698 100644 (file)
@@ -56,4 +56,14 @@ public class OF10PacketInMessageFactoryTest {
         Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
     }
 
-}
+    /**
+     * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO
+     */
+    @Test
+    public void testWithNoAdditionalData(){
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00");
+        PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); 
+
+        Assert.assertNull("Wrong data", builtByFactory.getData());
+    }
+}
\ No newline at end of file
index b538e856f21430aaa974d9e9a5cf32874363c9f9..cf0499ae95af6590735a4e86d19a7f890a824847 100644 (file)
@@ -91,4 +91,31 @@ public class PortStatusMessageFactoryTest {
         Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue());
         Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue());
     }
-}
+
+    /**
+     * Testing {@link PortStatusMessageFactory} for correct translation into POJO
+     */
+    @Test
+    public void testWithDifferentBitmaps(){
+        ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00 " + //reason, padding
+                                              "00 01 02 03 00 00 00 00 " + //port no, padding
+                                              "08 00 27 00 B0 EB 00 00 " + //mac address, padding
+                                              "73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port name, String "s1-eth1"
+                                              "00 00 00 24 " + //port config
+                                              "00 00 00 02 " + //port state
+                                              "00 00 00 81 00 00 00 A1 " + //current + advertised features
+                                              "00 00 FF FF 00 00 00 00 " + //supported + peer features
+                                              "00 00 00 81 00 00 00 80" //curr speed, max speed
+                                              );
+        PortStatusMessage message = BufferHelper.deserialize(statusFactory, bb);
+
+        Assert.assertEquals("Wrong portConfig", new PortConfig(true, false, true, false), message.getConfig());
+        Assert.assertEquals("Wrong portState", new PortState(true, false, false), message.getState());
+        Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, true, true, true,
+                     true, true, true, true, true, true, true, true, true, true, true, true),
+                     message.getSupportedFeatures());
+        Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false,
+                     false, false, false, false, false, false, false, false, false, false,
+                     false, false), message.getPeerFeatures());
+    }
+}
\ No newline at end of file
index 61110453433c9cfd00cfdde0633ad96094158084..6e4de3f9271df006c907d11f505c75fa446aeb02 100644 (file)
@@ -40,18 +40,8 @@ public class MultipartReplyExperimenterTest {
     @Test\r
     public void testMultipartReplyExperimenter() {\r
         factory.injectDeserializerRegistry(registry);\r
-        ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+\r
-                                              "00 00 00 0F "+// types\r
-                                              "00 00 00 0F "+// capabilities\r
-                                              "00 00 00 01 "+// max groups\r
-                                              "00 00 00 02 "+// max groups\r
-                                              "00 00 00 03 "+// max groups\r
-                                              "00 00 00 04 "+// max groups\r
-                                              "0F FF 98 01 "+// actions bitmap (all actions included)\r
-                                              "00 00 00 00 "+// actions bitmap (no actions included)\r
-                                              "00 00 00 00 "+// actions bitmap (no actions included)\r
-                                              "00 00 00 00"// actions bitmap (no actions included)\r
-                                              );\r
+        ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "\r
+                                            + "00 00 00 01 00 00 00 02"); // expID, expType\r
         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);\r
 \r
         BufferHelper.checkHeaderV13(builtByFactory);\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java
new file mode 100644 (file)
index 0000000..6ef4153
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class OF10StatsReplyExperimenterTest {\r
+\r
+    @Mock DeserializerRegistry registry;\r
+\r
+    /**\r
+     * Tests {@link OF10StatsReplyMessageFactory} for experimenter body translation\r
+     */\r
+    @Test\r
+    public void test() {\r
+        OF10StatsReplyMessageFactory factory = new OF10StatsReplyMessageFactory();\r
+        factory.injectDeserializerRegistry(registry);\r
+\r
+        ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "\r
+                                            + "00 00 00 01"); // expID\r
+        MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);\r
+\r
+        BufferHelper.checkHeaderV10(builtByFactory);\r
+        Assert.assertEquals("Wrong type", 65535, builtByFactory.getType().getIntValue());\r
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());\r
+        Mockito.verify(registry, Mockito.times(1)).getDeserializer(Matchers.any(MessageCodeKey.class));\r
+    }\r
+}
\ No newline at end of file