Remove use of junit-addons
[lispflowmapping.git] / mappingservice / lisp-proto / src / test / java / org / opendaylight / lispflowmapping / serializer / address / ServicePathTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  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.lispflowmapping.serializer.address;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import java.nio.ByteBuffer;
14 import org.junit.Test;
15 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
16 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
17 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
18 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
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.ServicePathLcaf;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
23
24 /**
25  * Test class for Service Path Serializer.
26  *
27  * @author Lorand Jakab
28  */
29 public class ServicePathTest extends BaseTestCase {
30
31     @Test
32     public void deserialize__Simple() throws Exception {
33         Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
34                 + "11 00 00 04 "
35                 + "AA BB CC FF"),
36                 new LispAddressSerializerContext(null));
37         assertEquals(ServicePathLcaf.VALUE, address.getAddressType());
38         ServicePath sp = (ServicePath) address.getAddress();
39
40         assertEquals(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }),
41                 sp.getServicePath().getServicePathId().getValue().intValue());
42         assertEquals((byte) 0xFF, sp.getServicePath().getServiceIndex().byteValue());
43     }
44
45     @Test
46     public void serialize__Simple() throws Exception {
47         Eid eid = LispAddressUtil.asServicePathEid(-1, 1L, (short) 0xFF);
48
49         ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
50         LispAddressSerializer.getInstance().serialize(buf, eid);
51         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 "
52                 + "11 00 00 04 "
53                 + "00 00 01 FF");
54         assertArrayEquals(expectedBuf.array(), buf.array());
55     }
56 }