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