Make sure to pick up junit version from odlparent
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / ActionsDeserializerTest.java
index a63edea95735bf90c54ff2624fd5b25cf1e71df5..e0dfb8f70d1261ede3a73b9da076a12da6b5c01c 100644 (file)
@@ -12,9 +12,13 @@ import io.netty.buffer.ByteBuf;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.action.AbstractActionDeserializer;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;\r
@@ -36,6 +40,17 @@ public class ActionsDeserializerTest {
 \r
     private static final Logger LOGGER = LoggerFactory\r
             .getLogger(ActionsDeserializerTest.class);\r
+    private DeserializerRegistry registry;\r
+\r
+    /**\r
+     * Initializes deserializer registry and lookups correct deserializer\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new DeserializerRegistryImpl();\r
+        registry.init();\r
+    }\r
+\r
     /**\r
      * Testing actions deserialization\r
      */\r
@@ -56,12 +71,14 @@ public class ActionsDeserializerTest {
                 + "00 18 00 08 00 00 00 00 "\r
                 + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 "\r
                 + "00 1A 00 08 00 0A 00 00 "\r
-                + "00 1B 00 08 00 00 00 00 "\r
-                + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07");\r
+                + "00 1B 00 08 00 00 00 00");\r
         \r
         message.skipBytes(4); // skip XID\r
         LOGGER.info("bytes: " + message.readableBytes());\r
-        List<Action> actions = ActionsDeserializer.createActions(message, message.readableBytes());\r
+        \r
+        CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);\r
+        List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,\r
+                message.readableBytes(), message, keyMaker, registry);\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
                 + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());\r
         Assert.assertEquals("Wrong action port", 1,\r
@@ -123,13 +140,27 @@ public class ActionsDeserializerTest {
                 actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
                 + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName());\r
-        Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName());\r
-        Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class)\r
-                .getExperimenter().intValue());\r
-        Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16)\r
-                .getAugmentation(ExperimenterAction.class).getData());\r
         Assert.assertTrue("Unread data in message", message.readableBytes() == 0);\r
     }\r
 \r
+    /**\r
+     * Tests {@link AbstractActionDeserializer#deserializeHeader(ByteBuf)}\r
+     */\r
+    @Test\r
+    public void testDeserializeHeader() {\r
+        ByteBuf message = BufferHelper.buildBuffer("00 00 00 04 00 19 00 04");\r
+\r
+        message.skipBytes(4); // skip XID\r
+        CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);\r
+        List<Action> actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID,\r
+                message.readableBytes(), message, keyMaker, registry);\r
+\r
+        Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
+                + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());\r
+        Assert.assertEquals("Wrong action port", null, actions.get(0).getAugmentation(PortAction.class));\r
+        Assert.assertEquals("Wrong action max-length", null, actions.get(0).getAugmentation(MaxLengthAction.class));\r
+        Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
+                + "openflow.common.action.rev130731.SetField", actions.get(1).getType().getName());\r
+        Assert.assertEquals("Wrong action oxm field", null, actions.get(1).getAugmentation(OxmFieldsAction.class));\r
+    }\r
 }\r