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