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