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
*/\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
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
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
Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 1, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 1, out.readUnsignedByte());\r
out.skipBytes(1);\r
Assert.assertEquals("Wrong out-port", 42, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
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
Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 42, out.readUnsignedByte());\r
out.skipBytes(1);\r
Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
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
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
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