6d8f8ce165657e3c7606a0396e1c3fab5e259dde
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / RouteOriginAsTwoOctetEcHandlerTest.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 io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
15 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
21 import org.opendaylight.yangtools.yang.common.Uint32;
22
23 public class RouteOriginAsTwoOctetEcHandlerTest {
24     private static final byte[] INPUT = {
25         0, 24, 4, 2, 8, 7
26     };
27
28     @Test
29     public void testHandler() throws BGPDocumentedException, BGPParsingException {
30         final RouteOriginAsTwoOctetEcHandler handler = new RouteOriginAsTwoOctetEcHandler();
31         final RouteOriginExtendedCommunityCase expected = new RouteOriginExtendedCommunityCaseBuilder()
32                 .setRouteOriginExtendedCommunity(new RouteOriginExtendedCommunityBuilder()
33                     .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(24)))
34                     .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build())
35                 .build();
36
37         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
38         Assert.assertEquals(expected, exComm);
39
40         final ByteBuf output = Unpooled.buffer(INPUT.length);
41         handler.serializeExtendedCommunity(expected, output);
42         Assert.assertArrayEquals(INPUT, output.array());
43     }
44 }