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