Code clean up
[bgpcep.git] / bgp / extensions / inet / src / test / java / org / opendaylight / protocol / bgp / inet / Ipv6BgpPrefixSidParserTest.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.inet;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.inet.codec.Ipv6BgpPrefixSidParser;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.Ipv6SidTlvBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
20
21 public final class Ipv6BgpPrefixSidParserTest {
22
23     private final Ipv6BgpPrefixSidParser handler = new Ipv6BgpPrefixSidParser();
24
25     private final byte[] expected = new byte[]{0, (byte) 0x80, 0};
26
27     @Test(expected = IllegalArgumentException.class)
28     public void testWrongTlvType() {
29         this.handler.serializeBgpPrefixSidTlv(() -> BgpPrefixSidTlv.class, Unpooled.EMPTY_BUFFER);
30     }
31
32     @Test
33     public void testHandling() {
34         final Ipv6SidTlvBuilder tlv = new Ipv6SidTlvBuilder();
35         tlv.setProcessIpv6HeadAbility(Boolean.TRUE);
36         final ByteBuf serialized = Unpooled.buffer(3);
37         this.handler.serializeBgpPrefixSidTlv(tlv.build(), serialized);
38         assertArrayEquals(this.expected, serialized.array());
39         assertTrue(this.handler.parseBgpPrefixSidTlv(serialized).isProcessIpv6HeadAbility());
40     }
41
42     @Test
43     public void testType() {
44         assertEquals(2, this.handler.getType());
45     }
46 }