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 0b133f5cdbec4614f8b66d6fb45f35cfba0e3bd9..e0dfb8f70d1261ede3a73b9da076a12da6b5c01c 100644 (file)
@@ -12,7 +12,12 @@ 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.GroupIdAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
@@ -22,8 +27,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -35,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
@@ -59,54 +75,57 @@ public class ActionsDeserializerTest {
         \r
         message.skipBytes(4); // skip XID\r
         LOGGER.info("bytes: " + message.readableBytes());\r
-        List<ActionsList> actions = ActionsDeserializer.createActionsList(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).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());\r
         Assert.assertEquals("Wrong action port", 1,\r
-                actions.get(0).getAction().getAugmentation(PortAction.class).getPort().getValue().intValue());\r
+                actions.get(0).getAugmentation(PortAction.class).getPort().getValue().intValue());\r
         Assert.assertEquals("Wrong action max-length", 2,\r
-                actions.get(0).getAction().getAugmentation(MaxLengthAction.class).getMaxLength().intValue());\r
+                actions.get(0).getAugmentation(MaxLengthAction.class).getMaxLength().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.CopyTtlOut", actions.get(1).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.CopyTtlOut", actions.get(1).getType().getName());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.CopyTtlIn", actions.get(2).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.CopyTtlIn", actions.get(2).getType().getName());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.SetMplsTtl", actions.get(3).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.SetMplsTtl", actions.get(3).getType().getName());\r
         Assert.assertEquals("Wrong action value", 3,\r
-                actions.get(3).getAction().getAugmentation(MplsTtlAction.class).getMplsTtl().shortValue());\r
+                actions.get(3).getAugmentation(MplsTtlAction.class).getMplsTtl().shortValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.DecMplsTtl", actions.get(4).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.DecMplsTtl", actions.get(4).getType().getName());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.PushVlan", actions.get(5).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PushVlan", actions.get(5).getType().getName());\r
         Assert.assertEquals("Wrong action value", 4,\r
-                actions.get(5).getAction().getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
+                actions.get(5).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.PopVlan", actions.get(6).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PopVlan", actions.get(6).getType().getName());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.PushMpls", actions.get(7).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PushMpls", actions.get(7).getType().getName());\r
         Assert.assertEquals("Wrong action value", 5,\r
-                actions.get(7).getAction().getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
+                actions.get(7).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.PopMpls", actions.get(8).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PopMpls", actions.get(8).getType().getName());\r
         Assert.assertEquals("Wrong action value", 6,\r
-                actions.get(8).getAction().getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
+                actions.get(8).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.SetQueue", actions.get(9).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.SetQueue", actions.get(9).getType().getName());\r
         Assert.assertEquals("Wrong action value", 7,\r
-                actions.get(9).getAction().getAugmentation(QueueIdAction.class).getQueueId().intValue());\r
+                actions.get(9).getAugmentation(QueueIdAction.class).getQueueId().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.Group", actions.get(10).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.Group", actions.get(10).getType().getName());\r
         Assert.assertEquals("Wrong action value", 8,\r
-                actions.get(10).getAction().getAugmentation(GroupIdAction.class).getGroupId().intValue());\r
+                actions.get(10).getAugmentation(GroupIdAction.class).getGroupId().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.SetNwTtl", actions.get(11).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.SetNwTtl", actions.get(11).getType().getName());\r
         Assert.assertEquals("Wrong action value", 9,\r
-                actions.get(11).getAction().getAugmentation(NwTtlAction.class).getNwTtl().intValue());\r
+                actions.get(11).getAugmentation(NwTtlAction.class).getNwTtl().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.DecNwTtl", actions.get(12).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.DecNwTtl", actions.get(12).getType().getName());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.SetField", actions.get(13).getAction().getType().getName());\r
-        List<MatchEntries> entries = actions.get(13).getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries();\r
+                + "openflow.common.action.rev130731.SetField", actions.get(13).getType().getName());\r
+        List<MatchEntries> entries = actions.get(13).getAugmentation(OxmFieldsAction.class).getMatchEntries();\r
         Assert.assertEquals("Wrong number of fields", 1, entries.size());\r
         Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow."\r
                 + "oxm.rev130731.OpenflowBasicClass", entries.get(0).getOxmClass().getName());\r
@@ -116,12 +135,32 @@ public class ActionsDeserializerTest {
         Assert.assertEquals("Wrong match entry value", 11, \r
                 entries.get(0).getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
-                + "openflow.common.action.rev130731.PushPbb", actions.get(14).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PushPbb", actions.get(14).getType().getName());\r
         Assert.assertEquals("Wrong action value", 10,\r
-                actions.get(14).getAction().getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
+                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).getAction().getType().getName());\r
+                + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName());\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