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