YANG revision dates mass-update
[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.Ipv4AddressNoZone;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AggregatorBuilder;
25 import org.opendaylight.yangtools.yang.common.Uint32;
26
27 public class AggregatorAttributeParserTest {
28     private static final byte[] ATTRIBUTE_BYTES = {
29         (byte) 0xC0, (byte) 0x07, (byte) 0x08,
30         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
31         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01
32     };
33
34     private static final Attributes RESULT = new AttributesBuilder()
35             .setAggregator(new AggregatorBuilder()
36                     .setAsNumber(new AsNumber(Uint32.ONE))
37                     .setNetworkAddress(new Ipv4AddressNoZone("255.255.255.1"))
38                     .build())
39             .build();
40
41     @Test
42     public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
43         final ByteBuf actual = Unpooled.buffer();
44         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
45                 .serializeAttribute(RESULT, actual);
46         assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
47
48         final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
49                 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
50         assertEquals(RESULT.getAggregator(), attributeOut.getAggregator());
51     }
52
53     @Test
54     public void testParseEmptyAttribute() {
55         final ByteBuf actual = Unpooled.buffer();
56         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
57                 .serializeAttribute(new AttributesBuilder()
58                         .setAggregator(new AggregatorBuilder()
59                                 .build())
60                         .build(), actual);
61         assertEquals(Unpooled.buffer(), actual);
62     }
63 }