Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / OFVersionDetectorTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.channel.ChannelHandlerContext;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.junit.Assert;
18 import static org.junit.Assert.assertEquals;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mock;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.opendaylight.openflowjava.util.ByteBufUtils;
25
26 /**
27  *
28  * @author michal.polkorab
29  */
30 @RunWith(MockitoJUnitRunner.class)
31 public class OFVersionDetectorTest {
32
33     @Mock
34     ChannelHandlerContext channelHandlerContext;
35
36     private OFVersionDetector detector;
37     private List<Object> list = new ArrayList<>();
38
39     /**
40      * Sets up test environment
41      */
42     @Before
43     public void setUp() {
44         list.clear();
45         detector = new OFVersionDetector();
46     }
47
48     /**
49      * Test of decode
50      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
51      * }
52      *
53      * @throws Exception
54      */
55     @Test
56     public void testDecode13ProtocolMessage() throws Exception {
57         detector.decode(channelHandlerContext,
58                 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
59                 list);
60
61         Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
62                 .getMessageBuffer().readableBytes());
63     }
64
65     /**
66      * Test of decode
67      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
68      * }
69      * @throws Exception
70      */
71     @Test
72     public void testDecode10ProtocolMessage() throws Exception {
73         detector.decode(channelHandlerContext,
74                 ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"),
75                 list);
76
77         Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
78                 .getMessageBuffer().readableBytes());
79     }
80
81     /**
82      * Test of decode
83      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
84      * }
85      * @throws Exception
86      */
87     @Test
88     public void testDecodeEmptyProtocolMessage() throws Exception {
89         ByteBuf byteBuffer = ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01").skipBytes(8);
90                 detector.decode(channelHandlerContext,
91                 byteBuffer,
92                 list);
93
94                 assertEquals( 0, byteBuffer.refCnt() ) ;
95                 
96     }
97
98     /**
99      * Test of decode
100      * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
101      * }
102      *
103      * @throws Exception
104      */
105     @Test
106     public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {
107         detector.decode(channelHandlerContext,
108                 ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"),
109                 list);
110
111         Assert.assertEquals("List is not empty", 0, list.size());
112     }
113
114 }