1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.core;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.channel.ChannelHandlerContext;
\r
7 import java.util.ArrayList;
\r
8 import java.util.List;
\r
10 import org.junit.Assert;
\r
11 import org.junit.Before;
\r
12 import org.junit.Test;
\r
13 import org.junit.runner.RunWith;
\r
14 import org.mockito.Mock;
\r
15 import org.mockito.runners.MockitoJUnitRunner;
\r
16 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
\r
19 * Testing class of {@link OFFrameDecoder}
\r
21 * @author michal.polkorab
\r
23 @RunWith(MockitoJUnitRunner.class)
\r
24 public class OFFrameDecoderTest {
\r
27 ChannelHandlerContext channelHandlerContext;
\r
29 private OFFrameDecoder decoder;
\r
30 private List<Object> list = new ArrayList<>();
\r
36 public void setUp() {
\r
38 decoder = new OFFrameDecoder();
\r
43 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
\r
48 public void testDecode8BMessage() throws Exception {
\r
49 decoder.decode(channelHandlerContext,
\r
50 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
\r
53 Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
\r
58 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
\r
63 public void testDecode16BMessage() throws Exception {
\r
64 decoder.decode(channelHandlerContext,
\r
65 ByteBufUtils.hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42"),
\r
68 Assert.assertEquals(16, ((ByteBuf) list.get(0)).readableBytes());
\r
73 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
\r
78 public void testDecodeIncompleteMessage() throws Exception {
\r
79 decoder.decode(channelHandlerContext,
\r
80 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00"),
\r
83 Assert.assertEquals("List is not empty", 0, list.size());
\r
88 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
\r
93 public void testDecodeCompleteAndPartialMessage() throws Exception {
\r
94 decoder.decode(channelHandlerContext,
\r
95 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00"),
\r
98 Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
\r
99 Assert.assertEquals(1, list.size());
\r