95c6280fa753de4e1cc92f5d73a0470870086069
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / OpaqueEcHandlerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  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 io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
21
22 public class OpaqueEcHandlerTest {
23
24     private static final byte[] INPUT = {
25         21, 45, 5, 4, 3, 1
26     };
27
28     @Test
29     public void testHandler() throws BGPDocumentedException, BGPParsingException {
30         final OpaqueEcHandler handler = new OpaqueEcHandler();
31         final OpaqueExtendedCommunityCase expected = new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
32                 new OpaqueExtendedCommunityBuilder().setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()).build();
33
34         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
35         Assert.assertEquals(expected, exComm);
36
37         final ByteBuf output = Unpooled.buffer(INPUT.length);
38         handler.serializeExtendedCommunity(expected, output);
39         Assert.assertArrayEquals(INPUT, output.array());
40     }
41
42 }