Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchSerializerTest.java
index 19d745be585af48feb30fbf1b18a3e66590da45f..db16f9c58b87a44d6768a808394515f209d8d1f5 100644 (file)
@@ -8,16 +8,23 @@
 
 package org.opendaylight.openflowjava.protocol.impl.util;
 
-import junit.framework.Assert;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
 
 /**
  * @author michal.polkorab
@@ -25,6 +32,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc
  */
 public class OF10MatchSerializerTest {
 
+    private SerializerRegistry registry;
+    private OFSerializer<MatchV10> matchSerializer;
+
+    /**
+     * Initializes serializer table and stores correct factory in field
+     */
+    @Before
+    public void startUp() {
+        registry = new SerializerRegistryImpl();
+        registry.init();
+        matchSerializer = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class));
+    }
+
     /**
      * Testing correct serialization of ofp_match
      */
@@ -49,8 +70,8 @@ public class OF10MatchSerializerTest {
         builder.setTpSrc(2048);
         builder.setTpDst(4096);
         MatchV10 match = builder.build();
-        OF10MatchSerializer.encodeMatchV10(out, match);
-        
+        matchSerializer.serialize(match, out);
+
         Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());
         Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
         byte[] dlSrc = new byte[6];
@@ -71,7 +92,7 @@ public class OF10MatchSerializerTest {
         Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());
         Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());
     }
-    
+
     /**
      * Testing correct serialization of ofp_match
      */
@@ -96,8 +117,8 @@ public class OF10MatchSerializerTest {
         builder.setTpSrc(2048);
         builder.setTpDst(4096);
         MatchV10 match = builder.build();
-        OF10MatchSerializer.encodeMatchV10(out, match);
-        
+        matchSerializer.serialize(match, out);
+
         Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
         Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
         byte[] dlSrc = new byte[6];