Fix most bgp-parser-spi checkstyle violations
[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.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
11
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.protocol.util.ByteBufWriteUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
19 import org.opendaylight.yangtools.yang.common.QName;
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;
24
25 public class PathIdUtilTest {
26
27     private ByteBuf buffer;
28
29     @Before
30     public void setUp() {
31         this.buffer = Unpooled.buffer();
32     }
33
34     @Test
35     public void testWritePathIdNull() {
36         PathIdUtil.writePathId(null, this.buffer);
37         Assert.assertEquals(0, this.buffer.readableBytes());
38     }
39
40     @Test
41     public void testWritePathIdZero() {
42         PathIdUtil.writePathId(NON_PATH_ID, this.buffer);
43         Assert.assertEquals(0, this.buffer.readableBytes());
44     }
45
46     @Test
47     public void testWritePathId() {
48         PathIdUtil.writePathId(new PathId(10L), this.buffer);
49         Assert.assertEquals(Integer.BYTES, this.buffer.readableBytes());
50     }
51
52     @Test
53     public void testReadPathId() {
54         final long expected = 10L;
55         ByteBufWriteUtil.writeUnsignedInt(expected, this.buffer);
56         final PathId pathId = PathIdUtil.readPathId(this.buffer);
57         Assert.assertEquals(expected, pathId.getValue().longValue());
58     }
59
60     @Test
61     public void testExtractPathId() {
62         final NodeIdentifier NII = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
63             "2015-03-05", "path-id").intern());
64         final long pathIdValue = 0;
65         final ContainerNode cont = ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(NII).addChild(
66             new ImmutableLeafNodeBuilder<>().withNodeIdentifier(NII).withValue(pathIdValue).build()).build();
67         Assert.assertEquals(pathIdValue, PathIdUtil.extractPathId(cont, NII).longValue());
68     }
69
70
71     @Test(expected = IllegalArgumentException.class)
72     public void testReadPathIdBufferNull() {
73         PathIdUtil.readPathId(null);
74     }
75
76     @Test(expected = IllegalArgumentException.class)
77     public void testReadPathIdBufferEmpty() {
78         PathIdUtil.readPathId(this.buffer);
79     }
80 }