Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10PortModInputMessageFactoryTest.java
index c49b7b26228cff71fa947256f932f1754d8defc2..9a71288b1c8a8e702061b6141367eefcb0a04550 100644 (file)
@@ -12,7 +12,12 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 import junit.framework.Assert;
 
+import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
@@ -29,6 +34,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class OF10PortModInputMessageFactoryTest {
 
+    private SerializerRegistry registry;
+    private OFSerializer<PortModInput> portModFactory;
+
+    /**
+     * Initializes serializer registry and stores correct factory in field
+     */
+    @Before
+    public void startUp() {
+        registry = new SerializerRegistryImpl();
+        registry.init();
+        portModFactory = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PortModInput.class));
+    }
+
     /**
      * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
      * @throws Exception 
@@ -46,8 +65,7 @@ public class OF10PortModInputMessageFactoryTest {
         PortModInput message = builder.build();
         
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
-        OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance();
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+        portModFactory.serialize(message, out);
         
         BufferHelper.checkHeaderV10(out, (byte) 15, 32);
         Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());