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.subobjects;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
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;
22 public class CommonPathKeyParserTest {
23 private final byte[] bytes = new byte[]{0, 1, 2, 3};
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))
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}))
40 @Test(expected = IllegalArgumentException.class)
41 public void testSerializationExcption1() {
42 CommonPathKeyParser.serializePathKey(this.key1);
45 @Test(expected = IllegalArgumentException.class)
46 public void testSerializationExcption2() {
47 CommonPathKeyParser.serializePathKey(this.key2);
51 public void testSerialization() {
52 final ByteBuf output = CommonPathKeyParser.serializePathKey(this.key3);
53 assertArrayEquals(this.bytes, ByteArray.readAllBytes(output));
57 public void testParsing() {
58 assertEquals(this.key3, CommonPathKeyParser.parsePathKey(2, Unpooled.copiedBuffer(this.bytes)));