BUG-4283: experimenter msg support - deserialization part
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / ExperimenterMessageFactoryTest.java
index d25137cac9b00a37c55cb5d080859861bc1aa97c..37dd6ddeb9f4da980b536ded0ae0f5cc43e3c526 100644 (file)
@@ -10,35 +10,39 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.when;
-import io.netty.buffer.ByteBuf;
 
+import io.netty.buffer.ByteBuf;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ExperimenterMessageFactoryTest {
 
     @Mock DeserializerRegistry registry;
-    @Mock OFDeserializer<ExperimenterMessage> deserializer;
-    @Mock ExperimenterMessage message;
+    @Mock OFDeserializer<ExperimenterDataOfChoice> deserializer;
+    @Mock ExperimenterDataOfChoice message;
+    private ExperimenterMessageFactory factory;
 
     /**
      * Initializes mocks
      */
     @Before
     public void startUp() {
-        MockitoAnnotations.initMocks(this);
+        factory = new ExperimenterMessageFactory();
     }
 
     /**
@@ -49,11 +53,10 @@ public class ExperimenterMessageFactoryTest {
         when(registry.getDeserializer(any(ExperimenterIdDeserializerKey.class))).thenReturn(deserializer);
         when(deserializer.deserialize(any(ByteBuf.class))).thenReturn(message);
 
-        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 02 03 00 00 00 10");
-        ExperimenterMessageFactory factory = new ExperimenterMessageFactory();
+        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 02 03 00 00 00 10 00 00 00 20");
         factory.injectDeserializerRegistry(registry);
         ExperimenterMessage deserializedMessage = factory.deserialize(buffer);
-        Assert.assertEquals("Wrong return value", message, deserializedMessage);
-        Assert.assertEquals("ByteBuf index moved", 0, buffer.readerIndex());
+        Assert.assertEquals("Wrong return value", message, deserializedMessage.getExperimenterDataOfChoice());
+        Assert.assertEquals("ByteBuf index moved", 0, buffer.readableBytes());
     }
 }
\ No newline at end of file