Extensibility support (deserialization part)
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10FeaturesReplyMessageFactoryTest.java
index bb955efdd6fbeb378e3021e27ec9388db262de9f..d9b50ee8432b6ac8083d39e62cfde0f4a9582d7f 100644 (file)
@@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 import io.netty.buffer.ByteBuf;
 
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
 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.common.types.rev130731.ActionTypeV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
@@ -28,6 +34,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class OF10FeaturesReplyMessageFactoryTest {
 
+    private OFDeserializer<GetFeaturesOutput> featuresFactory;
+
+    /**
+     * Initializes deserializer registry and lookups correct deserializer
+     */
+    @Before
+    public void startUp() {
+        DeserializerRegistry registry = new DeserializerRegistryImpl();
+        registry.init();
+        featuresFactory = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, GetFeaturesOutput.class));
+    }
+
     /**
      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
      */
@@ -37,8 +56,7 @@ public class OF10FeaturesReplyMessageFactoryTest {
                 + "00 00 00 8B 00 00 03 B5 "
                 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
-        GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
-                OF10FeaturesReplyMessageFactory.getInstance(), bb);
+        GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
@@ -77,8 +95,7 @@ public class OF10FeaturesReplyMessageFactoryTest {
                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
                 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 ");
-        GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
-                OF10FeaturesReplyMessageFactory.getInstance(), bb);
+        GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());
@@ -91,8 +108,7 @@ public class OF10FeaturesReplyMessageFactoryTest {
     public void testWithTwoPortsSet() {
         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
                 + "00 00 00 8B 00 00 03 B5");
-        GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
-                OF10FeaturesReplyMessageFactory.getInstance(), bb);
+        GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
 
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size());