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 static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.channel.ChannelHandlerContext;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.openflowjava.util.ByteBufUtils;
26 * Test for {@link org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector}.
28 @RunWith(MockitoJUnitRunner.class)
29 public class OFVersionDetectorTest {
32 ChannelHandlerContext channelHandlerContext;
34 private OFVersionDetector detector;
35 private List<Object> list = new ArrayList<>();
40 detector = new OFVersionDetector();
44 public void testDecode13ProtocolMessage() {
45 detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), list);
46 Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());
50 public void testDecode10ProtocolMessage() {
51 detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"), list);
52 Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());
56 public void testDecodeEmptyProtocolMessage() {
57 ByteBuf byteBuffer = ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01").skipBytes(8);
58 detector.decode(channelHandlerContext, byteBuffer, list);
59 assertEquals(0, byteBuffer.refCnt());
63 public void testDecodeNotSupportedVersionProtocolMessage() {
64 detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("02 01 00 08 00 00 00 01"), list);
65 Assert.assertEquals("List is not empty", 0, list.size());
69 public void testDecodeHelloProtocolMessage() {
70 detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("05 00 00 08 00 00 00 01"), list);
71 Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes());