2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
25 public class Ipv4SpecificEcHandlerTest {
27 private static final byte[] INPUT = {
32 public void testHandlerDeprecated() {
33 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
34 final Inet4SpecificExtendedCommunityCase input
35 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
36 new Inet4SpecificExtendedCommunityBuilder()
37 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
38 .setLocalAdministrator(new byte[]{21, 45}).build()).build();
40 final Inet4SpecificExtendedCommunityCase expected
41 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
42 new Inet4SpecificExtendedCommunityBuilder()
43 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
44 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
45 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
47 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
48 assertEquals(expected, exComm);
50 final ByteBuf output = Unpooled.buffer(INPUT.length);
51 handler.serializeExtendedCommunity(input, output);
52 assertArrayEquals(INPUT, output.array());
56 public void testHandle() {
57 final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
58 final Inet4SpecificExtendedCommunityCase expected
59 = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
60 new Inet4SpecificExtendedCommunityBuilder()
61 .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
62 .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
63 .setLocalAdministrator(new byte[]{21, 45}).build()).build())
66 final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
67 assertEquals(expected, exComm);
69 final ByteBuf output = Unpooled.buffer(INPUT.length);
70 handler.serializeExtendedCommunity(expected, output);
71 assertArrayEquals(INPUT, output.array());