Upgrade openroadm service models to 10.1
[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.service.rev211210.ServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureOutput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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 ServiceDataStoreOperations serviceDataStoreOperations;
86     private ListeningExecutorService executorService;
87     private CountDownLatch endSignal;
88     private static final int NUM_THREADS = 5;
89
90     @Before
91     public void setUp() {
92         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
93         endSignal = new CountDownLatch(1);
94         MockitoAnnotations.openMocks(this);
95         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
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                 serviceDataStoreOperations);
104         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
105             servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
106         result.addListener(new Runnable() {
107             @Override
108             public void run() {
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                 serviceDataStoreOperations);
129         ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(input);
130         result.addListener(new Runnable() {
131             @Override
132             public void run() {
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                 serviceDataStoreOperations);
150         ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
151             servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
152                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build());
153         result.addListener(new Runnable() {
154             @Override
155             public void run() {
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                 serviceDataStoreOperations);
174         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
175         result.addListener(new Runnable() {
176             @Override
177             public void run() {
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                 serviceDataStoreOperations);
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                 endSignal.countDown();
205             }
206         }, executorService);
207
208         endSignal.await();
209
210         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
211         Assert.assertEquals(
212             ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
213     }
214
215
216     @Test
217     public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
218         ServicehandlerImpl servicehandlerImpl =
219                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
220                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
221                         serviceDataStoreOperations);
222         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
223                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
224         result.addListener(new Runnable() {
225             @Override
226             public void run() {
227                 endSignal.countDown();
228             }
229         }, executorService);
230
231         endSignal.await();
232
233         RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
234         Assert.assertEquals(
235             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
236     }
237
238     @Test
239     public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful()
240             throws ExecutionException, InterruptedException {
241         ServiceFeasibilityCheckInput input = ServiceDataUtils.buildServiceFeasibilityCheckInput();
242         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
243         ServicehandlerImpl servicehandlerImpl =
244                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
245                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
246                         serviceDataStoreOperations);
247         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
248             servicehandlerImpl.serviceFeasibilityCheck(input);
249         result.addListener(new Runnable() {
250             @Override
251             public void run() {
252                 endSignal.countDown();
253             }
254         }, executorService);
255
256         endSignal.await();
257
258         RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
259         Assert.assertEquals(
260                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
261     }
262
263     @Test
264     public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
265         ServicehandlerImpl servicehandlerImpl =
266                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
267                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
268                         serviceDataStoreOperations);
269         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
270                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
271         result.addListener(new Runnable() {
272             @Override
273             public void run() {
274                 endSignal.countDown();
275             }
276         }, executorService);
277
278         endSignal.await();
279     }
280
281
282     @Test
283     public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
284         ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
285
286         //action -> service reconfigure
287         ServicehandlerImpl servicehandlerImpl =
288                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
289                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
290                         serviceDataStoreOperations);
291         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
292
293         result.addListener(new Runnable() {
294             @Override
295             public void run() {
296                 endSignal.countDown();
297             }
298         }, executorService);
299
300         endSignal.await();
301     }
302
303     @Test
304     public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
305         DataBroker dataBroker = getNewDataBroker();
306
307         //mocking
308         // serviceReconfigure is calling service delete method in renderer
309         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
310         //create service to reconfigure
311         ServicehandlerImpl servicehandlerImpl =
312                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
313                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
314                         serviceDataStoreOperations);
315         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
316         serviceDataStoreOperations.createService(createInput);
317
318         //service reconfigure test action
319         ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
320         //ServiceReconfigureInput is created with the same service information that is created before
321         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
322         result.addListener(new Runnable() {
323             @Override
324             public void run() {
325                 endSignal.countDown();
326             }
327         }, executorService);
328
329         endSignal.await();
330     }
331
332     @Test
333     public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
334         ServicehandlerImpl servicehandlerImpl =
335                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
336                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
337                         serviceDataStoreOperations);
338         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
339                 servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
340         result.addListener(new Runnable() {
341             @Override
342             public void run() {
343                 endSignal.countDown();
344             }
345         }, executorService);
346
347         endSignal.await();
348     }
349
350
351     @Test
352     public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
353         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
354
355         //action -> service restore
356         ServicehandlerImpl servicehandlerImpl =
357                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
358                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
359                         serviceDataStoreOperations);
360         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
361
362         result.addListener(new Runnable() {
363             @Override
364             public void run() {
365                 endSignal.countDown();
366             }
367         }, executorService);
368
369         endSignal.await();
370     }
371
372     @Test
373     public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
374         DataBroker dataBroker = getNewDataBroker();
375
376         //mocking
377         // serviceRestoration is calling service delete method in renderer
378         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
379         //create service to restore
380         ServicehandlerImpl servicehandlerImpl =
381                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
382                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
383                         serviceDataStoreOperations);
384         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
385         serviceDataStoreOperations.createService(createInput);
386
387         //service Restoration test action
388         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
389         //ServiceRestorationInput is created with the same service information that is created before
390         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
391         result.addListener(new Runnable() {
392             @Override
393             public void run() {
394                 endSignal.countDown();
395             }
396         }, executorService);
397
398         endSignal.await();
399     }
400
401     @Test
402     public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
403         ServicehandlerImpl servicehandlerImpl =
404                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
405                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
406                         serviceDataStoreOperations);
407         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
408                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
409         result.addListener(new Runnable() {
410             @Override
411             public void run() {
412                 endSignal.countDown();
413             }
414         }, executorService);
415
416         endSignal.await();
417     }
418
419     @Test
420     public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
421         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
422
423         //action -> service reconfigure
424         ServicehandlerImpl servicehandlerImpl =
425                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
426                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
427                         serviceDataStoreOperations);
428         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
429
430         result.addListener(new Runnable() {
431             @Override
432             public void run() {
433                 endSignal.countDown();
434             }
435         }, executorService);
436
437         endSignal.await();
438     }
439
440     @Test
441     public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
442         DataBroker dataBroker = getNewDataBroker();
443
444         //mocking
445         // serviceReroute is calling service delete method in renderer
446         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
447         //create service to be rerouted later
448         ServicehandlerImpl servicehandlerImpl =
449                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
450                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
451                         serviceDataStoreOperations);
452         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
453         serviceDataStoreOperations.createService(createInput);
454
455         //service reroute test action
456         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
457         //ServiceRerouteInput is created with the same service information that is created before
458         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
459         result.addListener(new Runnable() {
460             @Override
461             public void run() {
462                 endSignal.countDown();
463             }
464         }, executorService);
465
466         endSignal.await();
467     }
468
469     @Test
470     public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
471         ServicehandlerImpl servicehandlerImpl =
472                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
473                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
474                         serviceDataStoreOperations);
475         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
476                 servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder()
477                         .setCommonId("").build());
478         result.addListener(new Runnable() {
479             @Override
480             public void run() {
481                 endSignal.countDown();
482             }
483         }, executorService);
484
485         endSignal.await();
486
487         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
488         Assert.assertEquals(
489             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
490         Assert.assertEquals(
491             LogMessages.SERVICE_NON_COMPLIANT,
492             rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
493     }
494
495     @Test
496     public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
497         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
498         ServicehandlerImpl servicehandlerImpl =
499                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
500                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
501                         serviceDataStoreOperations);
502         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
503         result.addListener(new Runnable() {
504             @Override
505             public void run() {
506                 endSignal.countDown();
507             }
508         }, executorService);
509
510         endSignal.await();
511
512         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
513         Assert.assertEquals(
514             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
515     }
516
517     @Test
518     public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
519         DataBroker dataBroker = getNewDataBroker();
520         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
521
522         //create temp service to delete in the temp delete action
523         ServicehandlerImpl servicehandlerImpl =
524                 new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
525                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
526                         serviceDataStoreOperations);
527         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
528         serviceDataStoreOperations.createTempService(createInput);
529
530
531         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
532         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
533         result.addListener(new Runnable() {
534             @Override
535             public void run() {
536                 endSignal.countDown();
537             }
538         }, executorService);
539
540         endSignal.await();
541
542         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
543         Assert.assertEquals(
544                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
545     }
546
547     @Test
548     public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
549         ServicehandlerImpl servicehandlerImpl =
550                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
551                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
552                         serviceDataStoreOperations);
553         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
554                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
555         result.addListener(new Runnable() {
556             @Override
557             public void run() {
558                 endSignal.countDown();
559             }
560         }, executorService);
561
562         endSignal.await();
563
564         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
565         Assert.assertEquals(
566             ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
567     }
568
569
570     @Test
571     public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful()
572             throws ExecutionException, InterruptedException {
573         TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
574         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
575
576         ServicehandlerImpl servicehandlerImpl =
577                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
578                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
579                         serviceDataStoreOperations);
580
581         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =  servicehandlerImpl.tempServiceCreate(input);
582         result.addListener(new Runnable() {
583             @Override
584             public void run() {
585                 endSignal.countDown();
586             }
587         }, executorService);
588
589         endSignal.await();
590
591         RpcResult<TempServiceCreateOutput> rpcResult = result.get();
592
593         Assert.assertEquals(
594                 ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
595     }
596
597 }