Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / GetAsyncReplyMessageFactoryTest.java
index 0326720dac3c0b471bf4c60eb521e267b75f4823..c9dabd87cc51d9cde3983d753841c770468cab0d 100644 (file)
@@ -14,8 +14,14 @@ 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.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
@@ -32,36 +38,46 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  *
  */
 public class GetAsyncReplyMessageFactoryTest {
-    
+
+    private OFDeserializer<GetAsyncOutput> asyncFactory;
+
+    /**
+     * Initializes deserializer registry and lookups correct deserializer
+     */
+    @Before
+    public void startUp() {
+        DeserializerRegistry registry = new DeserializerRegistryImpl();
+        registry.init();
+        asyncFactory = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 27, GetAsyncOutput.class));
+    }
 
     /**
      * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO
      */
     @Test
     public void testGetAsyncReplyMessage() {
-        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ 
-                                              "00 00 00 05 "+
+        ByteBuf bb = BufferHelper.buildBuffer("00 00 00 07 "+
+                                              "00 00 00 00 "+
                                               "00 00 00 07 "+
                                               "00 00 00 00 "+
-                                              "00 00 00 03 "+
-                                              "00 00 00 0A");
-        GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb);
+                                              "00 00 00 0F "+
+                                              "00 00 00 00");
+        GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb);
 
         BufferHelper.checkHeaderV13(builtByFactory);
-        Assert.assertEquals("Wrong packetInMask",createPacketInMask(), 
-                                                 builtByFactory.getPacketInMask());
-        Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), 
-                                                   builtByFactory.getPortStatusMask());
-        Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), 
-                                                    builtByFactory.getFlowRemovedMask());
+        Assert.assertEquals("Wrong packetInMask",createPacketInMask(), builtByFactory.getPacketInMask());
+        Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), builtByFactory.getPortStatusMask());
+        Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), builtByFactory.getFlowRemovedMask());
     }
-    
+
     private static List<PacketInMask> createPacketInMask() {
         List<PacketInMask> inMasks = new ArrayList<>();
         PacketInMaskBuilder maskBuilder;
         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
         maskBuilder = new PacketInMaskBuilder();
         List<PacketInReason> reasons = new ArrayList<>();
+        reasons.add(PacketInReason.OFPRNOMATCH);
         reasons.add(PacketInReason.OFPRACTION);
         reasons.add(PacketInReason.OFPRINVALIDTTL);
         maskBuilder.setMask(reasons);
@@ -69,13 +85,11 @@ public class GetAsyncReplyMessageFactoryTest {
         // OFPCR_ROLE_SLAVE
         maskBuilder = new PacketInMaskBuilder();
         reasons = new ArrayList<>();
-        reasons.add(PacketInReason.OFPRNOMATCH);
-        reasons.add(PacketInReason.OFPRINVALIDTTL);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-    
+
     private static List<PortStatusMask> createPortStatusMask() {
         List<PortStatusMask> inMasks = new ArrayList<>();
         PortStatusMaskBuilder maskBuilder;
@@ -93,7 +107,7 @@ public class GetAsyncReplyMessageFactoryTest {
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-    
+
     private static List<FlowRemovedMask> createFlowRemovedMask() {
         List<FlowRemovedMask> inMasks = new ArrayList<>();
         FlowRemovedMaskBuilder maskBuilder;
@@ -102,15 +116,15 @@ public class GetAsyncReplyMessageFactoryTest {
         List<FlowRemovedReason> reasons = new ArrayList<>();
         reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
         reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
+        reasons.add(FlowRemovedReason.OFPRRDELETE);
+        reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         // OFPCR_ROLE_SLAVE
         maskBuilder = new FlowRemovedMaskBuilder();
         reasons = new ArrayList<>();
-        reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
-        reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
         maskBuilder.setMask(reasons);
         inMasks.add(maskBuilder.build());
         return inMasks;
     }
-}
+}
\ No newline at end of file