Service-notification handling for Renderer
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / impl / ServiceHandlerImplTest.java
1 /*
2  * Copyright © 2018 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.verify;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.ListeningExecutorService;
15 import com.google.common.util.concurrent.MoreExecutors;
16
17 import java.lang.reflect.InvocationTargetException;
18 import java.lang.reflect.Method;
19 import java.util.Arrays;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Optional;
23 import java.util.concurrent.Callable;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.Executors;
26 import java.util.concurrent.Future;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
36 import org.opendaylight.transportpce.common.OperationResult;
37 import org.opendaylight.transportpce.common.ResponseCodes;
38 import org.opendaylight.transportpce.pce.service.PathComputationService;
39 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
40 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
41 import org.opendaylight.transportpce.pce.utils.PceTestData;
42 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
43 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
44 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
45 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
46 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
47 import org.opendaylight.transportpce.servicehandler.ServiceInput;
48 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
49 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
50 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
51 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
52 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
53 import org.opendaylight.transportpce.test.AbstractTest;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInputBuilder;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
88 import org.opendaylight.yangtools.yang.common.RpcResult;
89 import org.slf4j.Logger;
90 import org.slf4j.LoggerFactory;
91
92 public class ServiceHandlerImplTest extends AbstractTest {
93
94     private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class);
95     private static final int NUMBER_OF_THREADS = 4;
96
97     private PathComputationService pathComputationService;
98     private RendererServiceOperations rendererServiceOperations;
99     private NetworkModelWavelengthService networkModelWavelengthService;
100     private ServicehandlerImpl serviceHandler;
101     private ListeningExecutorService executor;
102
103     @Mock
104     private ServiceDataStoreOperations serviceDataStoreOperationsMock;
105
106     @Mock
107     private PCEServiceWrapper pceServiceWrapperMock;
108
109     @Mock
110     private RendererServiceOperations rendererServiceOperationsMock;
111
112     @Mock
113     private ComplianceCheckResult complianceCheckResultMock;
114
115     @Mock
116     private Optional<Services> servicesOptionalMock;
117
118     @InjectMocks
119     private ServicehandlerImpl serviceHandlerImplMock;
120
121     @Before
122     public void setUp() {
123         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService,
124                 this.rendererServiceOperations, this.networkModelWavelengthService);
125         this.serviceHandlerImplMock = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null);
126         MockitoAnnotations.initMocks(this);
127     }
128
129     public ServiceHandlerImplTest() throws Exception {
130         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
131         this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService);
132         PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
133                 "topologyData/NW-simple-topology.xml");
134         this.rendererServiceOperations =
135                 new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker(),
136                         notificationPublishService);
137         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
138     }
139
140     @Test
141     public void testCreateServiceValid() throws ExecutionException, InterruptedException {
142
143         ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput();
144         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
145                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
146                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
147         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
148                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
149                         .setConfigurationResponseCommon(configurationResponseCommon).build();
150
151         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true))
152             .thenReturn(pathComputationRequestOutput);
153         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
154                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
155         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
156                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
157         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
158                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
159                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
160         Mockito.when(
161                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
162                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
163                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
164         Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceInput.getServiceName(),
165                 State.InService, State.InService)).thenReturn(OperationResult.ok("successful"));
166
167         Future<RpcResult<ServiceCreateOutput>> output0 = this.serviceHandlerImplMock.serviceCreate(serviceInput);
168         Assert.assertNotNull(output0);
169         Assert.assertTrue(output0.get().isSuccessful());
170         Assert.assertEquals(output0.get().getResult(),
171                 ModelMappingUtils.createCreateServiceReply(serviceInput, ResponseCodes.FINAL_ACK_YES,
172                         "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get().getResult());
173         Assert.assertEquals(0, output0.get().getErrors().size());
174     }
175
176     private <T> ListenableFuture<T> returnFuture(T output) {
177         return executor.submit(new Callable<T>() {
178
179             @Override
180             public T call() throws Exception {
181                 return output;
182             }
183         });
184     }
185
186     @Test
187     public void createTempServiceHandlerServiceCreateValid() throws ExecutionException, InterruptedException {
188         TempServiceCreateInput serviceInput = ServiceDataUtils.buildTempServiceCreateInput();
189         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
190                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
191                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
192         PathComputationRequestOutput pathComputationRequestOutput =
193                 new PathComputationRequestOutputBuilder(PceTestData.getPCE_simpletopology_test1_result((long) 5))
194                         .setConfigurationResponseCommon(configurationResponseCommon).build();
195         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true))
196                 .thenReturn(pathComputationRequestOutput);
197         Mockito.when(this.serviceDataStoreOperationsMock.createTempService(any(TempServiceCreateInput.class),
198                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
199         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
200                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
201         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
202                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
203                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
204         Mockito.when(
205                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
206                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
207                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
208         Mockito.when(this.serviceDataStoreOperationsMock.modifyTempService(serviceInput.getCommonId(), State.InService,
209                 State.InService)).thenReturn(OperationResult.ok("successful"));
210         Future<RpcResult<TempServiceCreateOutput>> output0 =
211                 this.serviceHandlerImplMock.tempServiceCreate(serviceInput);
212         Assert.assertNotNull(output0);
213         Assert.assertTrue(output0.get().isSuccessful());
214         Assert.assertEquals(output0.get().getResult(), ModelMappingUtils.createCreateServiceReply(serviceInput,
215                 ResponseCodes.FINAL_ACK_YES, "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get()
216                 .getResult());
217         Assert.assertEquals(0, output0.get().getErrors().size());
218     }
219
220     @Test
221     public void createServiceHandlerInvalidIfNameIsEmpty() throws ExecutionException, InterruptedException {
222         ServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
223         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyServiceNameInput);
224         emptyServiceNameInput = builtInput.setServiceName("").build();
225         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceNameInput).get().getResult(),
226                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
227                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
228                         .getResult());
229     }
230
231     @Test
232     public void createServiceHandlerInvalidIfNameIsNull() throws ExecutionException, InterruptedException {
233         ServiceCreateInput nullServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
234         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(nullServiceNameInput);
235         nullServiceNameInput = builtInput.setServiceName(null).build();
236         Assert.assertEquals(this.serviceHandler.serviceCreate(nullServiceNameInput).get().getResult(),
237                 ModelMappingUtils.createCreateServiceReply(nullServiceNameInput, ResponseCodes.FINAL_ACK_YES,
238                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
239                         .getResult());
240     }
241
242     @Test
243     public void createTempServiceHandlerInvalidIfCommonIdIsEmpty() throws ExecutionException, InterruptedException {
244         TempServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildTempServiceCreateInput();
245         TempServiceCreateInputBuilder builtInput = new TempServiceCreateInputBuilder(emptyServiceNameInput);
246         emptyServiceNameInput = builtInput.setCommonId("").build();
247         Assert.assertEquals(this.serviceHandler.tempServiceCreate(emptyServiceNameInput).get().getResult(),
248                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
249                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
250                         .getResult());
251     }
252
253     @Test
254     public void createTempServiceHandlerInvalidIfCommonIdIsNull() throws ExecutionException, InterruptedException {
255         TempServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildTempServiceCreateInput();
256         TempServiceCreateInputBuilder builtInput = new TempServiceCreateInputBuilder(emptyServiceNameInput);
257         emptyServiceNameInput = builtInput.setCommonId(null).build();
258         Assert.assertEquals(this.serviceHandler.tempServiceCreate(emptyServiceNameInput).get().getResult(),
259                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
260                                 "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED)
261                         .get().getResult());
262     }
263
264     @Test
265     public void createServiceHnadlerInvalidIfConTypeIsEmpty() throws ExecutionException, InterruptedException {
266         ServiceCreateInput emptyConTypeInput = ServiceDataUtils.buildServiceCreateInput();
267         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyConTypeInput);
268         emptyConTypeInput = builtInput.setConnectionType(null).build();
269         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyConTypeInput).get().getResult(),
270                 ModelMappingUtils.createCreateServiceReply(emptyConTypeInput, ResponseCodes.FINAL_ACK_YES,
271                         "Service ConnectionType is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
272     }
273
274     @Test
275     public void createServiceHandlerInvalidIfSdncRequestHeaderNull() throws ExecutionException, InterruptedException {
276         ServiceCreateInput emptySdncRequestHeader = ServiceDataUtils.buildServiceCreateInput();
277         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptySdncRequestHeader);
278         emptySdncRequestHeader = buildInput.setSdncRequestHeader(null).build();
279         ServiceCreateOutput result = this.serviceHandler.serviceCreate(emptySdncRequestHeader).get().getResult();
280         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
281         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
282                 ResponseCodes.FINAL_ACK_YES);
283     }
284
285     @Test
286     public void createServiceHandlerInvalidIfRequestIdEmpty() throws ExecutionException, InterruptedException {
287         ServiceCreateInput emptyRequestId = ServiceDataUtils.buildServiceCreateInput();
288         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyRequestId);
289         emptyRequestId = buildInput
290                 .setSdncRequestHeader(
291                         new SdncRequestHeaderBuilder(emptyRequestId.getSdncRequestHeader()).setRequestId("").build())
292                 .build();
293         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyRequestId).get().getResult(),
294                 ModelMappingUtils
295                         .createCreateServiceReply(emptyRequestId, ResponseCodes.FINAL_ACK_YES,
296                                 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
297                         .get().getResult());
298     }
299
300     @Test
301     public void createServiceHandlerInvalidIfRequestIdNull() throws ExecutionException, InterruptedException {
302         ServiceCreateInput nullRequestId = ServiceDataUtils.buildServiceCreateInput();
303         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(nullRequestId);
304         nullRequestId = buildInput
305                 .setSdncRequestHeader(
306                         new SdncRequestHeaderBuilder(nullRequestId.getSdncRequestHeader()).setRequestId(null).build())
307                 .build();
308         Assert.assertEquals(this.serviceHandler.serviceCreate(nullRequestId).get().getResult(),
309                 ModelMappingUtils
310                         .createCreateServiceReply(nullRequestId, ResponseCodes.FINAL_ACK_YES,
311                                 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
312                         .get().getResult());
313     }
314
315     @Test
316     public void serviceHandlerInvalidServiceActionIsNull() throws ExecutionException, InterruptedException {
317         ServiceCreateInput emptyServiceAction = ServiceDataUtils.buildServiceCreateInput();
318         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyServiceAction);
319         emptyServiceAction = buildInput.setSdncRequestHeader(
320                 new SdncRequestHeaderBuilder(emptyServiceAction.getSdncRequestHeader()).setRpcAction(null).build())
321                 .build();
322         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceAction).get().getResult(),
323                 ModelMappingUtils
324                         .createCreateServiceReply(emptyServiceAction, ResponseCodes.FINAL_ACK_YES,
325                                 "Service sndc-request-header 'rpc-action' is not set ", ResponseCodes.RESPONSE_FAILED)
326                         .get().getResult());
327     }
328
329     @Test
330     public void serviceHandlerInvalidServiceActionIsNotCreate() throws ExecutionException, InterruptedException {
331         ServiceCreateInput notCreateServiceAction = ServiceDataUtils.buildServiceCreateInput();
332         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notCreateServiceAction);
333         notCreateServiceAction = buildInput
334                 .setSdncRequestHeader(new SdncRequestHeaderBuilder(notCreateServiceAction.getSdncRequestHeader())
335                         .setRpcAction(RpcActions.ServiceFeasibilityCheck).build())
336                 .build();
337         Assert.assertEquals(this.serviceHandler.serviceCreate(notCreateServiceAction).get().getResult(),
338                 ModelMappingUtils.createCreateServiceReply(notCreateServiceAction, ResponseCodes.FINAL_ACK_YES,
339                         "Service sdncRequestHeader rpc-action '"
340                                 + notCreateServiceAction.getSdncRequestHeader().getRpcAction() + "' not equal to '"
341                                 + RpcActions.ServiceCreate.name() + "'",
342                         ResponseCodes.RESPONSE_FAILED).get().getResult());
343     }
344
345     @Test
346     public void createServiceHandlerNotValidServiceAEndIsNull() throws ExecutionException, InterruptedException {
347         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
348         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
349         notValidServiceAEnd = buildInput.setServiceAEnd(null).build();
350         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
351                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
352                         "SERVICEAEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
353     }
354
355     @Test
356     public void createServiceHandlerNotValidServiceZEndIsNull() throws ExecutionException, InterruptedException {
357         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
358         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
359         notValidServiceAEnd = buildInput.setServiceZEnd(null).build();
360         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
361                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
362                         "SERVICEZEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
363     }
364
365     @Test
366     public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException {
367         ServicehandlerImpl servicehandler =
368                 new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null);
369         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
370         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
371         notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setServiceRate(null)
372                 .build()).build();
373         Assert.assertEquals(servicehandler.serviceCreate(notValidServiceAEnd).get().getResult(),
374                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
375                         "Service " + ServiceEndpointType.SERVICEAEND + " rate is not set",
376                         ResponseCodes.RESPONSE_FAILED).get().getResult());
377     }
378
379     @Test
380     public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException {
381         ServicehandlerImpl servicehandler =
382                 new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null);
383         ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
384         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
385         notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setServiceRate(null)
386                 .build()).build();
387         Assert.assertEquals(servicehandler.serviceCreate(notValidServiceZEnd).get().getResult(),
388                 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
389                         "Service " + ServiceEndpointType.SERVICEZEND + " rate is not set",
390                         ResponseCodes.RESPONSE_FAILED).get().getResult());
391     }
392
393     @Test
394     public void createServiceHandlerNotValidServiceAEndClliIsNull()
395             throws ExecutionException, InterruptedException {
396         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
397         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
398         notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setClli(null)
399                 .build()).build();
400         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
401                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
402                         "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set",
403                         ResponseCodes.RESPONSE_FAILED).get().getResult());
404     }
405
406     @Test
407     public void createServiceHandlerNotValidServiceZEndClliIsNull()
408             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
409         ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
410         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
411         notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setClli(null).build())
412                 .build();
413         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceZEnd).get().getResult(),
414                 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
415                         "Service" + ServiceEndpointType.SERVICEZEND + " clli format is not set",
416                         ResponseCodes.RESPONSE_FAILED).get().getResult());
417     }
418
419     @Test
420     public void createServiceHandlerNotValidServiceAEndAttributes()
421             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
422         HashMap<String, Object> notValidData = new HashMap<>();
423         notValidData.put("setServiceRate", 0L);
424         notValidData.put("setServiceFormat", null);
425         notValidData.put("setClli", "");
426         notValidData.put("setTxDirection", null);
427         notValidData.put("setRxDirection", null);
428         for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
429                 .ServiceAEndBuilder.class.getDeclaredMethods()) {
430             if (notValidData.containsKey(method.getName())) {
431                 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
432                         .buildServiceCreateInput());
433                 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
434                     .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
435                 method.invoke(serviceAEndBuilder, notValidData.get(method.getName()));
436                 ServiceCreateOutput result = this.serviceHandler
437                         .serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get().getResult();
438                 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
439                         ResponseCodes.FINAL_ACK_YES);
440                 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
441                         ResponseCodes.RESPONSE_FAILED);
442             }
443         }
444     }
445
446     @Test
447     public void createServiceHandlerNotValidServiceZEndAttributes()
448             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
449         HashMap<String, Object> notValidData = new HashMap<>();
450         notValidData.put("setServiceRate", 0L);
451         notValidData.put("setServiceFormat", null);
452         notValidData.put("setClli", "");
453         notValidData.put("setTxDirection", null);
454         notValidData.put("setRxDirection", null);
455         for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
456                 .ServiceZEndBuilder.class.getDeclaredMethods()) {
457             if (notValidData.containsKey(method.getName())) {
458                 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
459                         .buildServiceCreateInput());
460                 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
461                     .ServiceZEndBuilder serviceZEndBuilder = ServiceDataUtils.getServiceZEndBuild();
462                 method.invoke(serviceZEndBuilder, notValidData.get(method.getName()));
463                 ServiceCreateOutput result = this.serviceHandler
464                         .serviceCreate(buildInput.setServiceZEnd(serviceZEndBuilder.build()).build()).get().getResult();
465                 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
466                         ResponseCodes.FINAL_ACK_YES);
467                 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
468                         ResponseCodes.RESPONSE_FAILED);
469             }
470         }
471     }
472
473     @Test
474     public void createServiceHandlerNotValidTxDirectionPort()
475             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
476         List<String> invalidData = Arrays.asList(null, "");
477         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
478         for (Method method : PortBuilder.class.getMethods()) {
479             if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
480                 for (Object data : invalidData) {
481                     PortBuilder portBuilder = new PortBuilder(
482                             serviceCreateInput.getServiceAEnd().getTxDirection().getPort());
483                     method.invoke(portBuilder, data);
484                     ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(portBuilder.build(),
485                             serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
486                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
487                             ResponseCodes.FINAL_ACK_YES);
488                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
489                             ResponseCodes.RESPONSE_FAILED);
490                 }
491             }
492         }
493     }
494
495     @Test
496     public void createServiceHandlerTxDirectionPortIsNull() throws ExecutionException, InterruptedException {
497         ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(null,
498             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getLgx());
499         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
500                 ResponseCodes.FINAL_ACK_YES);
501         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
502     }
503
504     @Test
505     public void createServiceHandlerNotValidTxDirectionLgx()
506             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
507         List<String> invalidData = Arrays.asList(null, "");
508         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
509         for (Method method : LgxBuilder.class.getMethods()) {
510             if (method.getName().startsWith("set")) {
511                 for (Object data : invalidData) {
512                     LgxBuilder lgxBuilder = new LgxBuilder(
513                             serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
514                     method.invoke(lgxBuilder, data);
515                     ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
516                             serviceCreateInput.getServiceAEnd().getTxDirection().getPort(), lgxBuilder.build());
517                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
518                             ResponseCodes.FINAL_ACK_YES);
519                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
520                             ResponseCodes.RESPONSE_FAILED);
521                 }
522             }
523         }
524     }
525
526     @Test
527     public void createServiceHandlerTxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
528         ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
529             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getPort(), null);
530         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
531                 ResponseCodes.FINAL_ACK_YES);
532         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
533     }
534
535     private ServiceCreateOutput getTxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
536             throws InterruptedException, ExecutionException {
537         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
538         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
539             .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
540         TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder(
541                 serviceCreateInput.getServiceAEnd().getTxDirection());
542         txDirectionBuilder.setPort(port);
543         txDirectionBuilder.setLgx(lgx);
544         serviceAEndBuilder.setTxDirection(txDirectionBuilder.build());
545         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
546         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null);
547         return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
548                 .getResult();
549     }
550
551     @Test
552     public void createServiceHandlerNotValidRxDirectionPort()
553             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
554         List<String> invalidData = Arrays.asList(null, "");
555         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
556         for (Method method : PortBuilder.class.getMethods()) {
557             if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
558                 for (Object data : invalidData) {
559                     PortBuilder portBuilder = new PortBuilder(
560                             serviceCreateInput.getServiceAEnd().getRxDirection().getPort());
561                     method.invoke(portBuilder, data);
562                     ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(portBuilder.build(),
563                             serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
564                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
565                             ResponseCodes.FINAL_ACK_YES);
566                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
567                             ResponseCodes.RESPONSE_FAILED);
568                 }
569             }
570         }
571     }
572
573     @Test
574     public void createServiceHandlerRxDirectionPortIsNull()
575             throws ExecutionException, InterruptedException {
576         ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(null,
577             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getLgx());
578         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
579                 ResponseCodes.FINAL_ACK_YES);
580         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
581     }
582
583     @Test
584     public void createServiceHandlerNotValidRxDirectionLgx()
585             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
586         List<String> invalidData = Arrays.asList(null, "");
587         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
588         for (Method method : LgxBuilder.class.getMethods()) {
589             if (method.getName().startsWith("set")) {
590                 for (Object data : invalidData) {
591                     LgxBuilder lgxBuilder = new LgxBuilder(
592                             serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
593                     method.invoke(lgxBuilder, data);
594                     ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
595                             serviceCreateInput.getServiceAEnd().getRxDirection().getPort(), lgxBuilder.build());
596                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
597                             ResponseCodes.FINAL_ACK_YES);
598                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
599                             ResponseCodes.RESPONSE_FAILED);
600                 }
601             }
602         }
603     }
604
605     @Test
606     public void createServiceHandlerRxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
607         ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
608             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getPort(), null);
609         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
610                 ResponseCodes.FINAL_ACK_YES);
611         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
612     }
613
614     @Test
615     public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException {
616         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
617
618         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
619                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
620                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failed").build();
621         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
622                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
623                         .setConfigurationResponseCommon(configurationResponseCommon).build();
624         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
625                 .thenReturn(pathComputationRequestOutput);
626         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
627         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
628                 ResponseCodes.FINAL_ACK_YES);
629         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
630         verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true);
631     }
632
633     @Test
634     public void createServiceHandlerOperationResultNotPassed() throws ExecutionException, InterruptedException {
635         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
636         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
637                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
638                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
639         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
640                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
641                         .setConfigurationResponseCommon(configurationResponseCommon).build();
642         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
643                 .thenReturn(pathComputationRequestOutput);
644         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
645                 any(PathComputationRequestOutput.class)))
646                 .thenReturn(OperationResult.failed(
647                         "Failed to create service " + serviceCreateInput.getServiceName() + " to Service List"));
648         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
649         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
650                 ResponseCodes.FINAL_ACK_YES);
651         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
652         verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class),
653                 any(PathComputationRequestOutput.class));
654     }
655
656     @Test
657     public void createServiceHandlerOperationServicePathSaveResultNotPassed()
658             throws ExecutionException, InterruptedException {
659         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
660         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
661                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
662                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
663         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
664                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
665                         .setConfigurationResponseCommon(configurationResponseCommon).build();
666         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
667                 .thenReturn(pathComputationRequestOutput);
668         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
669                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
670         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
671                 any(PathComputationRequestOutput.class)))
672                 .thenReturn(OperationResult.failed("Failed to create servicePath " + serviceCreateInput.getServiceName()
673                         + " to ServicePath List"));
674         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
675         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
676                 ResponseCodes.FINAL_ACK_YES);
677         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
678         verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class),
679                 any(PathComputationRequestOutput.class));
680     }
681
682     @Test
683     public void createServiceHandlerModifyServicePassed() throws ExecutionException, InterruptedException {
684         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
685         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
686                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
687                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
688         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
689                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
690                         .setConfigurationResponseCommon(configurationResponseCommon).build();
691         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
692                 .thenReturn(pathComputationRequestOutput);
693         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
694                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
695         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
696                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
697         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
698                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
699                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
700         Mockito.when(
701                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
702                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
703                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
704         Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
705                 State.InService, State.InService)).thenReturn(OperationResult.ok("successful"));
706         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
707         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
708                 ResponseCodes.FINAL_ACK_YES);
709         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
710         verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
711                 State.InService);
712     }
713
714     @Test
715     public void createServiceHandlerModifyServiceNotPassed() throws ExecutionException, InterruptedException {
716         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
717         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
718                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
719                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
720         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
721                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
722                         .setConfigurationResponseCommon(configurationResponseCommon).build();
723         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
724                 .thenReturn(pathComputationRequestOutput);
725         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
726                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
727         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
728                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
729         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
730                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
731                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
732         Mockito.when(
733                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
734                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
735                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
736         Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
737                 State.InService, State.InService)).thenReturn(OperationResult.failed("failure"));
738         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
739         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
740                 ResponseCodes.FINAL_ACK_YES);
741         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
742         verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
743                 State.InService);
744     }
745
746     @Test
747     public void createServiceHandlerServiceImplementationNotPassed() throws ExecutionException, InterruptedException {
748         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
749         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
750                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
751                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
752         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
753                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
754                         .setConfigurationResponseCommon(configurationResponseCommon).build();
755         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
756                 .thenReturn(pathComputationRequestOutput);
757         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
758                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
759         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
760                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
761         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
762                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
763                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
764         Mockito.when(
765                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
766                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
767                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
768         Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
769                 .thenReturn(OperationResult.ok("successful"));
770         Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
771                 .thenReturn(OperationResult.ok("successful"));
772         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
773         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
774                 ResponseCodes.FINAL_ACK_YES);
775         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
776         verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
777         verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
778     }
779
780     @Test
781     public void createServiceHandlerServiceImplementationNotPassed2() throws ExecutionException, InterruptedException {
782         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
783         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
784                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
785                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
786         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
787                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
788                         .setConfigurationResponseCommon(configurationResponseCommon).build();
789         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
790                 .thenReturn(pathComputationRequestOutput);
791         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
792                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
793         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
794                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
795         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
796                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
797                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
798         Mockito.when(
799                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
800                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
801                         .setConfigurationResponseCommon(configurationResponseCommon2).build()));
802         Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
803                 .thenReturn(OperationResult.failed("successful"));
804         Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
805                 .thenReturn(OperationResult.failed("successful"));
806         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
807         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
808                 ResponseCodes.FINAL_ACK_YES);
809         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
810         verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
811         verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
812     }
813
814     private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
815             throws InterruptedException, ExecutionException {
816         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
817         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
818             .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
819         RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder(
820                 serviceCreateInput.getServiceAEnd().getRxDirection());
821         rxDirectionBuilder.setPort(port);
822         rxDirectionBuilder.setLgx(lgx);
823         serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build());
824         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
825         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null);
826         return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
827                 .getResult();
828     }
829
830     @Test
831     public void deleteServiceInvalidIfServiceNameIsEmpty() throws ExecutionException, InterruptedException {
832
833         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
834         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
835         serviceDeleteInput = builder
836                 .setServiceDeleteReqInfo(
837                         new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName("").build())
838                 .build();
839         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
840         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
841                 ResponseCodes.FINAL_ACK_YES);
842         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
843     }
844
845     @Test
846     public void deleteServiceInvalidIfServiceNameIsNull() throws ExecutionException, InterruptedException {
847
848         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
849         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
850         serviceDeleteInput = builder
851                 .setServiceDeleteReqInfo(
852                         new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName(null).build())
853                 .build();
854         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
855         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
856                 ResponseCodes.FINAL_ACK_YES);
857         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
858     }
859
860     @Test
861     public void deleteTempServiceInvalidIfCommonIdIsEmpty() throws ExecutionException, InterruptedException {
862         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
863         TempServiceDeleteInputBuilder builder = new TempServiceDeleteInputBuilder(serviceDeleteInput);
864         serviceDeleteInput = builder.setCommonId("").build();
865         TempServiceDeleteOutput result = this.serviceHandler.tempServiceDelete(serviceDeleteInput).get().getResult();
866         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
867                 ResponseCodes.FINAL_ACK_YES);
868         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
869     }
870
871     @Test
872     public void deleteTempServiceInvalidIfCommonIdIsNull() throws ExecutionException, InterruptedException {
873         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
874         TempServiceDeleteInputBuilder builder = new TempServiceDeleteInputBuilder(serviceDeleteInput);
875         serviceDeleteInput = builder.setCommonId(null).build();
876         TempServiceDeleteOutput result = this.serviceHandler.tempServiceDelete(serviceDeleteInput).get().getResult();
877         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
878                 ResponseCodes.FINAL_ACK_YES);
879         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
880     }
881
882     @Test
883     public void deleteServiceInvalidIfSdncRequestHeaderIsNull() throws ExecutionException, InterruptedException {
884         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
885         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
886         serviceDeleteInput = builder.setSdncRequestHeader(null).build();
887         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
888         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
889                 ResponseCodes.FINAL_ACK_YES);
890         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
891     }
892
893     @Test
894     public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsNull()
895             throws ExecutionException, InterruptedException {
896
897         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
898         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
899         serviceDeleteInput = builder
900                 .setSdncRequestHeader(
901                         new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId(null).build())
902                 .build();
903         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
904         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
905                 ResponseCodes.FINAL_ACK_YES);
906         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
907     }
908
909     @Test
910     public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsEmpty()
911             throws ExecutionException, InterruptedException {
912
913         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
914         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
915         serviceDeleteInput = builder.setSdncRequestHeader(
916                 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId("").build()).build();
917         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
918         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
919                 ResponseCodes.FINAL_ACK_YES);
920         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
921     }
922
923     @Test
924     public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNull()
925             throws ExecutionException, InterruptedException {
926
927         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
928         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
929         serviceDeleteInput = builder
930                 .setSdncRequestHeader(
931                         new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRpcAction(null).build())
932                 .build();
933         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
934         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
935                 ResponseCodes.FINAL_ACK_YES);
936         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
937     }
938
939     @Test
940     public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNotDelete()
941             throws ExecutionException, InterruptedException {
942
943         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
944         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
945         serviceDeleteInput = builder.setSdncRequestHeader(new SdncRequestHeaderBuilder(builder.getSdncRequestHeader())
946                 .setRpcAction(RpcActions.ServiceCreate).build()).build();
947         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
948         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
949                 ResponseCodes.FINAL_ACK_YES);
950         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
951     }
952
953     @Test
954     public void deleteServiceIfServiceHandlerCompliancyCheckNotPassed()
955             throws ExecutionException, InterruptedException {
956
957         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
958
959         Mockito.when(this.complianceCheckResultMock.hasPassed()).thenReturn(false);
960
961         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
962         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
963                 ResponseCodes.FINAL_ACK_YES);
964         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
965     }
966
967     @Test
968     public void deleteServiceNotPresent() throws ExecutionException, InterruptedException {
969
970         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(ServiceDataUtils.buildServiceDeleteInput()).get()
971                 .getResult();
972         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
973                 ResponseCodes.FINAL_ACK_YES);
974         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
975     }
976
977     @Test
978     public void deleteServiceIfServiceNotPresent() throws ExecutionException, InterruptedException {
979
980         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
981         Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
982         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
983         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
984                 ResponseCodes.FINAL_ACK_YES);
985         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
986     }
987
988     @Test
989     public void deleteTempServiceIfTempServiceNotPresent() throws ExecutionException, InterruptedException {
990         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
991         Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
992         TempServiceDeleteOutput result =
993                 this.serviceHandlerImplMock.tempServiceDelete(serviceDeleteInput).get().getResult();
994         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
995                 ResponseCodes.FINAL_ACK_YES);
996         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
997     }
998
999     @Test
1000     public void deleteServiceNotPassed() throws ExecutionException, InterruptedException {
1001
1002         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
1003         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1004         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1005         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1006             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
1007                     new ServiceInput(serviceDeleteInput));
1008         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1009                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1010                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("success").build();
1011         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1012             .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
1013                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1014         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1015         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1016         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1017                 ResponseCodes.FINAL_ACK_YES);
1018         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
1019     }
1020
1021     @Test
1022     public void deleteServicePathNotPassed() throws ExecutionException, InterruptedException {
1023
1024         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
1025         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1026         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1027         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1028             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
1029                     new ServiceInput(serviceDeleteInput));
1030         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1031                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1032                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1033         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1034             .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
1035                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1036         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1037         Mockito.when(this.serviceDataStoreOperationsMock
1038                 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1039                 .thenReturn(OperationResult.failed("failed"));
1040         Mockito.when(this.serviceDataStoreOperationsMock
1041                 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1042                 .thenReturn(OperationResult.failed("failed"));
1043         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1044         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1045                 ResponseCodes.FINAL_ACK_YES);
1046         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1047     }
1048
1049     @Test
1050     public void deleteServiceOperationNotPassed() throws ExecutionException, InterruptedException {
1051
1052         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
1053         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1054         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1055         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1056             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
1057                     new ServiceInput(serviceDeleteInput));
1058         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1059                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1060                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1061         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1062             .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
1063                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1064         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1065         Mockito.when(this.serviceDataStoreOperationsMock
1066                 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1067                 .thenReturn(OperationResult.ok("success"));
1068         Mockito.when(this.serviceDataStoreOperationsMock
1069                 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1070                 .thenReturn(OperationResult.ok("success"));
1071         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1072         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1073                 ResponseCodes.FINAL_ACK_YES);
1074         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1075     }
1076
1077     @Test
1078     public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException {
1079
1080         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
1081         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1082         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1083         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1084             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
1085                     new ServiceInput(serviceDeleteInput));
1086         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1087                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1088                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1089         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1090             .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
1091                 .rev171017.ServiceDeleteOutputBuilder()
1092                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1093         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1094         Mockito.when(this.serviceDataStoreOperationsMock
1095                 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1096                 .thenReturn(OperationResult.ok("success"));
1097         Mockito.when(this.serviceDataStoreOperationsMock
1098                 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1099                 .thenReturn(OperationResult.ok("success"));
1100         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1101         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1102                 ResponseCodes.FINAL_ACK_YES);
1103         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1104     }
1105
1106     @Test
1107     public void deleteTempServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException {
1108
1109         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
1110         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
1111             .Services> service = Optional.of(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014
1112                     .temp.service.list.ServicesBuilder().setCommonId("service 1").build());
1113         Mockito.when(this.serviceDataStoreOperationsMock.getTempService("service 1")).thenReturn(service);
1114         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1115             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
1116                     new ServiceInput(serviceDeleteInput));
1117         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1118                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1119                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1120         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1121             .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
1122                 .rev171017.ServiceDeleteOutputBuilder()
1123                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1124         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1125         Mockito.when(this.serviceDataStoreOperationsMock
1126                 .deleteServicePath(serviceDeleteInput.getCommonId()))
1127                 .thenReturn(OperationResult.ok("success"));
1128         Mockito.when(this.serviceDataStoreOperationsMock
1129                 .deleteTempService(serviceDeleteInput.getCommonId()))
1130                 .thenReturn(OperationResult.ok("success"));
1131         TempServiceDeleteOutput result = this.serviceHandlerImplMock.tempServiceDelete(serviceDeleteInput).get()
1132                 .getResult();
1133         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1134                 ResponseCodes.FINAL_ACK_YES);
1135         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1136     }
1137
1138     @Test
1139     public void rerouteServiceIsNotPresent() throws ExecutionException, InterruptedException {
1140
1141         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
1142         ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult();
1143         Assert.assertEquals(result.getStatus(), RpcStatus.Failed);
1144         Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present");
1145
1146     }
1147
1148     @Test
1149     public void rerouteServiceIfserviceIsPresent() throws ExecutionException, InterruptedException {
1150
1151         ServiceRerouteInput serviceRerouteinput = ServiceDataUtils.buildServiceRerouteInput();
1152         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
1153         ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput();
1154
1155         /** Mock RPC service-delete. */
1156         Services serviceMock = ModelMappingUtils.mappingServices(serviceInput, null);
1157         Optional<Services> service = Optional.of(serviceMock);
1158         Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service);
1159         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1160             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, service.get());
1161         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1162                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1163                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1164         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
1165             .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
1166                 .rev171017.ServiceDeleteOutputBuilder()
1167                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1168         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output));
1169         Mockito.when(this.serviceDataStoreOperationsMock
1170                 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1171                 .thenReturn(OperationResult.ok("success"));
1172         Mockito.when(this.serviceDataStoreOperationsMock
1173                 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1174                 .thenReturn(OperationResult.ok("success"));
1175
1176         ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
1177                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1178                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1179         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
1180                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
1181                         .setConfigurationResponseCommon(configurationResponseCommon2).build();
1182
1183         /** Mock RPC service-create. */
1184         Mockito.when(this.pceServiceWrapperMock.performPCE(any(ServiceCreateInput.class), any(Boolean.class)))
1185             .thenReturn(pathComputationRequestOutput);
1186         Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
1187                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
1188         Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class),
1189                 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
1190         ConfigurationResponseCommon configurationResponseCommon3 = new ConfigurationResponseCommonBuilder()
1191                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1192                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
1193         Mockito.when(
1194                 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
1195                 .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder()
1196                         .setConfigurationResponseCommon(configurationResponseCommon3).build()));
1197         Mockito.when(this.serviceDataStoreOperationsMock.modifyService(any(String.class), any(State.class),
1198                 any(State.class))).thenReturn(OperationResult.ok("successful"));
1199
1200         ServiceRerouteOutput result = this.serviceHandlerImplMock.serviceReroute(serviceRerouteinput).get().getResult();
1201         Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful,
1202                 result.getStatus());
1203         Assert.assertEquals("Service reroute successfully !", result.getStatusMessage());
1204     }
1205 }