Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10FlowModInputMessageFactoryTest.java
index 12b2a945ebbac490b82113815a531d1b21d7fb8a..7a3effc866671ab3197f2c22486b4a0016d6bd04 100644 (file)
@@ -16,7 +16,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.junit.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;
@@ -44,6 +49,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class OF10FlowModInputMessageFactoryTest {
 
+    private SerializerRegistry registry;
+    private OFSerializer<FlowModInput> flowModFactory;
+
+    /**
+     * Initializes serializer registry and stores correct factory in field
+     */
+    @Before
+    public void startUp() {
+        registry = new SerializerRegistryImpl();
+        registry.init();
+        flowModFactory = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, FlowModInput.class));
+    }
+
     /**
      * @throws Exception 
      * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO
@@ -95,10 +114,9 @@ public class OF10FlowModInputMessageFactoryTest {
         FlowModInput message = builder.build();
         
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
-        OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance();
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+        flowModFactory.serialize(message, out);
         
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));
+        BufferHelper.checkHeaderV10(out, (byte) 14, 88);
         Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
         Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
         byte[] dlSrc = new byte[6];