Add unit & func tests for RPC service-reroute
[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.mockito.Mockito.mock;
12 import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
13
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import java.util.Map;
19 import java.util.Optional;
20 import java.util.concurrent.CountDownLatch;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executors;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.mockito.MockitoAnnotations;
29 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
30 import org.opendaylight.transportpce.common.ResponseCodes;
31 import org.opendaylight.transportpce.pce.service.PathComputationService;
32 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
33 import org.opendaylight.transportpce.servicehandler.ServiceInput;
34 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl;
35 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
36 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
37 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
38 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
39 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
40 import org.opendaylight.transportpce.test.AbstractTest;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteOutput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.delete.input.ServiceDeleteReqInfoBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey;
75 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.ResourceBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPointBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
78 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
79 import org.opendaylight.yangtools.yang.common.RpcResult;
80 import org.opendaylight.yangtools.yang.common.Uint32;
81
82 public class ServicehandlerImplTest extends AbstractTest {
83
84     @Mock
85     private PathComputationService pathComputationService;
86
87     @Mock
88     private RendererServiceOperations rendererServiceOperations;
89
90     @Mock
91     private NotificationPublishService notificationPublishService;
92
93     @Mock
94     private PceListenerImpl pceListenerImpl;
95
96     @Mock
97     private RendererListenerImpl rendererListenerImpl;
98
99     @Mock
100     private NetworkModelListenerImpl networkModelListenerImpl;
101
102     private ServiceDataStoreOperations serviceDataStoreOperations;
103     private ServiceCreateInput serviceCreateInput;
104     private ServiceDeleteInput serviceDeleteInput;
105     private ServiceReconfigureInput serviceReconfigureInput;
106     private ServiceRestorationInput serviceRestorationInput;
107     private ServiceRerouteInput serviceRerouteInput;
108     private ListeningExecutorService executorService;
109     private CountDownLatch endSignal;
110     private static final int NUM_THREADS = 5;
111
112     @Before
113     public void setUp() {
114         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
115         endSignal = new CountDownLatch(1);
116         MockitoAnnotations.openMocks(this);
117         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
118         serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
119         serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
120         serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput();
121         serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput();
122         serviceRerouteInput = ServiceDataUtils.buildServiceRerouteInput();
123     }
124
125     @Test
126     public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
127         ServicehandlerImpl servicehandlerImpl =
128                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
129                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
130                         serviceDataStoreOperations);
131         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
132                 servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
133         result.addListener(() -> endSignal.countDown(), executorService);
134
135         endSignal.await();
136         Assert.assertEquals(
137                 ResponseCodes.RESPONSE_FAILED,
138                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
139     }
140
141     @Test
142     public void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException,
143             InterruptedException {
144         final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
145         Mockito.when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
146                 .thenReturn(Optional.of(
147                         new ServicesBuilder()
148                                 .setServiceName(serviceCreateInput.getServiceName())
149                                 .build()));
150         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
151                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
152                 networkModelListenerImpl, serviceDSOperations);
153         ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
154         result.addListener(() -> endSignal.countDown(), executorService);
155
156         endSignal.await();
157         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
158                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
159     }
160
161     @Test
162     public void createServiceShouldBeSuccessfulWhenPerformPCESuccessful()
163             throws ExecutionException, InterruptedException {
164         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
165         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
166                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
167                 networkModelListenerImpl, serviceDataStoreOperations);
168         ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
169         result.addListener(() -> endSignal.countDown(), executorService);
170
171         endSignal.await();
172         Assert.assertEquals(
173                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
174     }
175
176     @Test
177     public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
178         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
179                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
180                 networkModelListenerImpl, serviceDataStoreOperations);
181         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(
182                 new ServiceDeleteInputBuilder()
183                         .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
184                                 .setServiceName("")
185                                 .build())
186                         .build());
187         result.addListener(() -> endSignal.countDown(), executorService);
188
189         endSignal.await();
190         Assert.assertEquals(
191                 ResponseCodes.RESPONSE_FAILED,
192                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
193     }
194
195     @Test
196     public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
197         ServicehandlerImpl servicehandlerImpl =
198                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
199                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
200                         serviceDataStoreOperations);
201         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
202         result.addListener(() -> endSignal.countDown(), executorService);
203
204         endSignal.await();
205         Assert.assertEquals(
206                 ResponseCodes.RESPONSE_FAILED,
207                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
208     }
209
210     @Test
211     public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
212         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
213         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
214                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
215                 networkModelListenerImpl, serviceDataStoreOperations);
216         serviceDataStoreOperations.createService(serviceCreateInput);
217         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
218         result.addListener(() -> endSignal.countDown(), executorService);
219
220         endSignal.await();
221         Assert.assertEquals(
222                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
223     }
224
225
226     @Test
227     public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
228         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
229                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
230                 networkModelListenerImpl, serviceDataStoreOperations);
231         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
232                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
233         result.addListener(() -> endSignal.countDown(), executorService);
234
235         endSignal.await();
236         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
237                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
238     }
239
240     @Test
241     public void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
242             throws ExecutionException, InterruptedException {
243         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
244         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
245                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
246                 networkModelListenerImpl, serviceDataStoreOperations);
247         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
248                 servicehandlerImpl.serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput());
249         result.addListener(() -> endSignal.countDown(), executorService);
250
251         endSignal.await();
252         Assert.assertEquals(
253                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
254     }
255
256     @Test
257     public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
258         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
259                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
260                 networkModelListenerImpl, serviceDataStoreOperations);
261         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
262                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
263         result.addListener(() -> endSignal.countDown(), executorService);
264
265         endSignal.await();
266     }
267
268
269     @Test
270     public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
271         //action -> service reconfigure
272         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
273                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
274                 networkModelListenerImpl, serviceDataStoreOperations);
275         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
276                 serviceReconfigureInput);
277
278         result.addListener(() -> endSignal.countDown(), executorService);
279
280         endSignal.await();
281     }
282
283     @Test
284     public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
285         // serviceReconfigure is calling service delete method in renderer
286         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
287         //create service to reconfigure
288         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
289                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
290                 networkModelListenerImpl, serviceDataStoreOperations);
291         serviceDataStoreOperations.createService(serviceCreateInput);
292
293         //service reconfigure test action
294         //ServiceReconfigureInput is created with the same service information that is created before
295         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
296                 serviceReconfigureInput);
297         result.addListener(() -> endSignal.countDown(), executorService);
298
299         endSignal.await();
300     }
301
302     @Test
303     public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
304         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
305                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
306                 networkModelListenerImpl, serviceDataStoreOperations);
307         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
308                 servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
309         result.addListener(() -> endSignal.countDown(), executorService);
310
311         endSignal.await();
312     }
313
314
315     @Test
316     public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
317         //action -> service restore
318         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
319                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
320                 networkModelListenerImpl, serviceDataStoreOperations);
321         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
322                 serviceRestorationInput);
323
324         result.addListener(() -> endSignal.countDown(), executorService);
325
326         endSignal.await();
327     }
328
329     @Test
330     public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
331         // serviceRestoration is calling service delete method in renderer
332         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
333         //create service to restore
334         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
335                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
336                 networkModelListenerImpl, serviceDataStoreOperations);
337         serviceDataStoreOperations.createService(serviceCreateInput);
338
339         //service Restoration test action
340         //ServiceRestorationInput is created with the same service information that is created before
341         ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
342                 serviceRestorationInput);
343         result.addListener(() -> endSignal.countDown(), executorService);
344
345         endSignal.await();
346     }
347
348     @Test
349     public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
350         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
351                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
352                 networkModelListenerImpl, serviceDataStoreOperations);
353         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
354                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
355         result.addListener(() -> endSignal.countDown(), executorService);
356
357         endSignal.await();
358
359         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
360                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
361     }
362
363     @Test
364     public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
365         //action -> service reconfigure
366         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
367                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
368                 networkModelListenerImpl, serviceDataStoreOperations);
369         ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(
370                 serviceRerouteInput);
371
372         result.addListener(() -> endSignal.countDown(), executorService);
373
374         endSignal.await();
375
376         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
377                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
378     }
379
380     @Test
381     public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
382         Mockito.when(pathComputationService.pathComputationRerouteRequest(any()))
383                 .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder()
384                         .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder()
385                                 .setResponseCode(ResponseCodes.RESPONSE_OK)
386                                 .build())
387                         .build()));
388         Map<AToZKey, AToZ> atoz = Map.of(
389                 new AToZKey("0"),
390                 new AToZBuilder()
391                         .setId("0")
392                         .setResource(new ResourceBuilder()
393                                 .setResource(new TerminationPointBuilder()
394                                         .setTpNodeId("tpNodeIdC")
395                                         .setTpId("TpIdC1")
396                                         .build())
397                                 .setState(State.InService)
398                                 .build())
399                         .build(),
400                 new AToZKey("1"),
401                 new AToZBuilder()
402                         .setId("1")
403                         .setResource(new ResourceBuilder()
404                                 .setResource(new TerminationPointBuilder()
405                                         .setTpNodeId("tpNodeIdD")
406                                         .setTpId("TpIdCD")
407                                         .build())
408                                 .setState(State.InService)
409                                 .build())
410                         .build(), new AToZKey("2"),
411                 new AToZBuilder()
412                         .setId("2")
413                         .setResource(new ResourceBuilder()
414                                 .setResource(new TerminationPointBuilder()
415                                         .setTpNodeId("tpNodeIdA")
416                                         .setTpId("TpIdA1")
417                                         .build())
418                                 .setState(State.InService)
419                                 .build())
420                         .build()
421
422         );
423         serviceDataStoreOperations.createServicePath(new ServiceInput(serviceCreateInput),
424                 new PathComputationRequestOutputBuilder()
425                         .setResponseParameters(new ResponseParametersBuilder()
426                                 .setPathDescription(new PathDescriptionBuilder()
427                                         .setAToZDirection(new AToZDirectionBuilder()
428                                                 .setAToZ(atoz)
429                                                 .setRate(Uint32.valueOf(1))
430                                                 .build())
431                                         .setZToADirection(new ZToADirectionBuilder()
432                                                 .setRate(Uint32.valueOf(1))
433                                                 .build())
434                                         .build())
435                                 .build())
436                         .build());
437
438         serviceDataStoreOperations.createService(serviceCreateInput);
439         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =  new ServicehandlerImpl(getNewDataBroker(),
440                 pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl,
441                 rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations)
442                 .serviceReroute(serviceRerouteInput);
443         result.addListener(() -> endSignal.countDown(), executorService);
444
445         endSignal.await();
446
447         Assert.assertEquals(
448                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
449     }
450
451     @Test
452     public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
453         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
454                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
455                 networkModelListenerImpl, serviceDataStoreOperations);
456         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
457                 servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder().setCommonId("").build());
458         result.addListener(() -> endSignal.countDown(), executorService);
459
460         endSignal.await();
461
462         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
463         Assert.assertEquals(
464                 ResponseCodes.RESPONSE_FAILED,
465                 rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
466         Assert.assertEquals(
467                 LogMessages.SERVICE_NON_COMPLIANT,
468                 rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
469     }
470
471     @Test
472     public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
473         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
474                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
475                 networkModelListenerImpl, serviceDataStoreOperations);
476         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(
477                 ServiceDataUtils.buildTempServiceDeleteInput());
478         result.addListener(() -> endSignal.countDown(), executorService);
479
480         endSignal.await();
481         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
482                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
483     }
484
485     @Test
486     public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
487         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
488
489         //create temp service to delete in the temp delete action
490         ServicehandlerImpl servicehandlerImpl =
491                 new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
492                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
493                         serviceDataStoreOperations);
494         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
495         serviceDataStoreOperations.createTempService(createInput);
496
497         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
498         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
499         result.addListener(() -> endSignal.countDown(), executorService);
500
501         endSignal.await();
502         Assert.assertEquals(
503                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
504     }
505
506     @Test
507     public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
508         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
509                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
510                 networkModelListenerImpl, serviceDataStoreOperations);
511         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
512                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
513         result.addListener(() -> endSignal.countDown(), executorService);
514
515         endSignal.await();
516         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
517                 result.get().getResult().getConfigurationResponseCommon().getResponseCode());
518     }
519
520
521     @Test
522     public void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
523             throws ExecutionException, InterruptedException {
524         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
525
526         ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
527                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
528                 networkModelListenerImpl, serviceDataStoreOperations);
529
530         ListenableFuture<RpcResult<TempServiceCreateOutput>> result = servicehandlerImpl.tempServiceCreate(
531                 ServiceDataUtils.buildTempServiceCreateInput());
532         result.addListener(() -> endSignal.countDown(), executorService);
533
534         endSignal.await();
535         Assert.assertEquals(
536                 ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
537     }
538
539 }