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
8 package org.opendaylight.protocol.bgp.parser.impl.message.update;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.ArrayList;
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.Ipv4AddressNoZone;
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;
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
31 ClusterIdAttributeParser parser;
35 this.parser = new ClusterIdAttributeParser();
39 public void testParserAttribute() throws Exception {
40 final List<ClusterIdentifier> list = new ArrayList<>();
41 final Ipv4AddressNoZone ip1 = new Ipv4AddressNoZone("192.168.1.1");
42 final Ipv4AddressNoZone ip2 = new Ipv4AddressNoZone("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)
49 final ByteBuf output = Unpooled.buffer();
50 this.parser.serializeAttribute(clusterId, output);
52 assertArrayEquals(CLUSTER_ID_BYTES, ByteArray.getAllBytes(output));
54 AttributesBuilder clusterIdOutput = new AttributesBuilder();
55 this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(CLUSTER_ID_BYTES, 3)), clusterIdOutput,
57 assertEquals(clusterId, clusterIdOutput.build());
61 public void testParseEmptyListAttribute() {
62 final List<ClusterIdentifier> list = new ArrayList<>();
63 final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
65 final ByteBuf output = Unpooled.buffer();
66 this.parser.serializeAttribute(clusterId, output);
67 assertEquals(Unpooled.buffer(), output);
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);