MVPN Models
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / SourceASHandlerTest.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.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunityBuilder;
23
24 public class SourceASHandlerTest {
25     private static final byte[] INPUT = {
26             0, 1, 0, 0, 0, 0
27     };
28
29     private final SourceASHandler handler = new SourceASHandler();
30
31     @Test
32     public void testHandler() {
33         final SourceAsExtendedCommunityCase expected = new SourceAsExtendedCommunityCaseBuilder()
34                 .setSourceAsExtendedCommunity(new SourceAsExtendedCommunityBuilder()
35                         .setGlobalAdministrator(new ShortAsNumber(1L))
36                         .build()).build();
37
38         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
39         Assert.assertEquals(expected, exComm);
40
41         final ByteBuf output = Unpooled.buffer(INPUT.length);
42         handler.serializeExtendedCommunity(expected, output);
43         Assert.assertArrayEquals(INPUT, output.array());
44
45         assertEquals(9, this.handler.getSubType());
46     }
47
48     @Test(expected = IllegalArgumentException.class)
49     public void testHandlerError() {
50         this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(),
51                 null);
52     }
53 }