2 * Copyright (c) 2013 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.pcep.impl.tlv;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
16 import java.io.IOException;
18 import org.junit.Test;
20 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
21 import org.opendaylight.protocol.pcep.impl.PCEPTlvParser;
22 import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
23 import org.opendaylight.protocol.util.ByteArray;
25 public class PCEStatefulCapabilityTlvParserTest {
27 public void testEquality() throws IOException, PCEPDeserializerException {
28 final PCEStatefulCapabilityTlv objToTest1a = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(
29 ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0);
30 final PCEStatefulCapabilityTlv objToTest1b = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(
31 ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0);
32 final PCEStatefulCapabilityTlv objToTest2 = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(
33 ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv2.bin")).get(0);
35 assertTrue(objToTest1a.equals(objToTest1a));
36 assertFalse(objToTest1a.equals(objToTest2));
37 assertFalse(objToTest1a == objToTest1b);
38 assertTrue(objToTest1a.equals(objToTest1b));
42 public void testSerialization() throws PCEPDeserializerException, IOException {
43 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin");
45 final PCEStatefulCapabilityTlv objToTest = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(bytesFromFile).get(0);
46 assertTrue(objToTest.isUpdate());
47 assertTrue(objToTest.isVersioned());
49 final byte[] bytesActual = PCEPTlvParser.put(objToTest);
51 assertArrayEquals(bytesFromFile, bytesActual);
55 public void testConstruction() throws PCEPDeserializerException, IOException {
56 final PCEStatefulCapabilityTlv expected = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(
57 ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0);
59 final PCEStatefulCapabilityTlv actual = new PCEStatefulCapabilityTlv(false, true, true);
61 assertEquals(expected, actual);
64 @Test(expected = PCEPDeserializerException.class)
65 public void testValidityControl() throws Exception {
67 * Should throw exception
69 PCEPTlvParser.parse(ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin"));