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