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 / SourceAS4OctectASHandlerTest.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 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.SourceAS4OctectHandler;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
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.SourceAs4ExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.SourceAs4ExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.source.as._4.extended.community._case.SourceAs4ExtendedCommunityBuilder;
23 import org.opendaylight.yangtools.yang.common.Uint32;
24
25 public class SourceAS4OctectASHandlerTest {
26     private static final byte[] INPUT = {0, 0, 0, 20, 0, 0};
27     private final SourceAS4OctectHandler handler = new SourceAS4OctectHandler();
28
29     @Test
30     public void testHandler() {
31         final SourceAs4ExtendedCommunityCase expected = new SourceAs4ExtendedCommunityCaseBuilder()
32                 .setSourceAs4ExtendedCommunity(new SourceAs4ExtendedCommunityBuilder()
33                         .setGlobalAdministrator(new AsNumber(Uint32.valueOf(20))).build()).build();
34
35         final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
36         assertEquals(expected, exComm);
37
38         final ByteBuf output = Unpooled.buffer(INPUT.length);
39         this.handler.serializeExtendedCommunity(expected, output);
40         Assert.assertArrayEquals(INPUT, output.array());
41
42         assertEquals(209, this.handler.getSubType());
43     }
44
45     @Test(expected = IllegalArgumentException.class)
46     public void testHandlerError() {
47         this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
48     }
49 }