Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / tlv / PCEStatefulCapabilityTlvParserTest.java
1 /*
2  * Copyright (c) 2013 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
9 package org.opendaylight.protocol.pcep.impl.tlv;
10
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;
15
16 import java.io.IOException;
17
18 import org.junit.Test;
19
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;
24
25 public class PCEStatefulCapabilityTlvParserTest {
26     @Test
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);
34
35         assertTrue(objToTest1a.equals(objToTest1a));
36         assertFalse(objToTest1a.equals(objToTest2));
37         assertFalse(objToTest1a == objToTest1b);
38         assertTrue(objToTest1a.equals(objToTest1b));
39     }
40
41     @Test
42     public void testSerialization() throws PCEPDeserializerException, IOException {
43         final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin");
44
45         final PCEStatefulCapabilityTlv objToTest = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(bytesFromFile).get(0);
46         assertTrue(objToTest.isUpdate());
47         assertTrue(objToTest.isVersioned());
48
49         final byte[] bytesActual = PCEPTlvParser.put(objToTest);
50
51         assertArrayEquals(bytesFromFile, bytesActual);
52     }
53
54     @Test
55     public void testConstruction() throws PCEPDeserializerException, IOException {
56         final PCEStatefulCapabilityTlv expected = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(
57                 ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0);
58
59         final PCEStatefulCapabilityTlv actual = new PCEStatefulCapabilityTlv(false, true, true);
60
61         assertEquals(expected, actual);
62     }
63
64     @Test(expected = PCEPDeserializerException.class)
65     public void testValidityControl() throws Exception {
66         /*
67          * Should throw exception
68          */
69         PCEPTlvParser.parse(ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin"));
70     }
71
72 }