YANG revision dates mass-update
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / MultiExitDiscriminatorAttributeParserTest.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.rev200120.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder;
23 import org.opendaylight.yangtools.yang.common.Uint32;
24
25 public class MultiExitDiscriminatorAttributeParserTest {
26     private static final byte[] ATTRIBUTE_BYTES = {
27         (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
28     };
29
30     private static final Attributes RESULT = new AttributesBuilder()
31             .setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ONE).build()).build();
32
33     @Test
34     public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
35         final ByteBuf actual = Unpooled.buffer();
36         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
37                 .serializeAttribute(RESULT, actual);
38         assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
39
40         final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
41                 .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
42         assertEquals(RESULT.getMultiExitDisc(), attributeOut.getMultiExitDisc());
43     }
44
45     @Test
46     public void testParseEmptyAttribute() {
47         final ByteBuf actual = Unpooled.buffer();
48         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
49                 .serializeAttribute(new AttributesBuilder()
50                         .setMultiExitDisc(new MultiExitDiscBuilder().build())
51                         .build(), actual);
52         assertEquals(Unpooled.buffer(), actual);
53     }
54 }