Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10BarrierInputMessageFactoryTest.java
index 7e50fa8bbbd270b9dcf49e7a3b482726c4782c47..f1a70c8ee561aafeb667ca3fac989ee65abbf149 100644 (file)
@@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
+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.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
@@ -23,6 +28,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class OF10BarrierInputMessageFactoryTest {
 
+    private SerializerRegistry registry;
+    private OFSerializer<BarrierInput> barrierFactory;
+
+    /**
+     * Initializes serializer registry and stores correct factory in field
+     */
+    @Before
+    public void startUp() {
+        registry = new SerializerRegistryImpl();
+        registry.init();
+        barrierFactory = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class));
+    }
+
     /**
      * Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO
      * @throws Exception 
@@ -34,8 +53,7 @@ public class OF10BarrierInputMessageFactoryTest {
         BarrierInput bi = bib.build();
         
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
-        OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance();
-        bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi);
+        barrierFactory.serialize(bi, out);
         
         BufferHelper.checkHeaderV10(out, (byte) 18, 8);
     }