Test coverage: rsvp-spi/subobjects
[bgpcep.git] / rsvp / spi / src / test / java / org / opendaylight / protocol / rsvp / parser / spi / EROSubobjectUtilTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.rsvp.parser.spi;
9
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;
16
17 public class EROSubobjectUtilTest {
18
19     @Test(expected=UnsupportedOperationException.class)
20     public void testPrivateConstructor() throws Throwable {
21         final Constructor<EROSubobjectUtil> c = EROSubobjectUtil.class.getDeclaredConstructor();
22         c.setAccessible(true);
23         try {
24             c.newInstance();
25         } catch (final InvocationTargetException e) {
26             throw e.getCause();
27         }
28     }
29
30     @Test
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());
38     }
39
40     @Test
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());
48     }
49
50     @Test
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());
58     }
59 }