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;
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 {
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());
+ }
}