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