Renamed packages to org.opendaylight.openflowjava.protocol.impl.*
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / OFVersionDetectorTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.core;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 import io.netty.channel.embedded.EmbeddedChannel;\r
6 \r
7 import org.junit.Assert;\r
8 import org.junit.Before;\r
9 import org.junit.Test;\r
10 import org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector;\r
11 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;\r
12 \r
13 /**\r
14  *\r
15  * @author michal.polkorab\r
16  */\r
17 public class OFVersionDetectorTest {\r
18 \r
19     private EmbeddedChannel embch;\r
20 \r
21     /**\r
22      * Sets up test environment\r
23      */\r
24     @Before\r
25     public void setUp() {\r
26         embch = new EmbeddedChannel(new OFVersionDetector());\r
27     }\r
28 \r
29     /**\r
30      * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
31      * }\r
32      * @throws Exception \r
33      */\r
34     @Test\r
35     public void testDecode13ProtocolMessage() throws Exception {\r
36         byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01};\r
37         ByteBuf writeObj = embch.alloc().buffer(64);\r
38         writeObj.writeBytes(msgs);\r
39         embch.writeInbound(writeObj);\r
40 \r
41         ByteBuf inObj = (ByteBuf) embch.readInbound();\r
42         Assert.assertEquals(7, inObj.readableBytes());\r
43         Assert.assertNotNull(embch.pipeline().get(COMPONENT_NAMES.OF_CODEC.name()));\r
44     }\r
45     \r
46     /**\r
47      * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
48      * }\r
49      * @throws Exception \r
50      */\r
51     @Test\r
52     public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {\r
53         byte[] msgs = new byte[]{0x01, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01};\r
54         ByteBuf writeObj = embch.alloc().buffer(64);\r
55         writeObj.writeBytes(msgs);\r
56         embch.writeInbound(writeObj);\r
57 \r
58         ByteBuf inObj = (ByteBuf) embch.readInbound();\r
59         Assert.assertNull(inObj);\r
60         Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.OF_CODEC.name()));\r
61     }\r
62 }