BUG-47 : switched subobjects to generated source code.
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPXROSubobjectParserTest.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 package org.opendaylight.protocol.pcep.impl;
9
10 import static org.junit.Assert.fail;
11
12 import java.io.IOException;
13
14 import org.junit.Test;
15 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
17 import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
18 import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
19 import org.opendaylight.protocol.util.ByteArray;
20
21 public class PCEPXROSubobjectParserTest {
22
23         @Test
24         public void testSerDeser() throws PCEPDeserializerException, IOException {
25                 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfXROSubobjects.bin");
26                 // final List<ExcludeRouteSubobject> objsToTest = PCEPXROSubobjectParser.parse(bytesFromFile);
27
28                 // assertEquals(5, objsToTest.size());
29                 //
30                 // assertEquals(
31                 // objsToTest.get(0),
32                 // new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(new byte[] { (byte) 192, (byte) 168, (byte) 0,
33                 // (byte) 0 }, 16)), true, XROSubobjectAttribute.NODE));
34                 // assertEquals(
35                 // objsToTest.get(1),
36                 // new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte)
37                 // 0x56,
38                 // (byte) 0x78, (byte) 0x90, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0x12,
39                 // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0, (byte) 0 }, 112)), true, XROSubobjectAttribute.INTERFACE));
40                 // assertEquals(objsToTest.get(2), new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0,
41                 // (byte) 0, (byte) 0,
42                 // (byte) 0x20 }), new UnnumberedInterfaceIdentifier(0x1234L), false, XROSubobjectAttribute.SRLG));
43                 // assertEquals(objsToTest.get(3), new XROAsNumberSubobject(new AsNumber((long) 0x1234), false));
44                 // assertEquals(objsToTest.get(4), new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
45
46                 // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest));
47
48         }
49
50         @Test
51         public void testDifferentLengthExceptions() {
52                 final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data for parsing subobjects
53
54                 try {
55                         new XROAsNumberSubobjectParser().parseSubobject(bytes, true);
56                         fail("");
57                 } catch (final PCEPDeserializerException e) {
58                 }
59
60                 try {
61                         new XROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, true);
62                         fail("");
63                 } catch (final PCEPDeserializerException e) {
64                 }
65
66                 try {
67                         new XROIpPrefixSubobjectParser().parseSubobject(bytes, true);
68                         fail("");
69                 } catch (final PCEPDeserializerException e) {
70                 }
71         }
72 }