Technical debt - fix SH deprecated warnings
[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 static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.InjectMocks;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
22 import org.opendaylight.transportpce.common.ResponseCodes;
23 import org.opendaylight.transportpce.pce.service.PathComputationService;
24 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
25 import org.opendaylight.transportpce.test.AbstractTest;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
39
40 public class PCEServiceWrapperTest extends AbstractTest {
41
42     @Mock
43     private PathComputationService pathComputationServiceMock;
44     @Mock
45     private NotificationPublishService notificationPublishServiceMock;
46     @InjectMocks
47     private PCEServiceWrapper pceServiceWrapperMock;
48
49     @Before
50     public void init() throws NoSuchMethodException {
51         MockitoAnnotations.initMocks(this);
52     }
53
54     @Test
55     public void performPCENullSdncRequestHeader() {
56         ServiceCreateInput input =  ServiceDataUtils.buildServiceCreateInput();
57         input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build();
58         PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
59         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
60                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
61         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
62                 pceResponse.getConfigurationResponseCommon().getResponseCode());
63         Mockito.verifyNoInteractions(this.pathComputationServiceMock);
64     }
65
66     @Test
67     public void performPCENullServiceName() {
68         ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
69         input = new ServiceCreateInputBuilder(input).setServiceName(null).build();
70         PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
71         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
72                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
73         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
74                 pceResponse.getConfigurationResponseCommon().getResponseCode());
75         Mockito.verifyNoInteractions(this.pathComputationServiceMock);
76     }
77
78     @Test
79     public void performPCENullCommonId() {
80         TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
81         input = new TempServiceCreateInputBuilder(input).setCommonId(null).build();
82         PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
83         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
84                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
85         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
86                 pceResponse.getConfigurationResponseCommon().getResponseCode());
87         Mockito.verifyNoInteractions(this.pathComputationServiceMock);
88     }
89
90
91     @Test
92     public void cancelPCEResourceNullServiceName() {
93         CancelResourceReserveOutput pceResponse =
94                 this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult);
95         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
96                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
97         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
98                 pceResponse.getConfigurationResponseCommon().getResponseCode());
99         Mockito.verifyNoInteractions(this.pathComputationServiceMock);
100     }
101
102     @Test
103     public void cancelPCEResourceValid() {
104         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
105                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
106                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
107         CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder()
108                 .setConfigurationResponseCommon(configurationResponseCommon).build();
109         ListenableFuture<CancelResourceReserveOutput> response = ServiceDataUtils.returnFuture(output);
110         Mockito.when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class)))
111                 .thenReturn(response);
112         CancelResourceReserveOutput pceResponse =
113                 this.pceServiceWrapperMock.cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult);
114         Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
115                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
116         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
117                 pceResponse.getConfigurationResponseCommon().getResponseCode());
118         Assert.assertEquals("PCE calculation in progress",
119                 pceResponse.getConfigurationResponseCommon().getResponseMessage());
120         verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class));
121     }
122
123     @Test
124     public void performPCEValid() {
125         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
126                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
127                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
128         PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
129                 .setConfigurationResponseCommon(configurationResponseCommon).build();
130         ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
131         Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
132                 .thenReturn(response);
133         ServiceCreateInput input =  ServiceDataUtils.buildServiceCreateInput();
134         PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
135         Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
136                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
137         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
138                 pceResponse.getConfigurationResponseCommon().getResponseCode());
139         Assert.assertEquals("PCE calculation in progress",
140                 pceResponse.getConfigurationResponseCommon().getResponseMessage());
141         verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
142     }
143
144     @Test
145     public void performPCETempValid() {
146         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
147                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
148                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
149         PathComputationRequestOutput output = new PathComputationRequestOutputBuilder()
150                 .setConfigurationResponseCommon(configurationResponseCommon).build();
151         ListenableFuture<PathComputationRequestOutput> response = ServiceDataUtils.returnFuture(output);
152         Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class)))
153                 .thenReturn(response);
154         TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
155         PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true);
156         Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
157                 pceResponse.getConfigurationResponseCommon().getAckFinalIndicator());
158         Assert.assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode());
159         Assert.assertEquals("PCE calculation in progress",
160                 pceResponse.getConfigurationResponseCommon().getResponseMessage());
161         verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class)));
162     }
163 }