Added unit tests for Error and Vendor/Experimenter message factories
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / VendorInputMessageFactoryTest.java
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..df1c345
--- /dev/null
@@ -0,0 +1,57 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.PooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class VendorInputMessageFactoryTest {\r
+\r
+    @Mock SerializerRegistry registry;\r
+    @Mock ExperimenterInputMessageFactory serializer;\r
+\r
+    /**\r
+     * Tests {@link VendorInputMessageFactory#serialize(ExperimenterInput, ByteBuf)}\r
+     */\r
+    @Test\r
+    public void test() {\r
+        Mockito.when(registry.getSerializer((MessageTypeKey<?>) Matchers.any(MessageTypeKey.class)))\r
+            .thenReturn(serializer);\r
+        VendorInputMessageFactory factory = new VendorInputMessageFactory();\r
+        factory.injectSerializerRegistry(registry);\r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        ExperimenterInputBuilder builder = new ExperimenterInputBuilder();\r
+        builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);\r
+        builder.setXid(12345L);\r
+        builder.setExperimenter(new ExperimenterId(42L));\r
+        builder.setExpType(84L);\r
+        ExperimenterInput experimenterInput = builder.build();\r
+\r
+        factory.serialize(experimenterInput, buffer);\r
+        Mockito.verify(serializer, Mockito.times(1)).serialize(experimenterInput, buffer);\r
+    }\r
+}
\ No newline at end of file