Catalog RPC Implementation
[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.pce.service.PathComputationService;
34 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
35 import org.opendaylight.transportpce.servicehandler.ServiceInput;
36 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
37 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl;
38 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl;
39 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
40 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
41 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
42 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
43 import org.opendaylight.transportpce.servicehandler.utils.CatalogDataUtils;
44 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
45 import org.opendaylight.transportpce.test.AbstractTest;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddSpecificOperationalModesToCatalogInput;
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.TempServiceDeleteInput;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteOutput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.delete.input.ServiceDeleteReqInfoBuilder;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
81 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
82 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
83 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
84 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZBuilder;
85 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey;
86 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.ResourceBuilder;
87 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPointBuilder;
88 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
89 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
90 import org.opendaylight.yangtools.yang.common.RpcResult;
91 import org.opendaylight.yangtools.yang.common.Uint32;
92
93 @ExtendWith(MockitoExtension.class)
94 public class ServicehandlerImplTest extends AbstractTest {
95
96     @Mock
97     private PathComputationService pathComputationService;
98     @Mock
99     private RendererServiceOperations rendererServiceOperations;
100     @Mock
101     private NotificationPublishService notificationPublishService;
102     @Mock
103     private PceListenerImpl pceListenerImpl;
104     @Mock
105     private RendererListenerImpl rendererListenerImpl;
106     @Mock
107     private NetworkModelListenerImpl networkModelListenerImpl;
108
109     private ServiceDataStoreOperations serviceDataStoreOperations;
110     private CatalogDataStoreOperations catalogDataStoreOperations;
111     private ServiceCreateInput serviceCreateInput;
112     private ServiceDeleteInput serviceDeleteInput;
113     private ServiceReconfigureInput serviceReconfigureInput;
114     private ServiceRestorationInput serviceRestorationInput;
115     private ServiceRerouteInput serviceRerouteInput;
116     private ListeningExecutorService executorService;
117     private CountDownLatch endSignal;
118     private static final int NUM_THREADS = 5;
119
120     @BeforeEach
121     void setUp() {
122         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
123         endSignal = new CountDownLatch(1);
124         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
125         this.catalogDataStoreOperations = new CatalogDataStoreOperationsImpl(getNewDataBroker());
126         serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
127         serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
128         serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput();
129         serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput();
130         serviceRerouteInput = ServiceDataUtils.buildServiceRerouteInput();
131     }
132
133     @Test
134     void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
135         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
136                     rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
137                     networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
138         ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl
139             .serviceCreate(new ServiceCreateInputBuilder().build());
140         result.addListener(() -> endSignal.countDown(), executorService);
141         endSignal.await();
142         assertEquals(
143             ResponseCodes.RESPONSE_FAILED,
144             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
145     }
146
147     @Test
148     void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException,
149             InterruptedException {
150         final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
151         when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
152                 .thenReturn(Optional.of(
153                         new ServicesBuilder()
154                                 .setServiceName(serviceCreateInput.getServiceName())
155                                 .build()));
156         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
157                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
158                 networkModelListenerImpl, serviceDSOperations, catalogDataStoreOperations);
159         ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
160         result.addListener(() -> endSignal.countDown(), executorService);
161
162         endSignal.await();
163         assertEquals(
164             ResponseCodes.RESPONSE_FAILED,
165             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
166     }
167
168     @Test
169     void createServiceShouldBeSuccessfulWhenPerformPCESuccessful()
170             throws ExecutionException, InterruptedException {
171         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
172         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
173                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
174                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
175         ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
176         result.addListener(() -> endSignal.countDown(), executorService);
177
178         endSignal.await();
179         assertEquals(
180             ResponseCodes.RESPONSE_OK,
181             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
182     }
183
184     @Test
185     void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
186         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
187                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
188                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
189         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(
190                 new ServiceDeleteInputBuilder()
191                         .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
192                                 .setServiceName("")
193                                 .build())
194                         .build());
195         result.addListener(() -> endSignal.countDown(), executorService);
196
197         endSignal.await();
198         assertEquals(
199             ResponseCodes.RESPONSE_FAILED,
200             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
201     }
202
203     @Test
204     void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
205         ServicehandlerImpl servicehandlerImpl =
206                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
207                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
208                         serviceDataStoreOperations, catalogDataStoreOperations);
209         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
210         result.addListener(() -> endSignal.countDown(), executorService);
211
212         endSignal.await();
213         assertEquals(
214             ResponseCodes.RESPONSE_FAILED,
215             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
216     }
217
218     @Test
219     void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
220         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
221         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
222                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
223                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
224         serviceDataStoreOperations.createService(serviceCreateInput);
225         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
226         result.addListener(() -> endSignal.countDown(), executorService);
227
228         endSignal.await();
229         assertEquals(
230             ResponseCodes.RESPONSE_OK,
231             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
232     }
233
234
235     @Test
236     void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
237         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
238                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
239                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
240         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
241                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
242         result.addListener(() -> endSignal.countDown(), executorService);
243
244         endSignal.await();
245         assertEquals(
246             ResponseCodes.RESPONSE_FAILED,
247             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
248     }
249
250     @Test
251     void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
252             throws ExecutionException, InterruptedException {
253         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
254         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
255                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
256                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
257         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
258                 servicehandlerImpl.serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput());
259         result.addListener(() -> endSignal.countDown(), executorService);
260
261         endSignal.await();
262         assertEquals(
263             ResponseCodes.RESPONSE_OK,
264             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
265     }
266
267     @Test
268     void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
269         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
270                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
271                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
272         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
273                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
274         result.addListener(() -> endSignal.countDown(), executorService);
275
276         endSignal.await();
277     }
278
279
280     @Test
281     void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
282         //action -> service reconfigure
283         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
284                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
285                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
286         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
287                 serviceReconfigureInput);
288
289         result.addListener(() -> endSignal.countDown(), executorService);
290
291         endSignal.await();
292     }
293
294     @Test
295     void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
296         // serviceReconfigure is calling service delete method in renderer
297         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
298         //create service to reconfigure
299         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
300                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
301                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
302         serviceDataStoreOperations.createService(serviceCreateInput);
303
304         //service reconfigure test action
305         //ServiceReconfigureInput is created with the same service information that is created before
306         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
307                 serviceReconfigureInput);
308         result.addListener(() -> endSignal.countDown(), executorService);
309
310         endSignal.await();
311     }
312
313     @Test
314     void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
315         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
316                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
317                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
318         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl
319             .serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
320         result.addListener(() -> endSignal.countDown(), executorService);
321
322         endSignal.await();
323     }
324
325
326     @Test
327     void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
328         //action -> service restore
329         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
330                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
331                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
332         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
333                 serviceRestorationInput);
334
335         result.addListener(() -> endSignal.countDown(), executorService);
336
337         endSignal.await();
338     }
339
340     @Test
341     void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
342         // serviceRestoration is calling service delete method in renderer
343         when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
344         //create service to restore
345         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
346                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
347                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
348         serviceDataStoreOperations.createService(serviceCreateInput);
349
350         //service Restoration test action
351         //ServiceRestorationInput is created with the same service information that is created before
352         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
353                 serviceRestorationInput);
354         result.addListener(() -> endSignal.countDown(), executorService);
355
356         endSignal.await();
357     }
358
359     @Test
360     void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
361         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
362                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
363                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
364         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
365                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
366         result.addListener(() -> endSignal.countDown(), executorService);
367
368         endSignal.await();
369
370         assertEquals(
371             ResponseCodes.RESPONSE_FAILED,
372             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
373     }
374
375     @Test
376     void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
377         //action -> service reconfigure
378         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
379                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
380                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
381         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl
382             .serviceReroute(serviceRerouteInput);
383
384         result.addListener(() -> endSignal.countDown(), executorService);
385
386         endSignal.await();
387
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
451         serviceDataStoreOperations.createService(serviceCreateInput);
452         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =  new ServicehandlerImpl(getNewDataBroker(),
453                 pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl,
454                 rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations)
455                 .serviceReroute(serviceRerouteInput);
456         result.addListener(() -> endSignal.countDown(), executorService);
457
458         endSignal.await();
459
460         assertEquals(
461             ResponseCodes.RESPONSE_OK,
462             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
463     }
464
465     @Test
466     void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
467         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
468                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
469                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
470         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
471                 servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder().setCommonId("").build());
472         result.addListener(() -> endSignal.countDown(), executorService);
473
474         endSignal.await();
475
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         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
488                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
489                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
490         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(
491                 ServiceDataUtils.buildTempServiceDeleteInput());
492         result.addListener(() -> endSignal.countDown(), executorService);
493
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
504         //create temp service to delete in the temp delete action
505         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
506                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
507                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
508         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
509         serviceDataStoreOperations.createTempService(createInput);
510
511         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
512         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
513         result.addListener(() -> endSignal.countDown(), executorService);
514
515         endSignal.await();
516         assertEquals(
517             ResponseCodes.RESPONSE_OK,
518             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
519     }
520
521     @Test
522     void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
523         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
524                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
525                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
526         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
527                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
528         result.addListener(() -> endSignal.countDown(), executorService);
529
530         endSignal.await();
531         assertEquals(
532             ResponseCodes.RESPONSE_FAILED,
533             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
534     }
535
536     @Test
537     void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
538             throws ExecutionException, InterruptedException {
539         when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
540
541         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
542                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
543                 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
544
545         ListenableFuture<RpcResult<TempServiceCreateOutput>> result = servicehandlerImpl.tempServiceCreate(
546                 ServiceDataUtils.buildTempServiceCreateInput());
547         result.addListener(() -> endSignal.countDown(), executorService);
548
549         endSignal.await();
550         assertEquals(
551             ResponseCodes.RESPONSE_OK,
552             result.get().getResult().getConfigurationResponseCommon().getResponseCode());
553     }
554
555     @Test
556     public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput() throws ExecutionException,
557             InterruptedException {
558         ServicehandlerImpl servicehandlerImpl =
559                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
560                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
561                         serviceDataStoreOperations,catalogDataStoreOperations);
562         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result = servicehandlerImpl
563                 .addOpenroadmOperationalModesToCatalog(new AddOpenroadmOperationalModesToCatalogInputBuilder().build());
564         RpcResult<AddOpenroadmOperationalModesToCatalogOutput> rpcResult = result.get();
565         Assert.assertEquals(
566                 ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon()
567                         .getResponseCode());
568     }
569
570     @Test
571     public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput() throws ExecutionException,
572             InterruptedException {
573         ServicehandlerImpl servicehandlerImpl =
574                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
575                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
576                         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 =
591                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
592                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
593                         serviceDataStoreOperations,catalogDataStoreOperations);
594         ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>> result = servicehandlerImpl
595                 .addOpenroadmOperationalModesToCatalog(input);
596         RpcResult<AddOpenroadmOperationalModesToCatalogOutput> rpcResult = result.get();
597         Assert.assertEquals(
598                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
599     }
600
601     @Test
602     public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog() throws
603             ExecutionException, InterruptedException {
604         AddSpecificOperationalModesToCatalogInput input = CatalogDataUtils.buildAddSpecificToCatalogInput();
605
606         ServicehandlerImpl servicehandlerImpl =
607                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
608                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
609                         serviceDataStoreOperations,catalogDataStoreOperations);
610         ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> result = servicehandlerImpl
611                 .addSpecificOperationalModesToCatalog(input);
612         RpcResult<AddSpecificOperationalModesToCatalogOutput> rpcResult = result.get();
613         Assert.assertEquals(
614                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
615     }
616 }