Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / EncapsulationECTest.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
18 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.EncapsulationTunnelType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.EncapsulationCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.EncapsulationCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.LinkBandwidthCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.encapsulation._case.EncapsulationExtendedCommunityBuilder;
26
27 public class EncapsulationECTest {
28     private static final byte[] RESULT = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a };
29     private static final int COMMUNITY_VALUE_SIZE = 6;
30     private static final EncapsulationTunnelType TUNNEL_TYPE = EncapsulationTunnelType.Mpls;
31     private EncapsulationEC parser;
32
33     @Before
34     public void setUp() {
35         this.parser = new EncapsulationEC();
36     }
37
38     @Test
39     public void testParser() throws BGPParsingException, BGPDocumentedException {
40         final ByteBuf buffer = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
41
42         final EncapsulationCase expected = new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(
43             new EncapsulationExtendedCommunityBuilder().setTunnelType(TUNNEL_TYPE).build()).build();
44         this.parser.serializeExtendedCommunity(expected, buffer);
45         assertArrayEquals(RESULT, ByteArray.getAllBytes(buffer));
46
47         final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
48         assertEquals(expected, result);
49     }
50
51     @Test(expected = IllegalArgumentException.class)
52     public void testWrongCase() {
53         this.parser.serializeExtendedCommunity(new LinkBandwidthCaseBuilder().build(), null);
54     }
55
56     @Test
57     public void testSubtype() {
58         assertEquals(EncapsulationEC.SUBTYPE, this.parser.getSubType());
59     }
60 }