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.bmp.spi.parser;
11 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.lang.reflect.Constructor;
15 import java.lang.reflect.InvocationTargetException;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.DistinguisherType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.peer.DistinguisherBuilder;
21 public class PeerDistinguisherUtilTest {
23 private static final byte[] DISTINGUISHER_TYPE0 = { 0x00, 0x00, 0x30, 0x39, 0x00, 0x09, (byte)0xfb, (byte)0xf1};
24 private static final byte[] DISTINGUISHER_TYPE1 = { 0x00, 0x01, 0x7f, (byte)0x9c, (byte)0x97, 0x0b, (byte)0xd4, 0x31};
25 private static final byte[] DISTINGUISHER_TYPE2 = { 0x00, 0x02, 0x00, 0x01, (byte)0xe2, 0x40, (byte)0xd4, 0x31};
27 private static final int ASN = 12345;
28 private static final int ASN_FOUR_BYTES = 123456;
29 private static final int ISP_NUMBER = 54321;
30 private static final int ISP_NUMBER_FOUR_BYTES = 654321;
31 private static final String IPV4_ADDRESS = "127.156.151.11";
34 public void testPeerDistingisherType0() {
35 final DistinguisherBuilder dBuilder = new DistinguisherBuilder();
36 dBuilder.setDistinguisherType(DistinguisherType.Type0);
37 dBuilder.setDistinguisher(ASN + ":" + ISP_NUMBER_FOUR_BYTES);
39 assertEquals(dBuilder.build(), PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE0)));
41 final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE0.length);
42 PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer);
43 Assert.assertArrayEquals(DISTINGUISHER_TYPE0, buffer.array());
47 public void testPeerDistingisherType1() {
48 final DistinguisherBuilder dBuilder = new DistinguisherBuilder();
49 dBuilder.setDistinguisherType(DistinguisherType.Type1);
50 dBuilder.setDistinguisher(IPV4_ADDRESS + ":" + ISP_NUMBER);
52 assertEquals(dBuilder.build(), PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE1)));
54 final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE1.length);
55 PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer);
56 Assert.assertArrayEquals(DISTINGUISHER_TYPE1, buffer.array());
60 public void testPeerDistingisherType2() {
61 final DistinguisherBuilder dBuilder = new DistinguisherBuilder();
62 dBuilder.setDistinguisherType(DistinguisherType.Type2);
63 dBuilder.setDistinguisher(ASN_FOUR_BYTES + ":" + ISP_NUMBER);
65 assertEquals(dBuilder.build(), PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE2)));
67 final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE2.length);
68 PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer);
69 Assert.assertArrayEquals(DISTINGUISHER_TYPE2, buffer.array());
72 @Test(expected=UnsupportedOperationException.class)
73 public void testPeerDistinguisherUtilPrivateConstructor() throws Throwable {
74 final Constructor<PeerDistinguisherUtil> c = PeerDistinguisherUtil.class.getDeclaredConstructor();
75 c.setAccessible(true);
78 } catch (final InvocationTargetException e) {