Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / AggregatorAttributeParserTest.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.AsNumber;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AggregatorBuilder;
25
26 public class AggregatorAttributeParserTest {
27     private static final byte[] ATTRIBUTE_BYTES = {
28         (byte) 0xC0, (byte) 0x07, (byte) 0x08,
29         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
30         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01
31     };
32
33     private static final Attributes RESULT = new AttributesBuilder()
34             .setAggregator(new AggregatorBuilder()
35                     .setAsNumber(new AsNumber(1L))
36                     .setNetworkAddress(new Ipv4Address("255.255.255.1"))
37                     .build())
38             .build();
39
40     @Test
41     public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
42         final ByteBuf actual = Unpooled.buffer();
43         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
44                 .serializeAttribute(RESULT, actual);
45         assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
46
47         final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
48                 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
49         assertEquals(RESULT.getAggregator(), attributeOut.getAggregator());
50     }
51
52     @Test
53     public void testParseEmptyAttribute() {
54         final ByteBuf actual = Unpooled.buffer();
55         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
56                 .serializeAttribute(new AttributesBuilder()
57                         .setAggregator(new AggregatorBuilder()
58                                 .build())
59                         .build(), actual);
60         assertEquals(Unpooled.buffer(), actual);
61     }
62 }