Added support for OF 1.0
[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.channel.ChannelHandlerContext;\r
5 \r
6 import java.util.ArrayList;\r
7 import java.util.List;\r
8 \r
9 import org.junit.Assert;\r
10 import org.junit.Before;\r
11 import org.junit.Test;\r
12 import org.junit.runner.RunWith;\r
13 import org.mockito.Mock;\r
14 import org.mockito.runners.MockitoJUnitRunner;\r
15 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
16 \r
17 /**\r
18  * \r
19  * @author michal.polkorab\r
20  */\r
21 @RunWith(MockitoJUnitRunner.class)\r
22 public class OFVersionDetectorTest {\r
23 \r
24     @Mock\r
25     ChannelHandlerContext channelHandlerContext;\r
26 \r
27     private OFVersionDetector detector;\r
28     private List<Object> list = new ArrayList<>();\r
29 \r
30     /**\r
31      * Sets up test environment\r
32      */\r
33     @Before\r
34     public void setUp() {\r
35         list.clear();\r
36         detector = new OFVersionDetector();\r
37     }\r
38 \r
39     /**\r
40      * Test of decode\r
41      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
42      * }\r
43      * \r
44      * @throws Exception\r
45      */\r
46     @Test\r
47     public void testDecode13ProtocolMessage() throws Exception {\r
48         detector.decode(channelHandlerContext,\r
49                 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),\r
50                 list);\r
51 \r
52         Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))\r
53                 .getMessageBuffer().readableBytes());\r
54     }\r
55 \r
56     /**\r
57      * Test of decode\r
58      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
59      * }\r
60      * \r
61      * @throws Exception\r
62      */\r
63     @Test\r
64     public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {\r
65         detector.decode(channelHandlerContext,\r
66                 ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"),\r
67                 list);\r
68 \r
69         Assert.assertEquals("List is not empty", 0, list.size());\r
70     }\r
71 \r
72 }