Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / LocalPreferenceAttributeParserTest.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.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
23
24 public class LocalPreferenceAttributeParserTest {
25     private static final byte[] ATTRIBUTE_BYTES = {
26         (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
27     };
28
29     private static final Attributes RESULT = new AttributesBuilder()
30             .setLocalPref(new LocalPrefBuilder()
31                     .setPref(1L)
32                     .build())
33             .build();
34
35     @Test
36     public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
37         final ByteBuf actual = Unpooled.buffer();
38         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
39                 .serializeAttribute(RESULT, actual);
40         assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
41
42         final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
43                 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
44         assertEquals(RESULT.getLocalPref(), attributeOut.getLocalPref());
45     }
46
47     @Test
48     public void testParseEmptyAttribute() {
49         final ByteBuf actual = Unpooled.buffer();
50         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
51                 .serializeAttribute(new AttributesBuilder()
52                         .setLocalPref(new LocalPrefBuilder().build())
53                         .build(), actual);
54         assertEquals(Unpooled.buffer(), actual);
55     }
56 }