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 / RouteOrigin4OctectASEcHandlerTest.java
1 /*
2  * Copyright (c) 2016 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 io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandler;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.spec.common.As4SpecificCommon;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.spec.common.As4SpecificCommonBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4RouteOriginExtendedCommunityCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
26 import org.opendaylight.yangtools.yang.common.Uint16;
27 import org.opendaylight.yangtools.yang.common.Uint32;
28
29 public final class RouteOrigin4OctectASEcHandlerTest {
30
31     public static final byte[] INPUT = {
32         0, 0, 0, 20, 0, 100
33     };
34     public static final As4SpecificCommon AS_COMMON = new As4SpecificCommonBuilder()
35             .setAsNumber(new AsNumber(Uint32.valueOf(20)))
36             .setLocalAdministrator(Uint16.valueOf(100))
37             .build();
38
39     private RouteOrigin4OctectASEcHandler handler;
40
41     @Before
42     public void before() {
43         this.handler = new RouteOrigin4OctectASEcHandler();
44     }
45
46     @Test
47     public void testHandler() throws BGPDocumentedException, BGPParsingException {
48
49         final As4RouteOriginExtendedCommunityCase expected = new As4RouteOriginExtendedCommunityCaseBuilder()
50             .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
51                 .setAs4SpecificCommon(AS_COMMON).build()).build();
52
53         final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
54         Assert.assertEquals(expected, exComm);
55
56         final ByteBuf output = Unpooled.buffer(INPUT.length);
57         this.handler.serializeExtendedCommunity(expected, output);
58         Assert.assertArrayEquals(INPUT, output.array());
59     }
60
61     @Test(expected = IllegalArgumentException.class)
62     public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
63         this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
64     }
65 }