Merge "Add if-cap-support for If-OTU4-ODU4 ports (7.1)"
[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.rev211210.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.rev211210.AddOpenroadmOperationalModesToCatalogInputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddSpecificOperationalModesToCatalogInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddSpecificOperationalModesToCatalogOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureOutput;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteOutput;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteOutput;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.delete.input.ServiceDeleteReqInfoBuilder;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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 tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
536             throws ExecutionException, InterruptedException {
537         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
538         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
539             new ServicehandlerImpl(
540                     pathComputationService, rendererServiceOperations, notificationPublishService,
541                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
542                     serviceDataStoreOperations, catalogDataStoreOperations)
543                 .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput());
544         result.addListener(() -> endSignal.countDown(), executorService);
545         endSignal.await();
546         assertEquals(
547             ResponseCodes.RESPONSE_OK,
548             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
549     }
550
551     @Test
552     public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput()
553             throws ExecutionException, InterruptedException {
554         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result =
555             new ServicehandlerImpl(
556                     pathComputationService, rendererServiceOperations, notificationPublishService,
557                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
558                     serviceDataStoreOperations, catalogDataStoreOperations)
559                 .addOpenroadmOperationalModesToCatalog(new AddOpenroadmOperationalModesToCatalogInputBuilder().build());
560         Assert.assertEquals(
561             ResponseCodes.RESPONSE_FAILED,
562             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
563     }
564
565     @Test
566     public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput()
567             throws ExecutionException, InterruptedException {
568         ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> result =
569             new ServicehandlerImpl(
570                     pathComputationService, rendererServiceOperations, notificationPublishService,
571                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
572                     serviceDataStoreOperations, catalogDataStoreOperations)
573                 .addSpecificOperationalModesToCatalog(new AddSpecificOperationalModesToCatalogInputBuilder().build());
574         Assert.assertEquals(
575             ResponseCodes.RESPONSE_FAILED,
576             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
577     }
578
579     @Test
580     public void addOpenroadmOperationalModesToCatalogShouldBeSuccessfulWhenAddORToCatalog()
581             throws ExecutionException, InterruptedException {
582         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result =
583             new ServicehandlerImpl(
584                     pathComputationService, rendererServiceOperations, notificationPublishService,
585                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
586                     serviceDataStoreOperations, catalogDataStoreOperations)
587                 .addOpenroadmOperationalModesToCatalog(CatalogDataUtils.buildAddORToCatalogInput());
588         Assert.assertEquals(
589             ResponseCodes.RESPONSE_OK,
590             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
591     }
592
593     @Test
594     public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog()
595             throws ExecutionException, InterruptedException {
596         ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> result =
597             new ServicehandlerImpl(
598                     pathComputationService, rendererServiceOperations, notificationPublishService,
599                     pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
600                     serviceDataStoreOperations, catalogDataStoreOperations)
601                 .addSpecificOperationalModesToCatalog(CatalogDataUtils.buildAddSpecificToCatalogInput());
602         Assert.assertEquals(
603             ResponseCodes.RESPONSE_OK,
604             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
605     }
606 }