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