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