2 * Copyright (c) 2013 Cisco Systems, Inc. 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
8 package org.opendaylight.controller.netconf.nettyutil.handler;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.base.Charsets;
13 import com.google.common.collect.Lists;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.util.List;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
20 public class NetconfChunkAggregatorTest {
22 private static final String CHUNKED_MESSAGE = "\n#4\n" +
25 " message-id=\"102\"\n" +
27 " xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
28 " <close-session/>\n" +
32 public static final String EXPECTED_MESSAGE = "<rpc message-id=\"102\"\n" +
33 " xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
34 " <close-session/>\n" +
37 private static final String CHUNKED_MESSAGE_ONE = "\n#101\n" + EXPECTED_MESSAGE + "\n##\n";
39 private static NetconfChunkAggregator agr;
42 public static void setUp() throws Exception {
43 agr = new NetconfChunkAggregator();
47 public void testMultipleChunks() throws Exception {
48 final List<Object> output = Lists.newArrayList();
49 final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(Charsets.UTF_8));
50 agr.decode(null, input, output);
52 assertEquals(1, output.size());
53 final ByteBuf chunk = (ByteBuf) output.get(0);
55 assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8));
59 public void testOneChunks() throws Exception {
60 final List<Object> output = Lists.newArrayList();
61 final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(Charsets.UTF_8));
62 agr.decode(null, input, output);
64 assertEquals(1, output.size());
65 final ByteBuf chunk = (ByteBuf) output.get(0);
67 assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8));