2 * Copyright © 2018 Orange, 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.transportpce.servicehandler.listeners;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.times;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.verifyNoMoreInteractions;
14 import static org.mockito.Mockito.verifyZeroInteractions;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.transportpce.common.OperationResult;
23 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
24 import org.opendaylight.transportpce.servicehandler.ServiceInput;
25 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
26 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
27 import org.opendaylight.transportpce.servicehandler.utils.InjectField;
28 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
29 import org.opendaylight.transportpce.test.AbstractTest;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResult;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResultBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes;
40 public class PceListenerImplTest extends AbstractTest {
43 private ServiceDataStoreOperations serviceDataStoreOperationsMock;
45 private RendererServiceOperations rendererServiceOperationsMock;
47 private PCEServiceWrapper pceServiceWrapperMock;
49 private ServiceInput serviceInputMock;
51 private PceListenerImpl pceListenerImplMock;
56 MockitoAnnotations.initMocks(this);
60 public void onServicePathRpcResultServiceInputIsNull() {
61 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
62 InjectField.inject(this.pceListenerImplMock, "tempService", false);
63 InjectField.inject(this.pceListenerImplMock, "input", null);
64 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
65 ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true);
66 this.pceListenerImplMock.onServicePathRpcResult(notification);
67 verifyNoMoreInteractions(this.serviceDataStoreOperationsMock);
68 verifyNoMoreInteractions(this.rendererServiceOperationsMock);
72 public void onServicePathRpcResultPathDescriptionIsNull() {
73 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
74 InjectField.inject(this.pceListenerImplMock, "tempService", false);
75 InjectField.inject(this.pceListenerImplMock, "input", null);
76 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
77 ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", false);
78 this.pceListenerImplMock.onServicePathRpcResult(notification);
79 verifyNoMoreInteractions(this.serviceDataStoreOperationsMock);
80 verifyNoMoreInteractions(this.rendererServiceOperationsMock);
84 public void onServicePathRpcResultPCRSuccess() {
85 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
86 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
87 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class)))
88 .thenReturn(OperationResult.ok("Successful"));
89 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
90 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
91 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd());
92 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd());
93 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
94 .thenReturn(serviceCreateInput.getSdncRequestHeader());
95 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
96 InjectField.inject(this.pceListenerImplMock, "tempService", false);
97 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
98 ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true);
99 this.pceListenerImplMock.onServicePathRpcResult(notification);
100 verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class));
101 verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class),
102 any(PathComputationRequestOutput.class));
103 verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class));
107 public void onServicePathRpcResultTempPCRSuccess() {
108 TempServiceCreateInput tempServiceCreateInput = ServiceDataUtils.buildTempServiceCreateInput();
109 Mockito.when(this.serviceInputMock.getTempServiceCreateInput()).thenReturn(tempServiceCreateInput);
110 Mockito.when(this.serviceDataStoreOperationsMock.createTempService(any(TempServiceCreateInput.class)))
111 .thenReturn(OperationResult.ok("Successful"));
112 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
113 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
114 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(tempServiceCreateInput.getServiceAEnd());
115 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(tempServiceCreateInput.getServiceZEnd());
116 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
117 .thenReturn(tempServiceCreateInput.getSdncRequestHeader());
118 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
119 InjectField.inject(this.pceListenerImplMock, "tempService", true);
120 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
121 ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true);
122 this.pceListenerImplMock.onServicePathRpcResult(notification);
123 verify(this.serviceDataStoreOperationsMock).createTempService(any(TempServiceCreateInput.class));
124 verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class),
125 any(PathComputationRequestOutput.class));
126 verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class));
130 public void onServicePathRpcResultPCRSuccessFeasabilityCheck() {
131 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
132 InjectField.inject(this.pceListenerImplMock, "serviceFeasiblity", true);
133 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
134 ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true);
135 this.pceListenerImplMock.onServicePathRpcResult(notification);
136 verifyZeroInteractions(this.serviceDataStoreOperationsMock);
137 verifyZeroInteractions(this.rendererServiceOperationsMock);
141 public void onServicePathRpcResultCRRSuccessWithNoReconfigure() {
142 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
143 ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false);
144 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName());
145 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
146 .thenReturn(OperationResult.ok("Successful"));
147 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
148 .thenReturn(OperationResult.ok("Successful"));
149 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
150 InjectField.inject(this.pceListenerImplMock, "tempService", false);
151 this.pceListenerImplMock.onServicePathRpcResult(notification);
152 verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class));
153 verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class));
157 public void onServicePathRpcResultCRRSuccessWithReconfigure() {
158 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
159 ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false);
160 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName());
161 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
162 .thenReturn(OperationResult.ok("Successful"));
163 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
164 .thenReturn(OperationResult.ok("Successful"));
165 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", true);
166 InjectField.inject(this.pceListenerImplMock, "tempService", false);
167 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
168 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
169 this.pceListenerImplMock.onServicePathRpcResult(notification);
170 verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class));
171 verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class));
172 verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true);
176 public void onServicePathRpcResultCRRTempSuccess() {
177 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
178 ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false);
179 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName());
180 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
181 .thenReturn(OperationResult.ok("Successful"));
182 Mockito.when(this.serviceDataStoreOperationsMock.deleteTempService(any(String.class)))
183 .thenReturn(OperationResult.ok("Successful"));
184 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
185 InjectField.inject(this.pceListenerImplMock, "tempService", true);
186 this.pceListenerImplMock.onServicePathRpcResult(notification);
187 verify(this.serviceDataStoreOperationsMock).deleteTempService(any(String.class));
188 verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class));
192 public void onServicePathRpcResultCRRFailed() {
193 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
194 ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false);
195 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
196 InjectField.inject(this.pceListenerImplMock, "tempService", false);
197 this.pceListenerImplMock.onServicePathRpcResult(notification);
198 verifyZeroInteractions(this.serviceDataStoreOperationsMock);
199 verifyZeroInteractions(this.pceServiceWrapperMock);
203 public void onServicePathRpcResultCRRTempFailed() {
204 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(
205 ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false);
206 InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false);
207 InjectField.inject(this.pceListenerImplMock, "tempService", true);
208 this.pceListenerImplMock.onServicePathRpcResult(notification);
209 verifyZeroInteractions(this.serviceDataStoreOperationsMock);
210 verifyZeroInteractions(this.pceServiceWrapperMock);
214 public void onServicePathRpcResultRepeat() {
215 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
216 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
217 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class)))
218 .thenReturn(OperationResult.ok("Successful"));
219 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
220 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
221 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd());
222 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd());
223 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
224 .thenReturn(serviceCreateInput.getSdncRequestHeader());
225 this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult());
226 verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class));
227 this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult());
228 verifyNoMoreInteractions(this.rendererServiceOperationsMock);
232 public void onServicePathRpcResultFailed() {
233 this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildFailedPceServicePathRpcResult());
234 verifyZeroInteractions(this.rendererServiceOperationsMock);
238 public void onServicePathRpcResultRepeatFailedCompareCase1() {
239 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
240 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
241 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class)))
242 .thenReturn(OperationResult.ok("Successful"));
243 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
244 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
245 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd());
246 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd());
247 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
248 .thenReturn(serviceCreateInput.getSdncRequestHeader());
249 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
250 .thenReturn(OperationResult.ok("Successful"));
251 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
252 .thenReturn(OperationResult.ok("Successful"));
253 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult();
254 this.pceListenerImplMock.onServicePathRpcResult(notification);
255 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName());
256 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
257 .thenReturn(OperationResult.ok("Successful"));
258 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
259 .thenReturn(OperationResult.ok("Successful"));
260 ServicePathRpcResult notification2 = new ServicePathRpcResultBuilder(notification)
261 .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve).build();
262 this.pceListenerImplMock.onServicePathRpcResult(notification2);
263 verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class));
267 public void onServicePathRpcResultRepeatFailedCompareCase2() {
268 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
269 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
270 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class)))
271 .thenReturn(OperationResult.ok("Successful"));
272 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
273 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
274 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd());
275 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd());
276 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
277 .thenReturn(serviceCreateInput.getSdncRequestHeader());
278 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
279 .thenReturn(OperationResult.ok("Successful"));
280 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
281 .thenReturn(OperationResult.ok("Successful"));
282 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult();
283 this.pceListenerImplMock.onServicePathRpcResult(notification);
284 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName());
285 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
286 .thenReturn(OperationResult.ok("Successful"));
287 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
288 .thenReturn(OperationResult.ok("Successful"));
289 ServicePathRpcResult notification2 =
290 new ServicePathRpcResultBuilder(notification).setServiceName("service 2").build();
291 this.pceListenerImplMock.onServicePathRpcResult(notification2);
292 verify(this.rendererServiceOperationsMock, times(2))
293 .serviceImplementation(any(ServiceImplementationRequestInput.class));
297 public void onServicePathRpcResultRepeatFailedCompareCase3() {
298 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
299 Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput);
300 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class)))
301 .thenReturn(OperationResult.ok("Successful"));
302 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
303 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
304 Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd());
305 Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd());
306 Mockito.when(this.serviceInputMock.getSdncRequestHeader())
307 .thenReturn(serviceCreateInput.getSdncRequestHeader());
308 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
309 .thenReturn(OperationResult.ok("Successful"));
310 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
311 .thenReturn(OperationResult.ok("Successful"));
312 ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult();
313 this.pceListenerImplMock.onServicePathRpcResult(notification);
314 Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName());
315 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class)))
316 .thenReturn(OperationResult.ok("Successful"));
317 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class)))
318 .thenReturn(OperationResult.ok("Successful"));
319 ServicePathRpcResult notification2 =
320 new ServicePathRpcResultBuilder(notification).setStatus(RpcStatusEx.Failed).build();
321 this.pceListenerImplMock.onServicePathRpcResult(notification2);
322 verify(this.rendererServiceOperationsMock, times(1))
323 .serviceImplementation(any(ServiceImplementationRequestInput.class));