Fix a few deprecation warnings
[bgpcep.git] / bgp / parser-spi / src / test / java / org / opendaylight / protocol / bgp / parser / spi / PathIdUtilTest.java
1 /*
2  * Copyright (c) 2016 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.bgp.parser.spi;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertThrows;
12
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;
22
23 class PathIdUtilTest {
24     private final ByteBuf buffer = Unpooled.buffer();
25
26     @Test
27     void testWritePathIdNull() {
28         PathIdUtil.writePathId(null, buffer);
29         assertEquals(0, buffer.readableBytes());
30     }
31
32     @Test
33     void testWritePathIdZero() {
34         PathIdUtil.writePathId(PathIdUtil.NON_PATH_ID, buffer);
35         assertEquals(0, buffer.readableBytes());
36     }
37
38     @Test
39     void testWritePathId() {
40         PathIdUtil.writePathId(new PathId(Uint32.TEN), buffer);
41         assertEquals(Integer.BYTES, buffer.readableBytes());
42     }
43
44     @Test
45     void testReadPathId() {
46         buffer.writeInt(10);
47         final PathId pathId = PathIdUtil.readPathId(buffer);
48         assertEquals(Uint32.TEN, pathId.getValue());
49     }
50
51     @Test
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))
58             .build();
59         assertEquals(0L, PathIdUtil.extractPathId(cont, NII).longValue());
60     }
61
62     @Test
63     void testReadPathIdBufferNull() {
64         assertThrows(IllegalArgumentException.class, () -> PathIdUtil.readPathId(null));
65     }
66
67     @Test
68     void testReadPathIdBufferEmpty() {
69         assertThrows(IllegalArgumentException.class, () -> PathIdUtil.readPathId(buffer));
70     }
71 }