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