Merge changes Icd0ec3e4,Ied393b60,I117bfce8,Ia8e86650,Id583e292
[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.ServiceDataStoreOperations;
35 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
36 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
37 import org.opendaylight.transportpce.test.AbstractTest;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureOutput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInputBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteOutput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfoBuilder;
64 import org.opendaylight.yangtools.yang.common.RpcResult;
65
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     @Mock
84     private NetworkModelListenerImpl networkModelListenerImpl;
85
86     private ServiceDataStoreOperations serviceDataStoreOperations;
87     private ListeningExecutorService executorService;
88     private CountDownLatch endSignal;
89     private static final int NUM_THREADS = 5;
90
91     @Before
92     public void setUp() {
93         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
94         endSignal = new CountDownLatch(1);
95         MockitoAnnotations.openMocks(this);
96         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
97     }
98
99     @Test
100     public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
101         ServicehandlerImpl servicehandlerImpl =
102             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
103                 notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
104                 serviceDataStoreOperations);
105         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
106             servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
107         result.addListener(new Runnable() {
108             @Override
109             public void run() {
110                 endSignal.countDown();
111             }
112         }, executorService);
113
114         endSignal.await();
115
116         RpcResult<ServiceCreateOutput> rpcResult = result.get();
117         Assert.assertEquals(
118             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
119     }
120
121     @Test
122     public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful()
123         throws ExecutionException, InterruptedException {
124         ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
125         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
126         ServicehandlerImpl servicehandlerImpl =
127             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
128                 notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
129                 serviceDataStoreOperations);
130         ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(input);
131         result.addListener(new Runnable() {
132             @Override
133             public void run() {
134                 endSignal.countDown();
135             }
136         }, executorService);
137
138         endSignal.await();
139
140         RpcResult<ServiceCreateOutput> rpcResult = result.get();
141         Assert.assertEquals(
142             ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
143     }
144
145     @Test
146     public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
147         ServicehandlerImpl servicehandlerImpl =
148             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
149                 notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
150                 serviceDataStoreOperations);
151         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
152             servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
153                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build());
154         result.addListener(new Runnable() {
155             @Override
156             public void run() {
157                 endSignal.countDown();
158             }
159         }, executorService);
160
161         endSignal.await();
162
163         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
164         Assert.assertEquals(
165             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
166     }
167
168     @Test
169     public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
170         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
171         ServicehandlerImpl servicehandlerImpl =
172             new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
173                 notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
174                 serviceDataStoreOperations);
175         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
176         result.addListener(new Runnable() {
177             @Override
178             public void run() {
179                 endSignal.countDown();
180             }
181         }, executorService);
182
183         endSignal.await();
184
185         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
186         Assert.assertEquals(
187             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
188     }
189
190     @Test
191     public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
192         DataBroker dataBroker = getNewDataBroker();
193         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
194         ServicehandlerImpl servicehandlerImpl =
195             new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
196                 notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
197                 serviceDataStoreOperations);
198         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
199         serviceDataStoreOperations.createService(createInput);
200         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
201         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
202         result.addListener(new Runnable() {
203             @Override
204             public void run() {
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                         serviceDataStoreOperations);
223         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
224                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
225         result.addListener(new Runnable() {
226             @Override
227             public void run() {
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                         serviceDataStoreOperations);
248         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
249             servicehandlerImpl.serviceFeasibilityCheck(input);
250         result.addListener(new Runnable() {
251             @Override
252             public void run() {
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                         serviceDataStoreOperations);
270         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
271                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
272         result.addListener(new Runnable() {
273             @Override
274             public void run() {
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                         serviceDataStoreOperations);
296         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
297
298         result.addListener(new Runnable() {
299             @Override
300             public void run() {
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                         serviceDataStoreOperations);
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                 endSignal.countDown();
336             }
337         }, executorService);
338
339         endSignal.await();
340
341         RpcResult<ServiceReconfigureOutput> rpcResult = result.get();
342         Assert.assertEquals(
343                 RpcStatus.Successful, rpcResult.getResult().getStatus());
344     }
345
346     @Test
347     public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
348         ServicehandlerImpl servicehandlerImpl =
349                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
350                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
351                         serviceDataStoreOperations);
352         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
353                 servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
354         result.addListener(new Runnable() {
355             @Override
356             public void run() {
357                 endSignal.countDown();
358             }
359         }, executorService);
360
361         endSignal.await();
362
363         RpcResult<ServiceRestorationOutput> rpcResult = result.get();
364         Assert.assertEquals(
365                 RpcStatus.Failed, rpcResult.getResult().getStatus());
366     }
367
368
369     @Test
370     public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
371         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
372
373         //action -> service restore
374         ServicehandlerImpl servicehandlerImpl =
375                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
376                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
377                         serviceDataStoreOperations);
378         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
379
380         result.addListener(new Runnable() {
381             @Override
382             public void run() {
383                 endSignal.countDown();
384             }
385         }, executorService);
386
387         endSignal.await();
388
389         RpcResult<ServiceRestorationOutput> rpcResult = result.get();
390         //ServiceRestorationOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly
391         Assert.assertEquals(
392                 RpcStatus.Failed, rpcResult.getResult().getStatus());
393     }
394
395     @Test
396     public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
397         DataBroker dataBroker = getNewDataBroker();
398
399         //mocking
400         // serviceRestoration is calling service delete method in renderer
401         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
402         //create service to restore
403         ServicehandlerImpl servicehandlerImpl =
404                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
405                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
406                         serviceDataStoreOperations);
407         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
408         serviceDataStoreOperations.createService(createInput);
409
410         //service Restoration test action
411         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
412         //ServiceRestorationInput is created with the same service information that is created before
413         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
414         result.addListener(new Runnable() {
415             @Override
416             public void run() {
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, networkModelListenerImpl,
433                         serviceDataStoreOperations);
434         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
435                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
436         result.addListener(new Runnable() {
437             @Override
438             public void run() {
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, networkModelListenerImpl,
458                         serviceDataStoreOperations);
459         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
460
461         result.addListener(new Runnable() {
462             @Override
463             public void run() {
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, networkModelListenerImpl,
487                         serviceDataStoreOperations);
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                 endSignal.countDown();
499             }
500         }, executorService);
501
502         endSignal.await();
503
504         RpcResult<ServiceRerouteOutput> rpcResult = result.get();
505         Assert.assertEquals(
506                 RpcStatus.Successful, rpcResult.getResult().getStatus());
507     }
508
509     @Test
510     public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
511         ServicehandlerImpl servicehandlerImpl =
512                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
513                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
514                         serviceDataStoreOperations);
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                 endSignal.countDown();
522             }
523         }, executorService);
524
525         endSignal.await();
526
527         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
528         Assert.assertEquals(
529             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
530         Assert.assertEquals(
531             LogMessages.SERVICE_NON_COMPLIANT,
532             rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
533     }
534
535     @Test
536     public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
537         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
538         ServicehandlerImpl servicehandlerImpl =
539                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
540                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
541                         serviceDataStoreOperations);
542         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
543         result.addListener(new Runnable() {
544             @Override
545             public void run() {
546                 endSignal.countDown();
547             }
548         }, executorService);
549
550         endSignal.await();
551
552         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
553         Assert.assertEquals(
554             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
555     }
556
557     @Test
558     public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
559         DataBroker dataBroker = getNewDataBroker();
560         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
561
562         //create temp service to delete in the temp delete action
563         ServicehandlerImpl servicehandlerImpl =
564                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
565                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
566                         serviceDataStoreOperations);
567         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
568         serviceDataStoreOperations.createTempService(createInput);
569
570
571         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
572         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
573         result.addListener(new Runnable() {
574             @Override
575             public void run() {
576                 endSignal.countDown();
577             }
578         }, executorService);
579
580         endSignal.await();
581
582         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
583         Assert.assertEquals(
584                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
585     }
586
587     @Test
588     public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
589         ServicehandlerImpl servicehandlerImpl =
590                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
591                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
592                         serviceDataStoreOperations);
593         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
594                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
595         result.addListener(new Runnable() {
596             @Override
597             public void run() {
598                 endSignal.countDown();
599             }
600         }, executorService);
601
602         endSignal.await();
603
604         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
605         Assert.assertEquals(
606             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
607     }
608
609
610     @Test
611     public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful()
612             throws ExecutionException, InterruptedException {
613         TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
614         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
615
616         ServicehandlerImpl servicehandlerImpl =
617                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
618                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
619                         serviceDataStoreOperations);
620
621         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =  servicehandlerImpl.tempServiceCreate(input);
622         result.addListener(new Runnable() {
623             @Override
624             public void run() {
625                 endSignal.countDown();
626             }
627         }, executorService);
628
629         endSignal.await();
630
631         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
632
633         Assert.assertEquals(
634                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
635     }
636
637 }