Add new revision for pcep types model
[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
9 package org.opendaylight.protocol.pcep.impl;
10
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;
23
24 public class UtilTest {
25
26     private static final Open OPEN = new OpenBuilder().build();
27
28     @Test
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());
39     }
40
41     @Test
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());
50     }
51
52     @Test(expected=UnsupportedOperationException.class)
53     public void testPrivateConstructor() throws Throwable {
54         final Constructor<Util> c = Util.class.getDeclaredConstructor();
55         c.setAccessible(true);
56         try {
57             c.newInstance();
58         } catch (InvocationTargetException e) {
59             throw e.getCause();
60         }
61     }
62
63 }