cb9e03a6b9cee72b6fd5b92c093b35f967ae76bc
[bgpcep.git] / util / src / test / java / org / opendaylight / protocol / util / MplsLabelUtilTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  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.protocol.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
17
18 public class MplsLabelUtilTest {
19
20     private static final long VAL1 = 5;
21     private static final byte[] VAL1_LEFT_BYTES = new byte[] { 0, 0, 0x50 };
22     private static final byte[] VAL1_LEFT_BYTES_BOTTOM = new byte[] { 0, 0, 0x51 };
23
24     @Test
25     public void testCreateLabel() {
26         assertEquals(new MplsLabel(VAL1), MplsLabelUtil
27                 .mplsLabelForByteBuf(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM)));
28     }
29
30     @Test
31     public void testBottomBit() {
32         assertFalse(MplsLabelUtil.getBottomBit(Unpooled.copiedBuffer(VAL1_LEFT_BYTES)));
33         assertTrue(MplsLabelUtil.getBottomBit(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM)));
34     }
35
36     @Test
37     public void testSerialization() {
38         final MplsLabel label = new MplsLabel(VAL1);
39         assertEquals(Unpooled.copiedBuffer(VAL1_LEFT_BYTES), MplsLabelUtil.byteBufForMplsLabel(label));
40         assertEquals(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM),
41             MplsLabelUtil.byteBufForMplsLabelWithBottomBit(label));
42     }
43 }