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 static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNull;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.impl.spi.Util;
17 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr;
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 {
25 private static final Open OPEN = new OpenBuilder().build();
28 public void testCreateErrorMessageWithOpen() {
29 final Pcerr errMsg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
30 assertThat(errMsg.getPcerrMessage().getErrorType(), isA(SessionCase.class));
31 final SessionCase sessionCase = (SessionCase) errMsg.getPcerrMessage().getErrorType();
32 assertEquals(OPEN, sessionCase.getSession().getOpen());
33 final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
34 assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
35 assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
39 public void testCreateErrorMessage() {
40 final Pcerr errMsg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, null);
41 assertNull(errMsg.getPcerrMessage().getErrorType());
42 final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
43 assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
44 assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());