Bump versions to 0.21.8-SNAPSHOT
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / UnrecognizedAttributesSerializerTest.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  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
12 import com.google.common.collect.ImmutableMap;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.ServiceLoader;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder;
23 import org.opendaylight.yangtools.yang.common.Uint8;
24
25 public class UnrecognizedAttributesSerializerTest {
26     @Test
27     public void testUnrecognizedAttributesSerializer() {
28         final byte[] unrecognizedValue1 = {
29             (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35
30         };
31         final byte[] unrecognizedValue2 = {
32             (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75
33         };
34         final byte[] unrecognizedBytes = {
35             (byte)0xe0, 0x65, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35,
36             (byte)0xd3, 0x5d, 0x35, (byte)0xe0, 0x66, 0x0c, (byte)0xd3, 0x5d, 0x35, (byte)0xd3, 0x5d, 0x35,
37             (byte)0xd7, 0x5d, 0x75, (byte)0xd7, 0x5d, 0x75
38         };
39         final UnrecognizedAttributes unrecognizedAttribute1 = new UnrecognizedAttributesBuilder().setPartial(true)
40                 .setTransitive(true).setType(Uint8.valueOf(101)).setValue(unrecognizedValue1).build();
41         final UnrecognizedAttributes unrecognizedAttribute2 = new UnrecognizedAttributesBuilder().setPartial(true)
42                 .setTransitive(true).setType(Uint8.valueOf(102)).setValue(unrecognizedValue2).build();
43         final Attributes attrs = new AttributesBuilder()
44                 .setUnrecognizedAttributes(ImmutableMap.of(unrecognizedAttribute1.key(), unrecognizedAttribute1,
45                     unrecognizedAttribute2.key(), unrecognizedAttribute2)).build();
46
47         final ByteBuf buffer = Unpooled.buffer();
48         ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst().orElseThrow().getAttributeRegistry()
49             .serializeAttribute(attrs, buffer);
50         assertArrayEquals(unrecognizedBytes, ByteArray.readAllBytes(buffer));
51     }
52 }