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