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 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.protocol.impl.util.ByteBufUtils;
26 * Testing class of {@link OFFrameDecoder}
28 * @author michal.polkorab
30 @RunWith(MockitoJUnitRunner.class)
31 public class OFFrameDecoderTest {
34 ChannelHandlerContext channelHandlerContext;
36 private OFFrameDecoder decoder;
37 private List<Object> list = new ArrayList<>();
45 decoder = new OFFrameDecoder();
50 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
55 public void testDecode8BMessage() throws Exception {
56 decoder.decode(channelHandlerContext,
57 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
60 Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
65 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
70 public void testDecode16BMessage() throws Exception {
71 decoder.decode(channelHandlerContext,
72 ByteBufUtils.hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42"),
75 Assert.assertEquals(16, ((ByteBuf) list.get(0)).readableBytes());
80 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
85 public void testDecodeIncompleteMessage() throws Exception {
86 decoder.decode(channelHandlerContext,
87 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00"),
90 Assert.assertEquals("List is not empty", 0, list.size());
95 * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
100 public void testDecodeCompleteAndPartialMessage() throws Exception {
101 decoder.decode(channelHandlerContext,
102 ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00"),
105 Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
106 Assert.assertEquals(1, list.size());