Merge "ROADM To ROADM Path Calculation"
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / service / PCEServiceWrapperTest.java
1 /*
2  * Copyright © 2018 Orange, 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.transportpce.servicehandler.service;
9
10 import java.lang.reflect.InvocationTargetException;
11 import java.lang.reflect.Method;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.transportpce.common.ResponseCodes;
17 import org.opendaylight.transportpce.pce.service.PathComputationService;
18 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
19 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
20 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
21 import org.opendaylight.transportpce.test.AbstractTest;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
29
30 public class PCEServiceWrapperTest extends AbstractTest {
31
32     private PathComputationService pathComputationService;
33     private PCEServiceWrapper pceServiceWrapper;
34     private Method method;
35     private static String METHOD_NAME = "mappingCancelResourceReserve";
36     private Class[] parameterTypes;
37     private Object[] parameters;
38
39
40
41     public PCEServiceWrapperTest() {
42         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
43         this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService);
44     }
45
46     @Before
47     public void init() throws NoSuchMethodException {
48         this.pceServiceWrapper = new PCEServiceWrapper(this.pathComputationService);
49         this.parameterTypes = new Class[2];
50         this.parameterTypes[0] = java.lang.String.class;
51         this.parameterTypes[1] = SdncRequestHeader.class;
52         this.method = this.pceServiceWrapper.getClass().getDeclaredMethod(METHOD_NAME, this.parameterTypes);
53         this.method.setAccessible(true);
54         this.parameters = new Object[2];
55     }
56
57     @Test
58     public void performPCENullSdncRequestHeader() {
59         ServiceCreateInput input =  ServiceDataUtils.buildServiceCreateInput();
60         input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build();
61         PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true);
62         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon()
63                 .getAckFinalIndicator());
64     }
65
66     @Test
67     public void mappingCancelResourceReserveNullSdncRequestHeader()
68         throws InvocationTargetException, IllegalAccessException {
69         this.parameters[0] = "service 1";
70         this.parameters[1] = null;
71         CancelResourceReserveInput result = (CancelResourceReserveInput)this.method.invoke(this.pceServiceWrapper,
72                 this.parameters);
73         Assert.assertEquals("service 1", result.getServiceName());
74     }
75
76     @Test
77     public void mappingCancelResourceReserveValidSdncRequestHeader()
78         throws InvocationTargetException, IllegalAccessException {
79         this.parameters[0] = "service 1";
80         this.parameters[1] = new SdncRequestHeaderBuilder().setRequestId("request 1")
81             .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").build();
82         CancelResourceReserveInput result = (CancelResourceReserveInput)this.method.invoke(this.pceServiceWrapper,
83                 this.parameters);
84         Assert.assertEquals("service 1", result.getServiceName());
85         Assert.assertEquals("request 1", result.getServiceHandlerHeader().getRequestId());
86     }
87 }