Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / OriginatorIdAttributeParserTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.impl.message.update;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
17 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
18 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
24
25 public class OriginatorIdAttributeParserTest {
26
27     private static final byte[] ATTRIBUTE_BYTES = {
28         (byte) 0x80, (byte) 0x09, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
29     };
30
31     private static final Attributes RESULT = new AttributesBuilder()
32             .setOriginatorId(new OriginatorIdBuilder()
33                     .setOriginator(new Ipv4Address("255.255.255.255"))
34                     .build())
35             .build();
36
37     @Test
38     public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
39         final ByteBuf actual = Unpooled.buffer();
40         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
41                 .serializeAttribute(RESULT, actual);
42         assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
43
44         final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
45                 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
46         assertEquals(RESULT.getOriginatorId(), attributeOut.getOriginatorId());
47     }
48
49     @Test
50     public void testParseEmptyAttribute() {
51         final ByteBuf actual = Unpooled.buffer();
52         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
53                 .serializeAttribute(new AttributesBuilder()
54                         .setOriginatorId(new OriginatorIdBuilder().build())
55                         .build(), actual);
56         assertEquals(Unpooled.buffer(), actual);
57     }
58 }