Change EchoReq/Res factories to version assignable
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / EchoReplyMessageFactoryTest.java
index 438ac186c5bd3bf82f521db8a8e18b55b15e5437..8ec42cb14eb935c59fa19e82d3df65d04d2f11d5 100644 (file)
@@ -9,58 +9,64 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
+import org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
 
 /**
+ * Test for {@link org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory}.
  * @author michal.polkorab
  * @author timotej.kubas
  */
-public class EchoReplyMessageFactoryTest {
+public class EchoReplyMessageFactoryTest extends DefaultDeserializerFactoryTest<EchoOutput> {
 
-    private OFDeserializer<EchoOutput> echoFactory;
+    /**
+     * Initializes deserializer registry and lookups OF13 deserializer.
+     */
+    public EchoReplyMessageFactoryTest() {
+        super(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 3, EchoOutput.class));
+    }
 
     /**
-     * Initializes deserializer registry and lookups correct deserializer
+     * Testing {@link EchoReplyMessageFactory} for correct header version.
      */
-    @Before
-    public void startUp() {
-        DeserializerRegistry registry = new DeserializerRegistryImpl();
-        registry.init();
-        echoFactory = registry.getDeserializer(
-                new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 3, EchoOutput.class));
+    @Test
+    public void testVersions() {
+        List<Byte> versions = new ArrayList<>(Arrays.asList(
+                EncodeConstants.OF10_VERSION_ID,
+                EncodeConstants.OF13_VERSION_ID,
+                EncodeConstants.OF14_VERSION_ID,
+                EncodeConstants.OF15_VERSION_ID
+        ));
+        ByteBuf bb = BufferHelper.buildBuffer();
+        testHeaderVersions(versions, bb);
     }
 
     /**
-     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO
+     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO.
      */
     @Test
     public void testWithEmptyDataField() {
         ByteBuf bb = BufferHelper.buildBuffer();
-        EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb);
-
-        BufferHelper.checkHeaderV13(builtByFactory);
+        EchoOutput builtByFactory = BufferHelper.deserialize(factory, bb);
+        Assert.assertArrayEquals("Wrong data", null, builtByFactory.getData());
     }
 
     /**
-     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO
+     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO.
      */
     @Test
     public void testWithDataFieldSet() {
         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
         ByteBuf bb = BufferHelper.buildBuffer(data);
-        EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb);
-
-        BufferHelper.checkHeaderV13(builtByFactory);
+        EchoOutput builtByFactory = BufferHelper.deserialize(factory, bb);
         Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
     }
-}
+}
\ No newline at end of file