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