Bump to odlparent-3.0.2 and yangtools-2.0.0
[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
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.lang.reflect.Constructor;
15 import java.lang.reflect.InvocationTargetException;
16 import org.junit.Test;
17
18 public class EROSubobjectUtilTest {
19
20     @Test(expected = UnsupportedOperationException.class)
21     @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
22     public void testPrivateConstructor() throws Throwable {
23         final Constructor<EROSubobjectUtil> c = EROSubobjectUtil.class.getDeclaredConstructor();
24         c.setAccessible(true);
25         try {
26             c.newInstance();
27         } catch (final InvocationTargetException e) {
28             throw e.getCause();
29         }
30     }
31
32     @Test
33     public void testFormatSubobject1() {
34         final byte[] array = new byte[]{2, 3};
35         final byte[] expected = new byte[]{(byte) 0x81, 4, 2, 3};
36         final ByteBuf body = Unpooled.copiedBuffer(array);
37         final ByteBuf aggregator = Unpooled.buffer(4);
38         EROSubobjectUtil.formatSubobject(1, Boolean.TRUE, body, aggregator);
39         assertArrayEquals(expected, aggregator.array());
40     }
41
42     @Test
43     public void testFormatSubobject2() {
44         final byte[] array = new byte[]{2, 3};
45         final byte[] expected = new byte[]{1, 4, 2, 3};
46         final ByteBuf body = Unpooled.copiedBuffer(array);
47         final ByteBuf aggregator = Unpooled.buffer(4);
48         EROSubobjectUtil.formatSubobject(1, Boolean.FALSE, body, aggregator);
49         assertArrayEquals(expected, aggregator.array());
50     }
51
52     @Test
53     public void testFormatSubobject3() {
54         final byte[] array = new byte[]{2, 3};
55         final byte[] expected = new byte[]{1, 4, 2, 3};
56         final ByteBuf body = Unpooled.copiedBuffer(array);
57         final ByteBuf aggregator = Unpooled.buffer(4);
58         EROSubobjectUtil.formatSubobject(1, null, body, aggregator);
59         assertArrayEquals(expected, aggregator.array());
60     }
61 }