Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / ClusterIdAttributeParserTest.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 package org.opendaylight.protocol.bgp.parser.impl.message.update;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import com.google.common.collect.Lists;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
25
26 public class ClusterIdAttributeParserTest {
27     private static final byte[] CLUSTER_ID_BYTES = {
28         (byte) 0x80, (byte) 0x0A, (byte) 0x08,
29         (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x1, (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x2
30     };
31     ClusterIdAttributeParser parser;
32
33     @Before
34     public void setUp() {
35         this.parser = new ClusterIdAttributeParser();
36     }
37
38     @Test
39     public void testParserAttribute() throws Exception {
40         final List<ClusterIdentifier> list = Lists.newArrayList();
41         final Ipv4Address ip1 = new Ipv4Address("192.168.1.1");
42         final Ipv4Address ip2 = new Ipv4Address("192.168.1.2");
43         list.add(new ClusterIdentifier(ip1));
44         list.add(new ClusterIdentifier(ip2));
45         final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
46             .build()).build();
47
48
49         final ByteBuf output = Unpooled.buffer();
50         this.parser.serializeAttribute(clusterId, output);
51
52         assertArrayEquals(CLUSTER_ID_BYTES, ByteArray.getAllBytes(output));
53
54         AttributesBuilder clusterIdOutput = new AttributesBuilder();
55         this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(CLUSTER_ID_BYTES, 3)), clusterIdOutput,
56             null);
57         assertEquals(clusterId, clusterIdOutput.build());
58     }
59
60     @Test
61     public void testParseEmptyListAttribute() {
62         final List<ClusterIdentifier> list = Lists.newArrayList();
63         final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
64             .build()).build();
65         final ByteBuf output = Unpooled.buffer();
66         this.parser.serializeAttribute(clusterId, output);
67         assertEquals(Unpooled.buffer(), output);
68     }
69
70     @Test
71     public void testParseEmptyAttribute() {
72         final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().build()).build();
73         final ByteBuf output = Unpooled.buffer();
74         this.parser.serializeAttribute(clusterId, output);
75         assertEquals(Unpooled.buffer(), output);
76     }
77 }