2 * Copyright (c) 2014 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
9 package org.opendaylight.protocol.pcep.impl;
11 import java.lang.reflect.Constructor;
12 import java.lang.reflect.InvocationTargetException;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.protocol.pcep.impl.spi.Util;
16 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase;
24 public class UtilTest {
26 private static final Open OPEN = new OpenBuilder().build();
29 public void testCreateErrorMessageWithOpen() {
30 final Message msg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
31 Assert.assertTrue(msg instanceof Pcerr);
32 final Pcerr errMsg = (Pcerr) msg;
33 Assert.assertTrue(errMsg.getPcerrMessage().getErrorType() instanceof SessionCase);
34 final SessionCase sessionCase = (SessionCase) errMsg.getPcerrMessage().getErrorType();
35 Assert.assertEquals(OPEN, sessionCase.getSession().getOpen());
36 final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
37 Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType().shortValue());
38 Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue().shortValue());
42 public void testCreateErrorMessage() {
43 final Message msg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, null);
44 Assert.assertTrue(msg instanceof Pcerr);
45 final Pcerr errMsg = (Pcerr) msg;
46 Assert.assertNull(errMsg.getPcerrMessage().getErrorType());
47 final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
48 Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType().shortValue());
49 Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue().shortValue());
52 @Test(expected=UnsupportedOperationException.class)
53 public void testPrivateConstructor() throws Throwable {
54 final Constructor<Util> c = Util.class.getDeclaredConstructor();
55 c.setAccessible(true);
58 } catch (InvocationTargetException e) {