2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.core;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.channel.ChannelHandlerContext;
14 import java.util.ArrayList;
15 import java.util.List;
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;
28 * @author michal.polkorab
30 @RunWith(MockitoJUnitRunner.class)
31 public class OFVersionDetectorTest {
34 ChannelHandlerContext channelHandlerContext;
36 private OFVersionDetector detector;
37 private List<Object> list = new ArrayList<>();
40 * Sets up test environment
45 detector = new OFVersionDetector();
50 * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
56 public void testDecode13ProtocolMessage() throws Exception {
57 detector.decode(channelHandlerContext,
58 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
61 Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
62 .getMessageBuffer().readableBytes());
67 * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
72 public void testDecode10ProtocolMessage() throws Exception {
73 detector.decode(channelHandlerContext,
74 ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"),
77 Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
78 .getMessageBuffer().readableBytes());
83 * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
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,
94 assertEquals( 0, byteBuffer.refCnt() ) ;
100 * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
106 public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {
107 detector.decode(channelHandlerContext,
108 ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"),
111 Assert.assertEquals("List is not empty", 0, list.size());