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
8 package org.opendaylight.protocol.pcep.api;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotSame;
12 import static org.junit.Assert.assertTrue;
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;
27 public class APITest {
30 public void testDeserializerException() {
31 final PCEPDeserializerException e = new PCEPDeserializerException("Some error message.");
32 assertEquals("Some error message.", e.getErrorMessage());
34 final PCEPDeserializerException e1 = new PCEPDeserializerException(new IllegalArgumentException(), "Some error message.");
35 assertEquals("Some error message.", e1.getErrorMessage());
36 assertTrue(e1.getCause() instanceof IllegalArgumentException);
40 public void testDocumentedException() throws PCEPDocumentedException {
41 final PCEPDocumentedException de = new PCEPDocumentedException("", PCEPErrors.C_BIT_SET);
42 assertEquals(PCEPErrors.C_BIT_SET, de.getError());
46 public void testPCEPObject() {
47 final PCEPObject obj1 = new PCEPObject(true, false) {
49 final PCEPObject obj2 = new PCEPErrorObject(PCEPErrors.CANNOT_PROCESS_STATE_REPORT);
50 final PCEPObject obj4 = new PCEPObject(true, false) {
53 assertNotSame(obj1, obj2);
54 assertNotSame(obj1, obj4);
55 assertEquals(obj1.hashCode(), obj4.hashCode());
56 assertEquals(obj1.toString(), obj4.toString());
61 public void testSubobject() {
62 final ExplicitRouteSubobject sub1 = new EROAsNumberSubobject(new AsNumber((long) 100), true);
63 final ExplicitRouteSubobject sub2 = new ExplicitRouteSubobject(false) {
65 final ExplicitRouteSubobject sub3 = new ExplicitRouteSubobject(false) {
67 final ExplicitRouteSubobject sub4 = new EROAsNumberSubobject(new AsNumber((long) 100), true);
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());