Bump versions to 0.21.7-SNAPSHOT
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / Ipv4SpecificEcHandlerTest.java
1 /*
2  * Copyright (c) 2015 Cisco 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.extended.communities;
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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
22
23 public class Ipv4SpecificEcHandlerTest {
24
25     private static final byte[] INPUT = {
26         12, 51, 2, 5, 21, 45
27     };
28
29     @Test
30     public void testHandlerDeprecated() {
31         final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
32         final Inet4SpecificExtendedCommunityCase input = new Inet4SpecificExtendedCommunityCaseBuilder()
33                 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
34                         .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
35                         .setLocalAdministrator(new byte[]{21, 45}).build()).build();
36
37         final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder()
38                 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
39                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
40                                 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
41                                 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
42                 .build();
43         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
44         assertEquals(expected, exComm);
45
46         final ByteBuf output = Unpooled.buffer(INPUT.length);
47         handler.serializeExtendedCommunity(input, output);
48         assertArrayEquals(INPUT, output.array());
49     }
50
51     @Test
52     public void testHandle() {
53         final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
54         final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder()
55                 .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder()
56                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
57                                 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
58                                 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
59                 .build();
60
61         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
62         assertEquals(expected, exComm);
63
64         final ByteBuf output = Unpooled.buffer(INPUT.length);
65         handler.serializeExtendedCommunity(expected, output);
66         assertArrayEquals(INPUT, output.array());
67     }
68
69 }