Fix unit test regression after netty version bump
[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 CommonPathKeyParser parser = new CommonPathKeyParser();
24     private PathKey key1;
25     private PathKey key2;
26     private PathKey key3;
27     private final byte[] bytes = new byte[] {0,1,2,3};
28
29     @Before
30     public void setUp() {
31         this.key1 = new PathKeyBuilder().build();
32         this.key2 = new PathKeyBuilder()
33             .setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey(1))
34             .build();
35         this.key3 = new PathKeyBuilder()
36             .setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey(1))
37             .setPceId(new PceId(new byte[] {2, 3}))
38             .build();
39     }
40
41     @Test(expected=IllegalArgumentException.class)
42     public void testSerializationExcption1() {
43         this.parser.serializePathKey(this.key1);
44     }
45
46     @Test(expected=IllegalArgumentException.class)
47     public void testSerializationExcption2() {
48         this.parser.serializePathKey(this.key2);
49     }
50
51     @Test
52     public void testSerialization() {
53         final ByteBuf output = this.parser.serializePathKey(this.key3);
54         assertArrayEquals(this.bytes, ByteArray.readAllBytes(output));
55     }
56
57     @Test
58     public void testParsing() {
59         assertEquals(this.key3, this.parser.parsePathKey(2, Unpooled.copiedBuffer(this.bytes)));
60     }
61 }