Enforce check-style under rsvp spi tests
[bgpcep.git] / rsvp / spi / src / test / java / org / opendaylight / protocol / rsvp / parser / spi / subobjects / CommonPathKeyParserTest.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.subobjects;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
21
22 public class CommonPathKeyParserTest {
23     private final byte[] bytes = new byte[]{0, 1, 2, 3};
24     private PathKey key1;
25     private PathKey key2;
26     private PathKey key3;
27
28     @Before
29     public void setUp() {
30         this.key1 = new PathKeyBuilder().build();
31         this.key2 = new PathKeyBuilder().setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
32             .yang.rsvp.rev150820.PathKey(1))
33             .build();
34         this.key3 = new PathKeyBuilder().setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
35             .yang.rsvp.rev150820.PathKey(1))
36             .setPceId(new PceId(new byte[]{2, 3}))
37             .build();
38     }
39
40     @Test(expected = IllegalArgumentException.class)
41     public void testSerializationExcption1() {
42         CommonPathKeyParser.serializePathKey(this.key1);
43     }
44
45     @Test(expected = IllegalArgumentException.class)
46     public void testSerializationExcption2() {
47         CommonPathKeyParser.serializePathKey(this.key2);
48     }
49
50     @Test
51     public void testSerialization() {
52         final ByteBuf output = CommonPathKeyParser.serializePathKey(this.key3);
53         assertArrayEquals(this.bytes, ByteArray.readAllBytes(output));
54     }
55
56     @Test
57     public void testParsing() {
58         assertEquals(this.key3, CommonPathKeyParser.parsePathKey(2, Unpooled.copiedBuffer(this.bytes)));
59     }
60 }