Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / test / java / org / opendaylight / protocol / pcep / api / APITest.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.api;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotSame;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
17 import org.opendaylight.protocol.pcep.PCEPErrors;
18 import org.opendaylight.protocol.pcep.PCEPObject;
19 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
20 import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
21 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
23
24 /**
25  *
26  */
27 public class APITest {
28
29         @Test
30         public void testDeserializerException() {
31                 final PCEPDeserializerException e = new PCEPDeserializerException("Some error message.");
32                 assertEquals("Some error message.", e.getErrorMessage());
33
34                 final PCEPDeserializerException e1 = new PCEPDeserializerException(new IllegalArgumentException(), "Some error message.");
35                 assertEquals("Some error message.", e1.getErrorMessage());
36                 assertTrue(e1.getCause() instanceof IllegalArgumentException);
37         }
38
39         @Test
40         public void testDocumentedException() throws PCEPDocumentedException {
41                 final PCEPDocumentedException de = new PCEPDocumentedException("", PCEPErrors.C_BIT_SET);
42                 assertEquals(PCEPErrors.C_BIT_SET, de.getError());
43         }
44
45         @Test
46         public void testPCEPObject() {
47                 final PCEPObject obj1 = new PCEPObject(true, false) {
48                 };
49                 final PCEPObject obj2 = new PCEPErrorObject(PCEPErrors.CANNOT_PROCESS_STATE_REPORT);
50                 final PCEPObject obj4 = new PCEPObject(true, false) {
51                 };
52
53                 assertNotSame(obj1, obj2);
54                 assertNotSame(obj1, obj4);
55                 assertEquals(obj1.hashCode(), obj4.hashCode());
56                 assertEquals(obj1.toString(), obj4.toString());
57
58         }
59
60         @Test
61         public void testSubobject() {
62                 final ExplicitRouteSubobject sub1 = new EROAsNumberSubobject(new AsNumber((long) 100), true);
63                 final ExplicitRouteSubobject sub2 = new ExplicitRouteSubobject(false) {
64                 };
65                 final ExplicitRouteSubobject sub3 = new ExplicitRouteSubobject(false) {
66                 };
67                 final ExplicitRouteSubobject sub4 = new EROAsNumberSubobject(new AsNumber((long) 100), true);
68
69                 assertNotSame(sub1, sub2);
70                 assertNotSame(sub2, sub3);
71                 assertEquals(sub1, sub4);
72                 assertNotSame(sub2, sub3);
73                 assertEquals(sub1.hashCode(), sub4.hashCode());
74                 assertEquals(sub2.toString(), sub3.toString());
75         }
76 }