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