Do not use RpcService in servicehandler module
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerImplTest.java
1 /*
2  * Copyright © 2019 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.impl;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
16 import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
17
18 import com.google.common.util.concurrent.Futures;
19 import com.google.common.util.concurrent.ListenableFuture;
20 import com.google.common.util.concurrent.ListeningExecutorService;
21 import com.google.common.util.concurrent.MoreExecutors;
22 import java.util.Map;
23 import java.util.Optional;
24 import java.util.concurrent.CountDownLatch;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.Executors;
27 import org.junit.Assert;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.jupiter.MockitoExtension;
33 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
34 import org.opendaylight.mdsal.binding.api.RpcProviderService;
35 import org.opendaylight.transportpce.common.ResponseCodes;
36 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
37 import org.opendaylight.transportpce.pce.service.PathComputationService;
38 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
39 import org.opendaylight.transportpce.servicehandler.ServiceInput;
40 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
41 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl;
42 import org.opendaylight.transportpce.servicehandler.listeners.NetworkListener;
43 import org.opendaylight.transportpce.servicehandler.listeners.PceListener;
44 import org.opendaylight.transportpce.servicehandler.listeners.RendererListener;
45 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
46 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
47 import org.opendaylight.transportpce.servicehandler.utils.CatalogDataUtils;
48 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
49 import org.opendaylight.transportpce.test.AbstractTest;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescription;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogInputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInputBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckInputBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckOutput;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInputBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureOutput;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteInput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteInputBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteOutput;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInputBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationOutput;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInputBuilder;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateOutput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInputBuilder;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteOutput;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.delete.input.ServiceDeleteReqInfoBuilder;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesBuilder;
83 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder;
84 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder;
85 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
86 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZBuilder;
87 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey;
88 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.ResourceBuilder;
89 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPointBuilder;
90 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
91 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
92 import org.opendaylight.yangtools.yang.common.RpcResult;
93 import org.opendaylight.yangtools.yang.common.Uint32;
94
95 @ExtendWith(MockitoExtension.class)
96 public class ServicehandlerImplTest extends AbstractTest {
97
98     @Mock
99     private RpcProviderService rpcProviderService;
100     @Mock
101     private PathComputationService pathComputationService;
102     @Mock
103     private RendererServiceOperations rendererServiceOperations;
104     @Mock
105     private NotificationPublishService notificationPublishService;
106     @Mock
107     private PceListener pceListenerImpl;
108     @Mock
109     private RendererListener rendererListenerImpl;
110     @Mock
111     private NetworkListener networkModelListenerImpl;
112
113     @Mock
114     private PathDescription pathDescription;
115     private ServiceDataStoreOperations serviceDataStoreOperations;
116     private CatalogDataStoreOperations catalogDataStoreOperations;
117     private ServiceCreateInput serviceCreateInput;
118     private ServiceDeleteInput serviceDeleteInput;
119     private ServiceReconfigureInput serviceReconfigureInput;
120     private ServiceRestorationInput serviceRestorationInput;
121     private ServiceRerouteInput serviceRerouteInput;
122     private ListeningExecutorService executorService;
123     private CountDownLatch endSignal;
124     private static final int NUM_THREADS = 5;
125
126     @BeforeEach
127     void setUp() {
128         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
129         endSignal = new CountDownLatch(1);
130         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
131         this.catalogDataStoreOperations =
132             new CatalogDataStoreOperationsImpl(new NetworkTransactionImpl(getDataBroker()));
133         serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
134         serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
135         serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput();
136         serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput();
137         serviceRerouteInput = ServiceDataUtils.buildServiceRerouteInput();
138         pathDescription = ServiceDataUtils.createPathDescription(0,1,0,1);
139     }
140
141     @Test
142     void testRpcRegistration() {
143         new ServicehandlerImpl(rpcProviderService,
144             pathComputationService, rendererServiceOperations, notificationPublishService,
145             pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
146             serviceDataStoreOperations, catalogDataStoreOperations);
147         verify(rpcProviderService, times(1)).registerRpcImplementations(any());
148     }
149
150     @Test
151     void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
152         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
153             new ServicehandlerImpl(rpcProviderService,
154                     pathComputationService, rendererServiceOperations, notificationPublishService,
155                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
156                     serviceDataStoreOperations, catalogDataStoreOperations)
157                 .serviceCreate(new ServiceCreateInputBuilder().build());
158         result.addListener(() -> endSignal.countDown(), executorService);
159         endSignal.await();
160         assertEquals(
161             ResponseCodes.RESPONSE_FAILED,
162             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
163     }
164
165     @Test
166     void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException {
167         final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
168         when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
169                 .thenReturn(Optional.of(
170                         new ServicesBuilder()
171                                 .setServiceName(serviceCreateInput.getServiceName())
172                                 .build()));
173         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
174             new ServicehandlerImpl(rpcProviderService,
175                     pathComputationService, rendererServiceOperations, notificationPublishService,
176                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
177                     serviceDSOperations, catalogDataStoreOperations)
178                 .serviceCreate(serviceCreateInput);
179         result.addListener(() -> endSignal.countDown(), executorService);
180         endSignal.await();
181         assertEquals(
182             ResponseCodes.RESPONSE_FAILED,
183             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
184     }
185
186     @Test
187     void createServiceShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException {
188         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
189         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
190             new ServicehandlerImpl(rpcProviderService,
191                     pathComputationService, rendererServiceOperations, notificationPublishService,
192                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
193                     serviceDataStoreOperations, catalogDataStoreOperations)
194                 .serviceCreate(serviceCreateInput);
195         result.addListener(() -> endSignal.countDown(), executorService);
196         endSignal.await();
197         assertEquals(
198             ResponseCodes.RESPONSE_OK,
199             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
200     }
201
202     @Test
203     void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
204         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
205             new ServicehandlerImpl(rpcProviderService,
206                     pathComputationService, rendererServiceOperations, notificationPublishService,
207                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
208                     serviceDataStoreOperations, catalogDataStoreOperations)
209                 .serviceDelete(
210                     new ServiceDeleteInputBuilder()
211                         .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
212                                 .setServiceName("")
213                                 .build())
214                         .build());
215         result.addListener(() -> endSignal.countDown(), executorService);
216         endSignal.await();
217         assertEquals(
218             ResponseCodes.RESPONSE_FAILED,
219             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
220     }
221
222     @Test
223     void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
224         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
225             new ServicehandlerImpl(rpcProviderService,
226                     pathComputationService, rendererServiceOperations, notificationPublishService,
227                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
228                     serviceDataStoreOperations, catalogDataStoreOperations)
229                 .serviceDelete(serviceDeleteInput);
230         result.addListener(() -> endSignal.countDown(), executorService);
231         endSignal.await();
232         assertEquals(
233             ResponseCodes.RESPONSE_FAILED,
234             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
235     }
236
237     @Test
238     void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
239         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
240         serviceDataStoreOperations.createService(serviceCreateInput);
241         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
242             new ServicehandlerImpl(rpcProviderService,
243                     pathComputationService, rendererServiceOperations, notificationPublishService,
244                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
245                     serviceDataStoreOperations, catalogDataStoreOperations)
246                 .serviceDelete(serviceDeleteInput);
247         result.addListener(() -> endSignal.countDown(), executorService);
248         endSignal.await();
249         assertEquals(
250             ResponseCodes.RESPONSE_OK,
251             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
252     }
253
254     @Test
255     void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
256         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(rpcProviderService, pathComputationService,
257                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
258                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
259         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
260                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
261         result.addListener(() -> endSignal.countDown(), executorService);
262         endSignal.await();
263         assertEquals(
264             ResponseCodes.RESPONSE_FAILED,
265             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
266     }
267
268     @Test
269     void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
270             throws ExecutionException, InterruptedException {
271         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
272         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
273             new ServicehandlerImpl(rpcProviderService,
274                     pathComputationService, rendererServiceOperations, notificationPublishService,
275                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
276                     serviceDataStoreOperations, catalogDataStoreOperations)
277                 .serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput());
278         result.addListener(() -> endSignal.countDown(), executorService);
279         endSignal.await();
280         assertEquals(
281             ResponseCodes.RESPONSE_OK,
282             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
283     }
284
285     @Test
286     void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
287         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
288             new ServicehandlerImpl(rpcProviderService,
289                     pathComputationService, rendererServiceOperations, notificationPublishService,
290                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
291                     serviceDataStoreOperations, catalogDataStoreOperations)
292                 .serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
293         result.addListener(() -> endSignal.countDown(), executorService);
294         endSignal.await();
295     }
296
297
298     @Test
299     void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
300         //action -> service reconfigure
301         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
302             new ServicehandlerImpl(rpcProviderService,
303                     pathComputationService, rendererServiceOperations, notificationPublishService,
304                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
305                     serviceDataStoreOperations, catalogDataStoreOperations)
306                 .serviceReconfigure(serviceReconfigureInput);
307         result.addListener(() -> endSignal.countDown(), executorService);
308         endSignal.await();
309     }
310
311     @Test
312     void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
313         // serviceReconfigure is calling service delete method in renderer
314         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
315         //create service to reconfigure
316         serviceDataStoreOperations.createService(serviceCreateInput);
317         //service reconfigure test action
318         //ServiceReconfigureInput is created with the same service information that is created before
319         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
320             new ServicehandlerImpl(rpcProviderService,
321                     pathComputationService, rendererServiceOperations, notificationPublishService,
322                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
323                     serviceDataStoreOperations, catalogDataStoreOperations)
324                 .serviceReconfigure(serviceReconfigureInput);
325         result.addListener(() -> endSignal.countDown(), executorService);
326         endSignal.await();
327     }
328
329     @Test
330     void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
331         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
332             new ServicehandlerImpl(rpcProviderService,
333                     pathComputationService, rendererServiceOperations, notificationPublishService,
334                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
335                     serviceDataStoreOperations, catalogDataStoreOperations)
336                 .serviceRestoration(new ServiceRestorationInputBuilder()
337                 .setServiceName("")
338                 .build());
339         result.addListener(() -> endSignal.countDown(), executorService);
340         endSignal.await();
341     }
342
343     @Test
344     void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
345         //action -> service restore
346         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
347             new ServicehandlerImpl(rpcProviderService,
348                     pathComputationService, rendererServiceOperations, notificationPublishService,
349                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
350                     serviceDataStoreOperations, catalogDataStoreOperations)
351                 .serviceRestoration(serviceRestorationInput);
352         result.addListener(() -> endSignal.countDown(), executorService);
353         endSignal.await();
354     }
355
356     @Test
357     void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
358         // serviceRestoration is calling service delete method in renderer
359         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
360         //create service to restore
361         serviceDataStoreOperations.createService(serviceCreateInput);
362         //service Restoration test action
363         //ServiceRestorationInput is created with the same service information that is created before
364         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
365             new ServicehandlerImpl(rpcProviderService,
366                     pathComputationService, rendererServiceOperations, notificationPublishService,
367                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
368                     serviceDataStoreOperations, catalogDataStoreOperations)
369                 .serviceRestoration(serviceRestorationInput);
370         result.addListener(() -> endSignal.countDown(), executorService);
371         endSignal.await();
372     }
373
374     @Test
375     void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
376         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
377             new ServicehandlerImpl(rpcProviderService,
378                     pathComputationService, rendererServiceOperations, notificationPublishService,
379                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
380                     serviceDataStoreOperations, catalogDataStoreOperations)
381                 .serviceReroute(new ServiceRerouteInputBuilder()
382                 .setServiceName("")
383                 .build());
384         result.addListener(() -> endSignal.countDown(), executorService);
385         endSignal.await();
386         assertEquals(
387             ResponseCodes.RESPONSE_FAILED,
388             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
389     }
390
391     @Test
392     void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
393         //action -> service reconfigure
394         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
395             new ServicehandlerImpl(rpcProviderService,
396                     pathComputationService, rendererServiceOperations, notificationPublishService,
397                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
398                     serviceDataStoreOperations, catalogDataStoreOperations)
399                 .serviceReroute(serviceRerouteInput);
400         result.addListener(() -> endSignal.countDown(), executorService);
401         endSignal.await();
402         assertEquals(
403             ResponseCodes.RESPONSE_FAILED,
404             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
405     }
406
407     @Test
408     void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
409         when(pathComputationService.pathComputationRerouteRequest(any()))
410             .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder()
411                     .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder()
412                             .setResponseCode(ResponseCodes.RESPONSE_OK)
413                             .build())
414                     .build()));
415         Map<AToZKey, AToZ> atoz = Map.of(
416                 new AToZKey("0"),
417                 new AToZBuilder()
418                         .setId("0")
419                         .setResource(new ResourceBuilder()
420                                 .setResource(new TerminationPointBuilder()
421                                         .setTpNodeId("tpNodeIdC")
422                                         .setTpId("TpIdC1")
423                                         .build())
424                                 .setState(State.InService)
425                                 .build())
426                         .build(),
427                 new AToZKey("1"),
428                 new AToZBuilder()
429                         .setId("1")
430                         .setResource(new ResourceBuilder()
431                                 .setResource(new TerminationPointBuilder()
432                                         .setTpNodeId("tpNodeIdD")
433                                         .setTpId("TpIdCD")
434                                         .build())
435                                 .setState(State.InService)
436                                 .build())
437                         .build(), new AToZKey("2"),
438                 new AToZBuilder()
439                         .setId("2")
440                         .setResource(new ResourceBuilder()
441                                 .setResource(new TerminationPointBuilder()
442                                         .setTpNodeId("tpNodeIdA")
443                                         .setTpId("TpIdA1")
444                                         .build())
445                                 .setState(State.InService)
446                                 .build())
447                         .build()
448
449         );
450         serviceDataStoreOperations.createServicePath(new ServiceInput(serviceCreateInput),
451                 new PathComputationRequestOutputBuilder()
452                         .setResponseParameters(new ResponseParametersBuilder()
453                                 .setPathDescription(new PathDescriptionBuilder()
454                                         .setAToZDirection(new AToZDirectionBuilder()
455                                                 .setAToZ(atoz)
456                                                 .setRate(Uint32.valueOf(1))
457                                                 .build())
458                                         .setZToADirection(new ZToADirectionBuilder()
459                                                 .setRate(Uint32.valueOf(1))
460                                                 .build())
461                                         .build())
462                                 .build())
463                         .build());
464         serviceDataStoreOperations.createService(serviceCreateInput);
465         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
466             new ServicehandlerImpl(rpcProviderService,
467                     pathComputationService, rendererServiceOperations, notificationPublishService,
468                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
469                     serviceDataStoreOperations, catalogDataStoreOperations)
470                 .serviceReroute(serviceRerouteInput);
471         result.addListener(() -> endSignal.countDown(), executorService);
472         endSignal.await();
473         assertEquals(
474             ResponseCodes.RESPONSE_OK,
475             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
476     }
477
478     @Test
479     void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
480         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
481             new ServicehandlerImpl(rpcProviderService,
482                     pathComputationService, rendererServiceOperations, notificationPublishService,
483                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
484                     serviceDataStoreOperations, catalogDataStoreOperations)
485                 .tempServiceDelete(new TempServiceDeleteInputBuilder()
486                 .setCommonId("")
487                 .build());
488         result.addListener(() -> endSignal.countDown(), executorService);
489         endSignal.await();
490         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
491         assertEquals(
492             ResponseCodes.RESPONSE_FAILED,
493             rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
494         assertEquals(
495             LogMessages.SERVICE_NON_COMPLIANT,
496             rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
497     }
498
499     @Test
500     void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
501         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
502             new ServicehandlerImpl(rpcProviderService,
503                     pathComputationService, rendererServiceOperations, notificationPublishService,
504                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
505                     serviceDataStoreOperations, catalogDataStoreOperations)
506                 .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput());
507         result.addListener(() -> endSignal.countDown(), executorService);
508         endSignal.await();
509         assertEquals(
510             ResponseCodes.RESPONSE_FAILED,
511             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
512     }
513
514     @Test
515     void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
516         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
517         //create temp service to delete in the temp delete action
518         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
519         serviceDataStoreOperations.createTempService(createInput, pathDescription);
520         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
521                 new ServicehandlerImpl(rpcProviderService,
522                         pathComputationService, rendererServiceOperations, notificationPublishService,
523                         pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
524                         serviceDataStoreOperations, catalogDataStoreOperations)
525                     .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId()));
526         result.addListener(() -> endSignal.countDown(), executorService);
527         endSignal.await();
528         assertEquals(
529             ResponseCodes.RESPONSE_OK,
530             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
531     }
532
533     @Test
534     void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
535         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
536             new ServicehandlerImpl(rpcProviderService,
537                     pathComputationService, rendererServiceOperations, notificationPublishService,
538                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
539                     serviceDataStoreOperations, catalogDataStoreOperations)
540                 .tempServiceCreate(new TempServiceCreateInputBuilder().build());
541         result.addListener(() -> endSignal.countDown(), executorService);
542         endSignal.await();
543         assertEquals(
544             ResponseCodes.RESPONSE_FAILED,
545             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
546     }
547
548     @Test
549     void tempServiceCreateShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException {
550         final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
551         when(serviceDSOperations.getTempService(any()))
552             .thenReturn(Optional.of(
553                     new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list
554                             .ServicesBuilder()
555                         .setCommonId("bad_commonId")
556                         .build()));
557         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
558             new ServicehandlerImpl(rpcProviderService,
559                     pathComputationService, rendererServiceOperations, notificationPublishService,
560                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
561                     serviceDSOperations, catalogDataStoreOperations)
562                 .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput());
563         result.addListener(() -> endSignal.countDown(), executorService);
564         endSignal.await();
565         assertEquals(
566             ResponseCodes.RESPONSE_FAILED,
567             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
568         assertEquals(
569             "Service 'Temp (commonId)' already exists in datastore",
570             result.get().getResult().getConfigurationResponseCommon().getResponseMessage());
571     }
572
573     @Test
574     void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
575             throws ExecutionException, InterruptedException {
576         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
577         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
578             new ServicehandlerImpl(rpcProviderService,
579                     pathComputationService, rendererServiceOperations, notificationPublishService,
580                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
581                     serviceDataStoreOperations, catalogDataStoreOperations)
582                 .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput());
583         result.addListener(() -> endSignal.countDown(), executorService);
584         endSignal.await();
585         assertEquals(
586             ResponseCodes.RESPONSE_OK,
587             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
588     }
589
590     @Test
591     public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput()
592             throws ExecutionException, InterruptedException {
593         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result =
594             new ServicehandlerImpl(rpcProviderService,
595                     pathComputationService, rendererServiceOperations, notificationPublishService,
596                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
597                     serviceDataStoreOperations, catalogDataStoreOperations)
598                 .addOpenroadmOperationalModesToCatalog(new AddOpenroadmOperationalModesToCatalogInputBuilder().build());
599         Assert.assertEquals(
600             ResponseCodes.RESPONSE_FAILED,
601             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
602     }
603
604     @Test
605     public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput()
606             throws ExecutionException, InterruptedException {
607         ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> result =
608             new ServicehandlerImpl(rpcProviderService,
609                     pathComputationService, rendererServiceOperations, notificationPublishService,
610                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
611                     serviceDataStoreOperations, catalogDataStoreOperations)
612                 .addSpecificOperationalModesToCatalog(new AddSpecificOperationalModesToCatalogInputBuilder().build());
613         Assert.assertEquals(
614             ResponseCodes.RESPONSE_FAILED,
615             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
616     }
617
618     @Test
619     public void addOpenroadmOperationalModesToCatalogShouldBeSuccessfulWhenAddORToCatalog()
620             throws ExecutionException, InterruptedException {
621         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result =
622             new ServicehandlerImpl(rpcProviderService,
623                     pathComputationService, rendererServiceOperations, notificationPublishService,
624                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
625                     serviceDataStoreOperations, catalogDataStoreOperations)
626                 .addOpenroadmOperationalModesToCatalog(CatalogDataUtils.buildAddORToCatalogInput());
627         Assert.assertEquals(
628             ResponseCodes.RESPONSE_OK,
629             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
630     }
631
632     @Test
633     public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog()
634             throws ExecutionException, InterruptedException {
635         ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> result =
636             new ServicehandlerImpl(rpcProviderService,
637                     pathComputationService, rendererServiceOperations, notificationPublishService,
638                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
639                     serviceDataStoreOperations, catalogDataStoreOperations)
640                 .addSpecificOperationalModesToCatalog(CatalogDataUtils.buildAddSpecificToCatalogInput());
641         Assert.assertEquals(
642             ResponseCodes.RESPONSE_OK,
643             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
644     }
645 }