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 / VrfRouteImportHandlerTest.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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
10
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.VrfRouteImportExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
24
25 public class VrfRouteImportHandlerTest {
26
27     private static final byte[] INPUT = {12, 51, 2, 5, 21, 45};
28     private final VrfRouteImportHandler handler = new VrfRouteImportHandler();
29
30     @Test
31     public void testHandler() {
32         final VrfRouteImportExtendedCommunityCase expected = new VrfRouteImportExtendedCommunityCaseBuilder()
33                 .setVrfRouteImportExtendedCommunity(new VrfRouteImportExtendedCommunityBuilder()
34                         .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
35                                 .setGlobalAdministrator(new Ipv4AddressNoZone("12.51.2.5"))
36                                 .setLocalAdministrator(new byte[]{21, 45}).build())
37                         .build())
38                 .build();
39
40         final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
41         assertEquals(expected, exComm);
42
43         final ByteBuf output = Unpooled.buffer(INPUT.length);
44         this.handler.serializeExtendedCommunity(expected, output);
45         Assert.assertArrayEquals(INPUT, output.array());
46
47         assertEquals(11, this.handler.getSubType());
48     }
49
50     @Test(expected = IllegalArgumentException.class)
51     public void testHandlerError() {
52         this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
53     }
54 }