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