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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertThrows;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Uint32;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
21 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
23 class PathIdUtilTest {
24 private final ByteBuf buffer = Unpooled.buffer();
27 void testWritePathIdNull() {
28 PathIdUtil.writePathId(null, buffer);
29 assertEquals(0, buffer.readableBytes());
33 void testWritePathIdZero() {
34 PathIdUtil.writePathId(PathIdUtil.NON_PATH_ID, buffer);
35 assertEquals(0, buffer.readableBytes());
39 void testWritePathId() {
40 PathIdUtil.writePathId(new PathId(Uint32.TEN), buffer);
41 assertEquals(Integer.BYTES, buffer.readableBytes());
45 void testReadPathId() {
47 final PathId pathId = PathIdUtil.readPathId(buffer);
48 assertEquals(Uint32.TEN, pathId.getValue());
52 void testExtractPathId() {
53 final NodeIdentifier NII = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
54 "2015-03-05", "path-id").intern());
55 final ContainerNode cont = ImmutableNodes.newContainerBuilder()
56 .withNodeIdentifier(NII)
57 .addChild(ImmutableNodes.leafNode(NII, Uint32.ZERO))
59 assertEquals(0L, PathIdUtil.extractPathId(cont, NII).longValue());
63 void testReadPathIdBufferNull() {
64 assertThrows(IllegalArgumentException.class, () -> PathIdUtil.readPathId(null));
68 void testReadPathIdBufferEmpty() {
69 assertThrows(IllegalArgumentException.class, () -> PathIdUtil.readPathId(buffer));