2 * Copyright (c) 2016 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.bgp.parser.spi;
10 import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.Uint32;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
22 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
23 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
25 public class PathIdUtilTest {
27 private ByteBuf buffer;
31 this.buffer = Unpooled.buffer();
35 public void testWritePathIdNull() {
36 PathIdUtil.writePathId(null, this.buffer);
37 Assert.assertEquals(0, this.buffer.readableBytes());
41 public void testWritePathIdZero() {
42 PathIdUtil.writePathId(NON_PATH_ID, this.buffer);
43 Assert.assertEquals(0, this.buffer.readableBytes());
47 public void testWritePathId() {
48 PathIdUtil.writePathId(new PathId(Uint32.TEN), this.buffer);
49 Assert.assertEquals(Integer.BYTES, this.buffer.readableBytes());
53 public void testReadPathId() {
54 this.buffer.writeInt(10);
55 final PathId pathId = PathIdUtil.readPathId(this.buffer);
56 Assert.assertEquals(Uint32.TEN, pathId.getValue());
60 public void testExtractPathId() {
61 final NodeIdentifier NII = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
62 "2015-03-05", "path-id").intern());
63 final ContainerNode cont = ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(NII).addChild(
64 new ImmutableLeafNodeBuilder<>().withNodeIdentifier(NII).withValue(Uint32.ZERO).build()).build();
65 Assert.assertEquals(0L, PathIdUtil.extractPathId(cont, NII).longValue());
69 @Test(expected = IllegalArgumentException.class)
70 public void testReadPathIdBufferNull() {
71 PathIdUtil.readPathId(null);
74 @Test(expected = IllegalArgumentException.class)
75 public void testReadPathIdBufferEmpty() {
76 PathIdUtil.readPathId(this.buffer);