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