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 CommonPathKeyParser parser = new CommonPathKeyParser();
27 private final byte[] bytes = new byte[] {0,1,2,3};
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))
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}))
41 @Test(expected=IllegalArgumentException.class)
42 public void testSerializationExcption1() {
43 this.parser.serializePathKey(this.key1);
46 @Test(expected=IllegalArgumentException.class)
47 public void testSerializationExcption2() {
48 this.parser.serializePathKey(this.key2);
52 public void testSerialization() {
53 final ByteBuf output = this.parser.serializePathKey(this.key3);
54 assertArrayEquals(this.bytes, ByteArray.readAllBytes(output));
58 public void testParsing() {
59 assertEquals(this.key3, this.parser.parsePathKey(2, Unpooled.copiedBuffer(this.bytes)));