Merge changes I66f5e0aa,I2aa60123
[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.mockito.ArgumentMatchers.any;
11
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.ListeningExecutorService;
15 import com.google.common.util.concurrent.MoreExecutors;
16
17 import java.util.concurrent.CountDownLatch;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Executors;
20
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.mockito.MockitoAnnotations;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
29 import org.opendaylight.transportpce.common.ResponseCodes;
30 import org.opendaylight.transportpce.pce.service.PathComputationService;
31 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
32 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
33 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
34 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
35 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
36 import org.opendaylight.transportpce.test.AbstractTest;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
63 import org.opendaylight.yangtools.yang.common.RpcResult;
64
65 public class ServicehandlerImplTest extends AbstractTest  {
66
67     @Mock
68     private PathComputationService pathComputationService;
69
70     @Mock
71     private RendererServiceOperations rendererServiceOperations;
72
73     @Mock
74     private NotificationPublishService notificationPublishService;
75
76     @Mock
77     private PceListenerImpl pceListenerImpl;
78
79     @Mock
80     private RendererListenerImpl rendererListenerImpl;
81
82     private ListeningExecutorService executorService;
83     private CountDownLatch endSignal;
84     private static final int NUM_THREADS = 5;
85     private boolean callbackRan;
86
87     @Before
88     public void setUp() {
89         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
90         endSignal = new CountDownLatch(1);
91         callbackRan = false;
92         MockitoAnnotations.initMocks(this);
93     }
94
95     @Test
96     public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
97         ServicehandlerImpl servicehandlerImpl =
98             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
99                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
100         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
101             servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
102         result.addListener(new Runnable() {
103             @Override
104             public void run() {
105                 callbackRan = true;
106                 endSignal.countDown();
107             }
108         }, executorService);
109
110         endSignal.await();
111
112         RpcResult<ServiceCreateOutput> rpcResult = result.get();
113         Assert.assertEquals(
114             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
115     }
116
117     @Test
118     public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful()
119         throws ExecutionException, InterruptedException {
120         ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
121         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
122         ServicehandlerImpl servicehandlerImpl =
123             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
124                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
125         ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(input);
126         result.addListener(new Runnable() {
127             @Override
128             public void run() {
129                 callbackRan = true;
130                 endSignal.countDown();
131             }
132         }, executorService);
133
134         endSignal.await();
135
136         RpcResult<ServiceCreateOutput> rpcResult = result.get();
137         Assert.assertEquals(
138             ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
139     }
140
141     @Test
142     public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
143         ServicehandlerImpl servicehandlerImpl =
144             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
145                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
146         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
147              servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
148                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build());
149         result.addListener(new Runnable() {
150             @Override
151             public void run() {
152                 callbackRan = true;
153                 endSignal.countDown();
154             }
155         }, executorService);
156
157         endSignal.await();
158
159         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
160         Assert.assertEquals(
161             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
162     }
163
164     @Test
165     public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
166         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
167         ServicehandlerImpl servicehandlerImpl =
168             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
169                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
170         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
171         result.addListener(new Runnable() {
172             @Override
173             public void run() {
174                 callbackRan = true;
175                 endSignal.countDown();
176             }
177         }, executorService);
178
179         endSignal.await();
180
181         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
182         Assert.assertEquals(
183             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
184     }
185
186     @Test
187     public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
188         DataBroker dataBroker = getNewDataBroker();
189         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
190         ServicehandlerImpl servicehandlerImpl =
191             new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
192                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
193         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
194         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
195         serviceDataStoreOperations.createService(createInput);
196         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
197         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
198         result.addListener(new Runnable() {
199             @Override
200             public void run() {
201                 callbackRan = true;
202                 endSignal.countDown();
203             }
204         }, executorService);
205
206         endSignal.await();
207
208         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
209         Assert.assertEquals(
210             ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
211     }
212
213
214     @Test
215     public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
216         ServicehandlerImpl servicehandlerImpl =
217                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
218                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
219         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
220                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
221         result.addListener(new Runnable() {
222             @Override
223             public void run() {
224                 callbackRan = true;
225                 endSignal.countDown();
226             }
227         }, executorService);
228
229         endSignal.await();
230
231         RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
232         Assert.assertEquals(
233             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
234     }
235
236     @Test
237     public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful()
238             throws ExecutionException, InterruptedException {
239         ServiceFeasibilityCheckInput input = ServiceDataUtils.buildServiceFeasibilityCheckInput();
240         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
241         ServicehandlerImpl servicehandlerImpl =
242                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
243                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
244         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
245             servicehandlerImpl.serviceFeasibilityCheck(input);
246         result.addListener(new Runnable() {
247             @Override
248             public void run() {
249                 callbackRan = true;
250                 endSignal.countDown();
251             }
252         }, executorService);
253
254         endSignal.await();
255
256         RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
257         Assert.assertEquals(
258                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
259     }
260
261     @Test
262     public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
263         ServicehandlerImpl servicehandlerImpl =
264                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
265                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
266         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
267                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
268         result.addListener(new Runnable() {
269             @Override
270             public void run() {
271                 callbackRan = true;
272                 endSignal.countDown();
273             }
274         }, executorService);
275
276         endSignal.await();
277
278         RpcResult<ServiceReconfigureOutput> rpcResult = result.get();
279         Assert.assertEquals(
280                 RpcStatus.Failed, rpcResult.getResult().getStatus());
281     }
282
283
284     @Test
285     public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
286         ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
287
288         //action -> service reconfigure
289         ServicehandlerImpl servicehandlerImpl =
290                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
291                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
292         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
293
294         result.addListener(new Runnable() {
295             @Override
296             public void run() {
297                 callbackRan = true;
298                 endSignal.countDown();
299             }
300         }, executorService);
301
302         endSignal.await();
303
304         RpcResult<ServiceReconfigureOutput> rpcResult = result.get();
305         //ServiceReconfigureOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly
306         Assert.assertEquals(
307                 RpcStatus.Failed, rpcResult.getResult().getStatus());
308     }
309
310     @Test
311     public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
312         DataBroker dataBroker = getNewDataBroker();
313
314         //mocking
315         // serviceReconfigure is calling service delete method in renderer
316         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
317         //create service to reconfigure
318         ServicehandlerImpl servicehandlerImpl =
319                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
320                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
321         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
322         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
323         serviceDataStoreOperations.createService(createInput);
324
325         //service reconfigure test action
326         ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
327         //ServiceReconfigureInput is created with the same service information that is created before
328         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
329         result.addListener(new Runnable() {
330             @Override
331             public void run() {
332                 callbackRan = true;
333                 endSignal.countDown();
334             }
335         }, executorService);
336
337         endSignal.await();
338
339         RpcResult<ServiceReconfigureOutput> rpcResult = result.get();
340         Assert.assertEquals(
341                 RpcStatus.Successful, rpcResult.getResult().getStatus());
342     }
343
344     @Test
345     public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
346         ServicehandlerImpl servicehandlerImpl =
347                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
348                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
349         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
350                 servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
351         result.addListener(new Runnable() {
352             @Override
353             public void run() {
354                 callbackRan = true;
355                 endSignal.countDown();
356             }
357         }, executorService);
358
359         endSignal.await();
360
361         RpcResult<ServiceRestorationOutput> rpcResult = result.get();
362         Assert.assertEquals(
363                 RpcStatus.Failed, rpcResult.getResult().getStatus());
364     }
365
366
367     @Test
368     public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
369         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
370
371         //action -> service restore
372         ServicehandlerImpl servicehandlerImpl =
373                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
374                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
375         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
376
377         result.addListener(new Runnable() {
378             @Override
379             public void run() {
380                 callbackRan = true;
381                 endSignal.countDown();
382             }
383         }, executorService);
384
385         endSignal.await();
386
387         RpcResult<ServiceRestorationOutput> rpcResult = result.get();
388         //ServiceRestorationOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly
389         Assert.assertEquals(
390                 RpcStatus.Failed, rpcResult.getResult().getStatus());
391     }
392
393     @Test
394     public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
395         DataBroker dataBroker = getNewDataBroker();
396
397         //mocking
398         // serviceRestoration is calling service delete method in renderer
399         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
400         //create service to restore
401         ServicehandlerImpl servicehandlerImpl =
402                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
403                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
404         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
405         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
406         serviceDataStoreOperations.createService(createInput);
407
408         //service Restoration test action
409         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
410         //ServiceRestorationInput is created with the same service information that is created before
411         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
412         result.addListener(new Runnable() {
413             @Override
414             public void run() {
415                 callbackRan = true;
416                 endSignal.countDown();
417             }
418         }, executorService);
419
420         endSignal.await();
421
422         RpcResult<ServiceRestorationOutput> rpcResult = result.get();
423         Assert.assertEquals(
424                 RpcStatus.Successful, rpcResult.getResult().getStatus());
425     }
426
427     @Test
428     public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
429         ServicehandlerImpl servicehandlerImpl =
430                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
431                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
432         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
433                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
434         result.addListener(new Runnable() {
435             @Override
436             public void run() {
437                 callbackRan = true;
438                 endSignal.countDown();
439             }
440         }, executorService);
441
442         endSignal.await();
443
444         RpcResult<ServiceRerouteOutput> rpcResult = result.get();
445         Assert.assertEquals(
446                 RpcStatus.Failed, rpcResult.getResult().getStatus());
447     }
448
449     @Test
450     public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
451         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
452
453         //action -> service reconfigure
454         ServicehandlerImpl servicehandlerImpl =
455                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
456                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
457         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
458
459         result.addListener(new Runnable() {
460             @Override
461             public void run() {
462                 callbackRan = true;
463                 endSignal.countDown();
464             }
465         }, executorService);
466
467         endSignal.await();
468
469         RpcResult<ServiceRerouteOutput> rpcResult = result.get();
470         //ServiceRerouteOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly
471         Assert.assertEquals(
472                 RpcStatus.Failed, rpcResult.getResult().getStatus());
473     }
474
475     @Test
476     public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
477         DataBroker dataBroker = getNewDataBroker();
478
479         //mocking
480         // serviceReroute is calling service delete method in renderer
481         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
482         //create service to be rerouted later
483         ServicehandlerImpl servicehandlerImpl =
484                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
485                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
486         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
487         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
488         serviceDataStoreOperations.createService(createInput);
489
490         //service reroute test action
491         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
492         //ServiceRerouteInput is created with the same service information that is created before
493         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
494         result.addListener(new Runnable() {
495             @Override
496             public void run() {
497                 callbackRan = true;
498                 endSignal.countDown();
499             }
500         }, executorService);
501
502         endSignal.await();
503
504         RpcResult<ServiceRerouteOutput> rpcResult = result.get();
505         Assert.assertEquals(
506                 RpcStatus.Successful, rpcResult.getResult().getStatus());
507     }
508
509     @Test
510     public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
511         ServicehandlerImpl servicehandlerImpl =
512                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
513                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
514         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
515                 servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder()
516                         .setCommonId("").build());
517         result.addListener(new Runnable() {
518             @Override
519             public void run() {
520                 callbackRan = true;
521                 endSignal.countDown();
522             }
523         }, executorService);
524
525         endSignal.await();
526
527         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
528         Assert.assertEquals(
529             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
530         Assert.assertEquals(
531             "Service not compliant !", rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
532     }
533
534     @Test
535     public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
536         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
537         ServicehandlerImpl servicehandlerImpl =
538                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
539                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
540         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
541         result.addListener(new Runnable() {
542             @Override
543             public void run() {
544                 callbackRan = true;
545                 endSignal.countDown();
546             }
547         }, executorService);
548
549         endSignal.await();
550
551         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
552         Assert.assertEquals(
553             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
554     }
555
556     @Test
557     public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
558         DataBroker dataBroker = getNewDataBroker();
559         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
560
561         //create temp service to delete in the temp delete action
562         ServicehandlerImpl servicehandlerImpl =
563                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
564                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
565         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
566         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
567         serviceDataStoreOperations.createTempService(createInput);
568
569
570         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
571         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
572         result.addListener(new Runnable() {
573             @Override
574             public void run() {
575                 callbackRan = true;
576                 endSignal.countDown();
577             }
578         }, executorService);
579
580         endSignal.await();
581
582         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
583         Assert.assertEquals(
584                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
585     }
586
587     @Test
588     public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
589         ServicehandlerImpl servicehandlerImpl =
590                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
591                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
592         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
593                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
594         result.addListener(new Runnable() {
595             @Override
596             public void run() {
597                 callbackRan = true;
598                 endSignal.countDown();
599             }
600         }, executorService);
601
602         endSignal.await();
603
604         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
605         Assert.assertEquals(
606             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
607     }
608
609
610     @Test
611     public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful()
612             throws ExecutionException, InterruptedException {
613         TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
614         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
615
616         ServicehandlerImpl servicehandlerImpl =
617                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
618                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
619
620         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =  servicehandlerImpl.tempServiceCreate(input);
621         result.addListener(new Runnable() {
622             @Override
623             public void run() {
624                 callbackRan = true;
625                 endSignal.countDown();
626             }
627         }, executorService);
628
629         endSignal.await();
630
631         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
632
633         Assert.assertEquals(
634                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
635     }
636
637 }