8475f45d896c10aee5409f3bacf1cb68f43a8bef
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / UtilTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
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;
22
23 public class UtilTest {
24
25     private static final Open OPEN = new OpenBuilder().build();
26
27     @Test
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());
38     }
39
40     @Test
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());
49     }
50
51     @Test(expected = UnsupportedOperationException.class)
52     public void testPrivateConstructor() throws Throwable {
53         final Constructor<Util> c = Util.class.getDeclaredConstructor();
54         c.setAccessible(true);
55         try {
56             c.newInstance();
57         } catch (InvocationTargetException e) {
58             throw e.getCause();
59         }
60     }
61
62 }