2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
11 import static org.junit.Assert.assertEquals;
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;
25 public class SourceASHandlerTest {
26 private static final byte[] INPUT = {0, 1, 0, 0, 0, 0};
28 private final SourceASHandler handler = new SourceASHandler();
31 public void testHandler() {
32 final SourceAsExtendedCommunityCase expected = new SourceAsExtendedCommunityCaseBuilder()
33 .setSourceAsExtendedCommunity(new SourceAsExtendedCommunityBuilder()
34 .setGlobalAdministrator(new ShortAsNumber(Uint32.ONE))
37 final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
38 Assert.assertEquals(expected, exComm);
40 final ByteBuf output = Unpooled.buffer(INPUT.length);
41 this.handler.serializeExtendedCommunity(expected, output);
42 Assert.assertArrayEquals(INPUT, output.array());
44 assertEquals(9, this.handler.getSubType());
47 @Test(expected = IllegalArgumentException.class)
48 public void testHandlerError() {
49 this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(),