2 * Copyright (c) 2014 Contextream, 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.lispflowmapping.serializer.address;
10 import static org.junit.Assert.assertEquals;
12 import java.nio.ByteBuffer;
14 import junitx.framework.ArrayAssert;
16 import org.junit.Test;
17 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
18 import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
19 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameType;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
29 public class DistinguishedNameSerializerTest extends BaseTestCase {
32 public void deserialize__EmptyString() throws Exception {
33 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 00"), null);
35 assertEquals(DistinguishedNameAfi.class, address.getAddressType());
36 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
38 assertEquals("", distinguishedName.getDistinguishedName().getValue());
43 public void deserialize__DavidString() throws Exception {
44 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 69 64 00"),
47 assertEquals(DistinguishedNameAfi.class, address.getAddressType());
48 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
50 assertEquals("david", distinguishedName.getDistinguishedName().getValue());
55 public void deserialize__inList() throws Exception {
56 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
58 "00 11 64 61 76 69 64 00"), null);
60 assertEquals(AfiListLcaf.class, address.getAddressType());
61 assertEquals("david", ((AfiList) address.getAddress()).getAfiList().getAddressList().get(0)
62 .getDistinguishedNameType().getValue());
66 @Test(expected = LispSerializationException.class)
67 public void deserialize__ShorterBuffer() throws Exception {
68 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
70 "00 11 64 61 76 69 64 00"), null);
73 @Test(expected = LispSerializationException.class)
74 public void deserialize__ShorterBuffer2() throws Exception {
75 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
76 "01 00 00 18 "), null);
80 public void deserialize__ReadUntilZero() throws Exception {
81 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 00 69 64"),
84 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
86 assertEquals("dav", distinguishedName.getDistinguishedName().getValue());
90 public void serialize__Simple() throws Exception {
91 EidBuilder eb = new EidBuilder();
92 eb.setAddressType(DistinguishedNameAfi.class);
93 eb.setVirtualNetworkId(null);
94 eb.setAddress(new DistinguishedNameBuilder().setDistinguishedName(new DistinguishedNameType("david")).build());
96 ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
97 LispAddressSerializer.getInstance().serialize(buf, eb.build());
98 ByteBuffer expectedBuf = hexToByteBuffer("00 11 64 61 76 69 64 00");
99 ArrayAssert.assertEquals(expectedBuf.array(), buf.array());