Allow any hello mesage and extend hello support for v1.4, v1.5
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / OFVersionDetectorTest.java
index 8cf3f75f527ad5e3e857e2e8963816a085358f20..7b3d814a59b0f458e1b42e8198993b7b6bd3a690 100644 (file)
@@ -8,14 +8,13 @@
 
 package org.opendaylight.openflowjava.protocol.impl.core;
 
+import static org.junit.Assert.assertEquals;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.Assert;
-import static org.junit.Assert.assertEquals;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -24,8 +23,7 @@ import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 
 /**
- *
- * @author michal.polkorab
+ * Test for {@link org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OFVersionDetectorTest {
@@ -36,74 +34,40 @@ public class OFVersionDetectorTest {
     private OFVersionDetector detector;
     private List<Object> list = new ArrayList<>();
 
-    /**
-     * Sets up test environment
-     */
     @Before
     public void setUp() {
         list.clear();
         detector = new OFVersionDetector();
     }
 
-    /**
-     * Test of decode
-     * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
-     * }
-     *
-     * @throws Exception
-     */
     @Test
-    public void testDecode13ProtocolMessage() throws Exception {
-        detector.decode(channelHandlerContext,
-                ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
-                list);
-
-        Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
-                .getMessageBuffer().readableBytes());
+    public void testDecode13ProtocolMessage() {
+        detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), list);
+        Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());
     }
 
-    /**
-     * Test of decode
-     * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
-     * }
-     * @throws Exception
-     */
     @Test
-    public void testDecode10ProtocolMessage() throws Exception {
-        detector.decode(channelHandlerContext,
-                ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"),
-                list);
-
-        Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
-                .getMessageBuffer().readableBytes());
+    public void testDecode10ProtocolMessage() {
+        detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"), list);
+        Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());
     }
 
-    /**
-     * Test of decode
-     * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
-     * }
-     * @throws Exception
-     */
     @Test
-    public void testDecodeEmptyProtocolMessage() throws Exception {
+    public void testDecodeEmptyProtocolMessage() {
         ByteBuf byteBuffer = ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01").skipBytes(8);
         detector.decode(channelHandlerContext, byteBuffer, list);
-
-        assertEquals( 0, byteBuffer.refCnt() ) ;
+        assertEquals(0, byteBuffer.refCnt());
     }
 
-    /**
-     * Test of decode
-     * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
-     * }
-     *
-     * @throws Exception
-     */
     @Test
-    public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {
-        detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"), list);
-
+    public void testDecodeNotSupportedVersionProtocolMessage() {
+        detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("02 01 00 08 00 00 00 01"), list);
         Assert.assertEquals("List is not empty", 0, list.size());
     }
 
+    @Test
+    public void testDecodeHelloProtocolMessage() {
+        detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("05 00 00 08 00 00 00 01"), list);
+        Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());
+    }
 }