2 * Copyright (c) 2015 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.protocol.rsvp.parser.spi;
10 import static org.junit.Assert.assertArrayEquals;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.lang.reflect.Constructor;
14 import java.lang.reflect.InvocationTargetException;
15 import org.junit.Test;
17 public class EROSubobjectUtilTest {
19 @Test(expected=UnsupportedOperationException.class)
20 public void testPrivateConstructor() throws Throwable {
21 final Constructor<EROSubobjectUtil> c = EROSubobjectUtil.class.getDeclaredConstructor();
22 c.setAccessible(true);
25 } catch (final InvocationTargetException e) {
31 public void testFormatSubobject1() {
32 final byte[] array = new byte[] {2, 3};
33 final byte[] expected = new byte[] {(byte)0x81, 4, 2, 3};
34 final ByteBuf body = Unpooled.copiedBuffer(array);
35 final ByteBuf aggregator = Unpooled.buffer(4);
36 EROSubobjectUtil.formatSubobject(1, Boolean.TRUE, body, aggregator);
37 assertArrayEquals(expected, aggregator.array());
41 public void testFormatSubobject2() {
42 final byte[] array = new byte[] {2, 3};
43 final byte[] expected = new byte[] {1, 4, 2, 3};
44 final ByteBuf body = Unpooled.copiedBuffer(array);
45 final ByteBuf aggregator = Unpooled.buffer(4);
46 EROSubobjectUtil.formatSubobject(1, Boolean.FALSE, body, aggregator);
47 assertArrayEquals(expected, aggregator.array());
51 public void testFormatSubobject3() {
52 final byte[] array = new byte[] {2, 3};
53 final byte[] expected = new byte[] {1, 4, 2, 3};
54 final ByteBuf body = Unpooled.copiedBuffer(array);
55 final ByteBuf aggregator = Unpooled.buffer(4);
56 EROSubobjectUtil.formatSubobject(1, null, body, aggregator);
57 assertArrayEquals(expected, aggregator.array());