Default experimenters moved to separate bundle + unit tests
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10StatsRequestInputFactoryTest.java
index c8141a7b58f439ae3053c180493eb8fff5149537..5909067e512a02510d39501a88ed6b301e9d9926 100644 (file)
@@ -11,10 +11,15 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
@@ -40,6 +45,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class OF10StatsRequestInputFactoryTest {\r
 \r
+    private SerializerRegistry registry;\r
+    private OFSerializer<MultipartRequestInput> multipartFactory;\r
+\r
+    /**\r
+     * Initializes serializer registry and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        multipartFactory = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartRequestInput.class));\r
+    }\r
+\r
     /**\r
      * Testing OF10StatsRequestInputFactory (Desc) for correct serialization\r
      * @throws Exception\r
@@ -57,10 +76,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
         Assert.assertEquals("Wrong type", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -103,10 +121,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong wildcards", 3414271, out.readUnsignedInt());\r
@@ -171,10 +188,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
         Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt());\r
@@ -219,10 +235,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
         Assert.assertEquals("Wrong type", 3, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -246,10 +261,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
         Assert.assertEquals("Wrong type", 4, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r
@@ -276,10 +290,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
         Assert.assertEquals("Wrong type", 5, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r