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.spi;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.spi.PCEPErrorMapping.PCEPErrorIdentifier;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
20 public class APITest {
23 public void testDeserializerException() {
24 final PCEPDeserializerException e = new PCEPDeserializerException("Some error message.");
25 assertEquals("Some error message.", e.getMessage());
27 final PCEPDeserializerException e1 = new PCEPDeserializerException("Some error message.", new IllegalArgumentException());
28 assertEquals("Some error message.", e1.getMessage());
29 assertTrue(e1.getCause() instanceof IllegalArgumentException);
33 public void testObjectHeader() {
34 ObjectHeaderImpl header = new ObjectHeaderImpl(null, true);
35 assertEquals("ObjectHeader [objClass=, processed=null, ignored=true]", header.toString());
36 assertTrue(header.isIgnore());
37 assertNull(header.isProcessingRule());
39 assertEquals(new ObjectHeaderImpl(null, true).hashCode(), header.hashCode());
40 assertTrue(new ObjectHeaderImpl(null, true).equals(header));
44 public void testUnknownObject() {
45 UnknownObject un = new UnknownObject(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS);
46 assertFalse(un.isIgnore());
47 assertFalse(un.isProcessingRule());
48 assertEquals(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS, un.getError());
49 final PCEPErrorMapping mapping = PCEPErrorMapping.getInstance();
50 final PCEPErrorIdentifier id = mapping.getFromErrorsEnum(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS);
51 assertEquals(id.getType(), un.getErrors().get(0).getErrorObject().getType().shortValue());
53 final Object o = new CCloseBuilder().build();
54 UnknownObject unknown = new UnknownObject(PCEPErrors.LSP_RSVP_ERROR, o);
55 assertEquals(Object.class, unknown.getImplementedInterface());
56 assertEquals(o, unknown.getInvalidObject());