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