6c06e45c21ad222ba670b840c240480268b0d44c
[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
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
14
15 import java.lang.reflect.InvocationTargetException;
16 import java.lang.reflect.Method;
17 import java.util.Arrays;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Optional;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executors;
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.controller.md.sal.binding.api.NotificationService;
34 import org.opendaylight.transportpce.common.ResponseCodes;
35 import org.opendaylight.transportpce.pce.service.PathComputationService;
36 import org.opendaylight.transportpce.pce.utils.PceTestData;
37 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
38 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
39 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
40 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
41 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
42 import org.opendaylight.transportpce.servicehandler.ServiceInput;
43 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
44 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
45 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
46 import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper;
47 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
48 import org.opendaylight.transportpce.servicehandler.stub.StubPceServiceOperations;
49 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
50 import org.opendaylight.transportpce.servicehandler.utils.MockedNotificationServiceWrapper;
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.pce.rev171017.TransportpcePceListener;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener;
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.ServiceNotificationTypes;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInputBuilder;
88 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
89 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
90 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
91 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
92 import org.opendaylight.yangtools.concepts.ListenerRegistration;
93 import org.opendaylight.yangtools.yang.common.RpcResult;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
96
97 public class ServiceHandlerImplTest extends AbstractTest {
98
99     private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class);
100     private static final int NUMBER_OF_THREADS = 4;
101
102     private PathComputationService pathComputationService;
103     private RendererServiceOperations rendererServiceOperations;
104     private ServicehandlerImpl serviceHandler;
105     private PceListenerImpl pceListenerImpl;
106     private RendererListenerImpl rendererListenerImpl;
107     private ListeningExecutorService executor;
108     private NotificationPublishService notificationPublishService;
109     private NotificationService notificationService;
110     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
111     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
112     private MockedNotificationServiceWrapper mockedNotificationServiceWrapper;
113
114     @Mock
115     private ServiceDataStoreOperations serviceDataStoreOperationsMock;
116     @Mock
117     private PCEServiceWrapper pceServiceWrapperMock;
118     @Mock
119     private RendererServiceWrapper rendererServiceWrapperMock;
120     @Mock
121     private PathComputationService pathComputationServiceMock;
122     @Mock
123     private RendererServiceOperations rendererServiceOperationsMock;
124     @Mock
125     private ComplianceCheckResult complianceCheckResultMock;
126     @Mock
127     private Optional<Services> servicesOptionalMock;
128     @Mock
129     private PceListenerImpl pceListenerImplMock;
130     @Mock
131     private RendererListenerImpl rendererListenerImplMock;
132     @Mock
133     private NotificationPublishService notificationPublishServiceMock;
134     @Mock
135     private NetworkModelWavelengthService networkModelWavelengthServiceMock;
136     @InjectMocks
137     private ServicehandlerImpl serviceHandlerImplMock;
138
139     @Before
140     public void setUp() {
141         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService,
142                 this.rendererServiceOperations, this.notificationPublishService, this.pceListenerImpl,
143                 this.rendererListenerImpl, this.networkModelWavelengthServiceMock);
144         this.serviceHandlerImplMock =
145                 new ServicehandlerImpl(getDataBroker(), this.pathComputationService, this.rendererServiceOperations,
146                         notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
147         MockitoAnnotations.initMocks(this);
148     }
149
150     public ServiceHandlerImplTest() throws Exception {
151         this.mockedNotificationServiceWrapper = new MockedNotificationServiceWrapper(getNotificationPublishService());
152         this.notificationPublishService = this.mockedNotificationServiceWrapper.getMockedNotificationService();
153         this.notificationService = getNotificationService();
154         this.pathComputationService = new StubPceServiceOperations(notificationPublishService);
155         this.rendererServiceOperations = new StubRendererServiceOperations(this.networkModelWavelengthServiceMock,
156                 getDataBroker(), notificationPublishService);
157         PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
158                 "topologyData/NW-simple-topology.xml");
159         this.pceListenerImpl =
160                 new PceListenerImpl(rendererServiceOperations, pathComputationService, notificationPublishService,
161                         null);
162         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperationsMock);
163         this.pceListenerImpl.setServiceReconfigure(false);
164         this.rendererListenerImpl =
165                 new RendererListenerImpl(pathComputationServiceMock, notificationPublishService);
166         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperationsMock);
167         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
168         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
169         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
170     }
171
172
173
174     @Test
175     public void testCreateServiceValid() throws ExecutionException, InterruptedException {
176         ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput();
177         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
178                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
179                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
180         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
181                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
182                         .setConfigurationResponseCommon(configurationResponseCommon).build();
183         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true))
184             .thenReturn(pathComputationRequestOutput);
185         Future<RpcResult<ServiceCreateOutput>> output0 = this.serviceHandlerImplMock.serviceCreate(serviceInput);
186         Assert.assertNotNull(output0);
187         Assert.assertTrue(output0.get().isSuccessful());
188         Assert.assertEquals(output0.get().getResult(), ModelMappingUtils.createCreateServiceReply(serviceInput,
189                 ResponseCodes.FINAL_ACK_NO,"PCE calculation in progress", ResponseCodes.RESPONSE_OK)
190                         .get().getResult());
191         Assert.assertEquals(0, output0.get().getErrors().size());
192     }
193
194     @Test
195     public void createServiceHandlerInvalidIfNameIsEmpty() throws ExecutionException, InterruptedException {
196         ServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
197         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyServiceNameInput);
198         emptyServiceNameInput = builtInput.setServiceName("").build();
199         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceNameInput).get().getResult(),
200                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
201                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
202                         .getResult());
203     }
204
205     @Test
206     public void createServiceHandlerInvalidIfNameIsNull() throws ExecutionException, InterruptedException {
207         ServiceCreateInput nullServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
208         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(nullServiceNameInput);
209         nullServiceNameInput = builtInput.setServiceName(null).build();
210         Assert.assertEquals(this.serviceHandler.serviceCreate(nullServiceNameInput).get().getResult(),
211                 ModelMappingUtils.createCreateServiceReply(nullServiceNameInput, ResponseCodes.FINAL_ACK_YES,
212                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
213                         .getResult());
214     }
215
216     @Test
217     public void createTempServiceHandlerInvalidIfCommonIdIsEmpty() throws ExecutionException, InterruptedException {
218         TempServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildTempServiceCreateInput();
219         TempServiceCreateInputBuilder builtInput = new TempServiceCreateInputBuilder(emptyServiceNameInput);
220         emptyServiceNameInput = builtInput.setCommonId("").build();
221         Assert.assertEquals(this.serviceHandler.tempServiceCreate(emptyServiceNameInput).get().getResult(),
222                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
223                         "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED).get()
224                         .getResult());
225     }
226
227     @Test
228     public void createTempServiceHandlerInvalidIfCommonIdIsNull() throws ExecutionException, InterruptedException {
229         TempServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildTempServiceCreateInput();
230         TempServiceCreateInputBuilder builtInput = new TempServiceCreateInputBuilder(emptyServiceNameInput);
231         emptyServiceNameInput = builtInput.setCommonId(null).build();
232         Assert.assertEquals(this.serviceHandler.tempServiceCreate(emptyServiceNameInput).get().getResult(),
233                 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
234                                 "Service Name (common-id for Temp service) is not set", ResponseCodes.RESPONSE_FAILED)
235                         .get().getResult());
236     }
237
238     @Test
239     public void createServiceHnadlerInvalidIfConTypeIsEmpty() throws ExecutionException, InterruptedException {
240         ServiceCreateInput emptyConTypeInput = ServiceDataUtils.buildServiceCreateInput();
241         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyConTypeInput);
242         emptyConTypeInput = builtInput.setConnectionType(null).build();
243         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyConTypeInput).get().getResult(),
244                 ModelMappingUtils.createCreateServiceReply(emptyConTypeInput, ResponseCodes.FINAL_ACK_YES,
245                         "Service ConnectionType is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
246     }
247
248     @Test
249     public void createServiceHandlerInvalidIfSdncRequestHeaderNull() throws ExecutionException, InterruptedException {
250         ServiceCreateInput emptySdncRequestHeader = ServiceDataUtils.buildServiceCreateInput();
251         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptySdncRequestHeader);
252         emptySdncRequestHeader = buildInput.setSdncRequestHeader(null).build();
253         ServiceCreateOutput result = this.serviceHandler.serviceCreate(emptySdncRequestHeader).get().getResult();
254         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
255         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
256                 ResponseCodes.FINAL_ACK_YES);
257     }
258
259     @Test
260     public void createServiceHandlerInvalidIfRequestIdEmpty() throws ExecutionException, InterruptedException {
261         ServiceCreateInput emptyRequestId = ServiceDataUtils.buildServiceCreateInput();
262         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyRequestId);
263         emptyRequestId = buildInput
264                 .setSdncRequestHeader(
265                         new SdncRequestHeaderBuilder(emptyRequestId.getSdncRequestHeader()).setRequestId("").build())
266                 .build();
267         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyRequestId).get().getResult(),
268                 ModelMappingUtils
269                         .createCreateServiceReply(emptyRequestId, ResponseCodes.FINAL_ACK_YES,
270                                 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
271                         .get().getResult());
272     }
273
274     @Test
275     public void createServiceHandlerInvalidIfRequestIdNull() throws ExecutionException, InterruptedException {
276         ServiceCreateInput nullRequestId = ServiceDataUtils.buildServiceCreateInput();
277         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(nullRequestId);
278         nullRequestId = buildInput
279                 .setSdncRequestHeader(
280                         new SdncRequestHeaderBuilder(nullRequestId.getSdncRequestHeader()).setRequestId(null).build())
281                 .build();
282         Assert.assertEquals(this.serviceHandler.serviceCreate(nullRequestId).get().getResult(),
283                 ModelMappingUtils
284                         .createCreateServiceReply(nullRequestId, ResponseCodes.FINAL_ACK_YES,
285                                 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
286                         .get().getResult());
287     }
288
289     @Test
290     public void serviceHandlerInvalidServiceActionIsNull() throws ExecutionException, InterruptedException {
291         ServiceCreateInput emptyServiceAction = ServiceDataUtils.buildServiceCreateInput();
292         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyServiceAction);
293         emptyServiceAction = buildInput.setSdncRequestHeader(
294                 new SdncRequestHeaderBuilder(emptyServiceAction.getSdncRequestHeader()).setRpcAction(null).build())
295                 .build();
296         Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceAction).get().getResult(),
297                 ModelMappingUtils
298                         .createCreateServiceReply(emptyServiceAction, ResponseCodes.FINAL_ACK_YES,
299                                 "Service sndc-request-header 'rpc-action' is not set ", ResponseCodes.RESPONSE_FAILED)
300                         .get().getResult());
301     }
302
303     @Test
304     public void serviceHandlerInvalidServiceActionIsNotCreate() throws ExecutionException, InterruptedException {
305         ServiceCreateInput notCreateServiceAction = ServiceDataUtils.buildServiceCreateInput();
306         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notCreateServiceAction);
307         notCreateServiceAction = buildInput
308                 .setSdncRequestHeader(new SdncRequestHeaderBuilder(notCreateServiceAction.getSdncRequestHeader())
309                         .setRpcAction(RpcActions.ServiceFeasibilityCheck).build())
310                 .build();
311         Assert.assertEquals(this.serviceHandler.serviceCreate(notCreateServiceAction).get().getResult(),
312                 ModelMappingUtils.createCreateServiceReply(notCreateServiceAction, ResponseCodes.FINAL_ACK_YES,
313                         "Service sdncRequestHeader rpc-action '"
314                                 + notCreateServiceAction.getSdncRequestHeader().getRpcAction() + "' not equal to '"
315                                 + RpcActions.ServiceCreate.name() + "'",
316                         ResponseCodes.RESPONSE_FAILED).get().getResult());
317     }
318
319     @Test
320     public void createServiceHandlerNotValidServiceAEndIsNull() throws ExecutionException, InterruptedException {
321         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
322         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
323         notValidServiceAEnd = buildInput.setServiceAEnd(null).build();
324         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
325                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
326                         "SERVICEAEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
327     }
328
329     @Test
330     public void createServiceHandlerNotValidServiceZEndIsNull() throws ExecutionException, InterruptedException {
331         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
332         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
333         notValidServiceAEnd = buildInput.setServiceZEnd(null).build();
334         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
335                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
336                         "SERVICEZEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
337     }
338
339     @Test
340     public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException {
341         ServicehandlerImpl servicehandler =
342                 new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, null, null);
343         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
344         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
345         notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setServiceRate(null)
346                 .build()).build();
347         Assert.assertEquals(servicehandler.serviceCreate(notValidServiceAEnd).get().getResult(),
348                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
349                         "Service " + ServiceEndpointType.SERVICEAEND + " rate is not set",
350                         ResponseCodes.RESPONSE_FAILED).get().getResult());
351     }
352
353     @Test
354     public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException {
355         ServicehandlerImpl servicehandler =
356                 new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, null, null);
357         ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
358         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
359         notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setServiceRate(null)
360                 .build()).build();
361         Assert.assertEquals(servicehandler.serviceCreate(notValidServiceZEnd).get().getResult(),
362                 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
363                         "Service " + ServiceEndpointType.SERVICEZEND + " rate is not set",
364                         ResponseCodes.RESPONSE_FAILED).get().getResult());
365     }
366
367     @Test
368     public void createServiceHandlerNotValidServiceAEndClliIsNull()
369             throws ExecutionException, InterruptedException {
370         ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
371         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
372         notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setClli(null)
373                 .build()).build();
374         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
375                 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
376                         "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set",
377                         ResponseCodes.RESPONSE_FAILED).get().getResult());
378     }
379
380     @Test
381     public void createServiceHandlerNotValidServiceZEndClliIsNull()
382             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
383         ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
384         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
385         notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setClli(null).build())
386                 .build();
387         Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceZEnd).get().getResult(),
388                 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
389                         "Service" + ServiceEndpointType.SERVICEZEND + " clli format is not set",
390                         ResponseCodes.RESPONSE_FAILED).get().getResult());
391     }
392
393     @Test
394     public void createServiceHandlerNotValidServiceAEndAttributes()
395             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
396         HashMap<String, Object> notValidData = new HashMap<>();
397         notValidData.put("setServiceRate", 0L);
398         notValidData.put("setServiceFormat", null);
399         notValidData.put("setClli", "");
400         notValidData.put("setTxDirection", null);
401         notValidData.put("setRxDirection", null);
402         for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
403                 .ServiceAEndBuilder.class.getDeclaredMethods()) {
404             if (notValidData.containsKey(method.getName())) {
405                 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
406                         .buildServiceCreateInput());
407                 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
408                     .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
409                 method.invoke(serviceAEndBuilder, notValidData.get(method.getName()));
410                 ServiceCreateOutput result = this.serviceHandler
411                         .serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get().getResult();
412                 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
413                         ResponseCodes.FINAL_ACK_YES);
414                 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
415                         ResponseCodes.RESPONSE_FAILED);
416             }
417         }
418     }
419
420     @Test
421     public void createServiceHandlerNotValidServiceZEndAttributes()
422             throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
423         HashMap<String, Object> notValidData = new HashMap<>();
424         notValidData.put("setServiceRate", 0L);
425         notValidData.put("setServiceFormat", null);
426         notValidData.put("setClli", "");
427         notValidData.put("setTxDirection", null);
428         notValidData.put("setRxDirection", null);
429         for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
430                 .ServiceZEndBuilder.class.getDeclaredMethods()) {
431             if (notValidData.containsKey(method.getName())) {
432                 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
433                         .buildServiceCreateInput());
434                 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
435                     .ServiceZEndBuilder serviceZEndBuilder = ServiceDataUtils.getServiceZEndBuild();
436                 method.invoke(serviceZEndBuilder, notValidData.get(method.getName()));
437                 ServiceCreateOutput result = this.serviceHandler
438                         .serviceCreate(buildInput.setServiceZEnd(serviceZEndBuilder.build()).build()).get().getResult();
439                 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
440                         ResponseCodes.FINAL_ACK_YES);
441                 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
442                         ResponseCodes.RESPONSE_FAILED);
443             }
444         }
445     }
446
447     @Test
448     public void createServiceHandlerNotValidTxDirectionPort()
449             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
450         List<String> invalidData = Arrays.asList(null, "");
451         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
452         for (Method method : PortBuilder.class.getMethods()) {
453             if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
454                 for (Object data : invalidData) {
455                     PortBuilder portBuilder = new PortBuilder(
456                             serviceCreateInput.getServiceAEnd().getTxDirection().getPort());
457                     method.invoke(portBuilder, data);
458                     ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(portBuilder.build(),
459                             serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
460                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
461                             ResponseCodes.FINAL_ACK_YES);
462                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
463                             ResponseCodes.RESPONSE_FAILED);
464                 }
465             }
466         }
467     }
468
469     @Test
470     public void createServiceHandlerTxDirectionPortIsNull() throws ExecutionException, InterruptedException {
471         ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(null,
472             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getLgx());
473         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
474                 ResponseCodes.FINAL_ACK_YES);
475         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
476     }
477
478     @Test
479     public void createServiceHandlerNotValidTxDirectionLgx()
480             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
481         List<String> invalidData = Arrays.asList(null, "");
482         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
483         for (Method method : LgxBuilder.class.getMethods()) {
484             if (method.getName().startsWith("set")) {
485                 for (Object data : invalidData) {
486                     LgxBuilder lgxBuilder = new LgxBuilder(
487                             serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
488                     method.invoke(lgxBuilder, data);
489                     ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
490                             serviceCreateInput.getServiceAEnd().getTxDirection().getPort(), lgxBuilder.build());
491                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
492                             ResponseCodes.FINAL_ACK_YES);
493                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
494                             ResponseCodes.RESPONSE_FAILED);
495                 }
496             }
497         }
498     }
499
500     @Test
501     public void createServiceHandlerTxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
502         ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
503             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getPort(), null);
504         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
505                 ResponseCodes.FINAL_ACK_YES);
506         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
507     }
508
509     private ServiceCreateOutput getTxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
510             throws InterruptedException, ExecutionException {
511         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
512         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
513             .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
514         TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder(
515                 serviceCreateInput.getServiceAEnd().getTxDirection());
516         txDirectionBuilder.setPort(port);
517         txDirectionBuilder.setLgx(lgx);
518         serviceAEndBuilder.setTxDirection(txDirectionBuilder.build());
519         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
520         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null,
521                 null, null);
522         return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
523                 .getResult();
524     }
525
526     @Test
527     public void createServiceHandlerNotValidRxDirectionPort()
528             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
529         List<String> invalidData = Arrays.asList(null, "");
530         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
531         for (Method method : PortBuilder.class.getMethods()) {
532             if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
533                 for (Object data : invalidData) {
534                     PortBuilder portBuilder = new PortBuilder(
535                             serviceCreateInput.getServiceAEnd().getRxDirection().getPort());
536                     method.invoke(portBuilder, data);
537                     ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(portBuilder.build(),
538                             serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
539                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
540                             ResponseCodes.FINAL_ACK_YES);
541                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
542                             ResponseCodes.RESPONSE_FAILED);
543                 }
544             }
545         }
546     }
547
548     @Test
549     public void createServiceHandlerRxDirectionPortIsNull()
550             throws ExecutionException, InterruptedException {
551         ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(null,
552             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getLgx());
553         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
554                 ResponseCodes.FINAL_ACK_YES);
555         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
556     }
557
558     @Test
559     public void createServiceHandlerNotValidRxDirectionLgx()
560             throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
561         List<String> invalidData = Arrays.asList(null, "");
562         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
563         for (Method method : LgxBuilder.class.getMethods()) {
564             if (method.getName().startsWith("set")) {
565                 for (Object data : invalidData) {
566                     LgxBuilder lgxBuilder = new LgxBuilder(
567                             serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
568                     method.invoke(lgxBuilder, data);
569                     ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
570                             serviceCreateInput.getServiceAEnd().getRxDirection().getPort(), lgxBuilder.build());
571                     Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
572                             ResponseCodes.FINAL_ACK_YES);
573                     Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
574                             ResponseCodes.RESPONSE_FAILED);
575                 }
576             }
577         }
578     }
579
580     @Test
581     public void createServiceHandlerRxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
582         ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
583             ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getPort(), null);
584         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
585                 ResponseCodes.FINAL_ACK_YES);
586         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
587     }
588
589     @Test
590     public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException {
591         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
592         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
593                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
594                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("PCE calculation failed").build();
595         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
596                 PceTestData.getPCE_simpletopology_test1_result((long) 5))
597                         .setConfigurationResponseCommon(configurationResponseCommon).build();
598         Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
599                 .thenReturn(pathComputationRequestOutput);
600         ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
601         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
602     }
603
604     private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
605             throws InterruptedException, ExecutionException {
606         ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
607         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
608             .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
609         RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder(
610                 serviceCreateInput.getServiceAEnd().getRxDirection());
611         rxDirectionBuilder.setPort(port);
612         rxDirectionBuilder.setLgx(lgx);
613         serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build());
614         ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
615         this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null,
616                 null, null);
617         return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
618                 .getResult();
619     }
620
621     @Test
622     public void deleteServiceInvalidIfServiceNameIsEmpty() throws ExecutionException, InterruptedException {
623
624         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
625         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
626         serviceDeleteInput = builder
627                 .setServiceDeleteReqInfo(
628                         new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName("").build())
629                 .build();
630         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
631         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
632                 ResponseCodes.FINAL_ACK_YES);
633         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
634     }
635
636     @Test
637     public void deleteServiceInvalidIfServiceNameIsNull() throws ExecutionException, InterruptedException {
638
639         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
640         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
641         serviceDeleteInput = builder
642                 .setServiceDeleteReqInfo(
643                         new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName(null).build())
644                 .build();
645         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
646         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
647                 ResponseCodes.FINAL_ACK_YES);
648         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
649     }
650
651     @Test
652     public void deleteTempServiceInvalidIfCommonIdIsEmpty() throws ExecutionException, InterruptedException {
653         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
654         TempServiceDeleteInputBuilder builder = new TempServiceDeleteInputBuilder(serviceDeleteInput);
655         serviceDeleteInput = builder.setCommonId("").build();
656         TempServiceDeleteOutput result = this.serviceHandler.tempServiceDelete(serviceDeleteInput).get().getResult();
657         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
658                 ResponseCodes.FINAL_ACK_YES);
659         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
660     }
661
662     @Test
663     public void deleteTempServiceInvalidIfCommonIdIsNull() throws ExecutionException, InterruptedException {
664         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
665         TempServiceDeleteInputBuilder builder = new TempServiceDeleteInputBuilder(serviceDeleteInput);
666         serviceDeleteInput = builder.setCommonId(null).build();
667         TempServiceDeleteOutput result = this.serviceHandler.tempServiceDelete(serviceDeleteInput).get().getResult();
668         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
669                 ResponseCodes.FINAL_ACK_YES);
670         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
671     }
672
673     @Test
674     public void deleteServiceInvalidIfSdncRequestHeaderIsNull() throws ExecutionException, InterruptedException {
675         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
676         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
677         serviceDeleteInput = builder.setSdncRequestHeader(null).build();
678         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
679         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
680                 ResponseCodes.FINAL_ACK_YES);
681         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
682     }
683
684     @Test
685     public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsNull()
686             throws ExecutionException, InterruptedException {
687
688         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
689         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
690         serviceDeleteInput = builder
691                 .setSdncRequestHeader(
692                         new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId(null).build())
693                 .build();
694         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
695         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
696                 ResponseCodes.FINAL_ACK_YES);
697         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
698     }
699
700     @Test
701     public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsEmpty()
702             throws ExecutionException, InterruptedException {
703
704         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
705         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
706         serviceDeleteInput = builder.setSdncRequestHeader(
707                 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId("").build()).build();
708         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
709         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
710                 ResponseCodes.FINAL_ACK_YES);
711         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
712     }
713
714     @Test
715     public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNull()
716             throws ExecutionException, InterruptedException {
717
718         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
719         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
720         serviceDeleteInput = builder
721                 .setSdncRequestHeader(
722                         new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRpcAction(null).build())
723                 .build();
724         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
725         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
726                 ResponseCodes.FINAL_ACK_YES);
727         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
728     }
729
730     @Test
731     public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNotDelete()
732             throws ExecutionException, InterruptedException {
733
734         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
735         ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
736         serviceDeleteInput = builder.setSdncRequestHeader(new SdncRequestHeaderBuilder(builder.getSdncRequestHeader())
737                 .setRpcAction(RpcActions.ServiceCreate).build()).build();
738         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
739         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
740                 ResponseCodes.FINAL_ACK_YES);
741         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
742     }
743
744     @Test
745     public void deleteServiceIfServiceHandlerCompliancyCheckNotPassed()
746             throws ExecutionException, InterruptedException {
747
748         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
749
750         Mockito.when(this.complianceCheckResultMock.hasPassed()).thenReturn(false);
751
752         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
753         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
754                 ResponseCodes.FINAL_ACK_YES);
755         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
756     }
757
758     @Test
759     public void deleteServiceNotPresent() throws ExecutionException, InterruptedException {
760
761         ServiceDeleteOutput result = this.serviceHandler.serviceDelete(ServiceDataUtils.buildServiceDeleteInput()).get()
762                 .getResult();
763         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
764                 ResponseCodes.FINAL_ACK_YES);
765         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
766     }
767
768     @Test
769     public void deleteServiceIfServiceNotPresent() throws ExecutionException, InterruptedException {
770
771         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
772         Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
773         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
774         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
775                 ResponseCodes.FINAL_ACK_YES);
776         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
777     }
778
779     @Test
780     public void deleteTempServiceIfTempServiceNotPresent() throws ExecutionException, InterruptedException {
781         TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput();
782         Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
783         TempServiceDeleteOutput result =
784                 this.serviceHandlerImplMock.tempServiceDelete(serviceDeleteInput).get().getResult();
785         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
786                 ResponseCodes.FINAL_ACK_YES);
787         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
788     }
789
790     @Test
791     public void deleteServiceNotPassed() throws ExecutionException, InterruptedException {
792         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
793         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
794         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
795         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
796             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
797                     new ServiceInput(serviceDeleteInput));
798         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
799                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
800                 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("Renderer service delete failed !")
801                 .build();
802         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
803             .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
804                 .setConfigurationResponseCommon(configurationResponseCommon).build();
805         Mockito.when(this.rendererServiceWrapperMock.performRenderer(input,
806                 ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(output);
807         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
808         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
809                 ResponseCodes.FINAL_ACK_YES);
810         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
811     }
812
813     @Test
814     public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException {
815         ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
816         Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
817         Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
818         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
819             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(
820                     new ServiceInput(serviceDeleteInput));
821         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
822                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
823                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
824                 .build();
825         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
826             .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
827                 .rev171017.ServiceDeleteOutputBuilder()
828                 .setConfigurationResponseCommon(configurationResponseCommon).build();
829         Mockito.when(
830                 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult))
831                 .thenReturn(output);
832         ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
833         Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
834                 ResponseCodes.FINAL_ACK_NO);
835         Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
836     }
837
838     @Test
839     public void rerouteServiceIsNotPresent() throws ExecutionException, InterruptedException {
840         ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
841         ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult();
842         Assert.assertEquals(result.getStatus(), RpcStatus.Failed);
843         Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present");
844
845     }
846
847     @Test
848     public void rerouteServiceIfserviceIsPresent() throws ExecutionException, InterruptedException {
849         ServiceRerouteInput serviceRerouteinput = ServiceDataUtils.buildServiceRerouteInput();
850         ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput();
851         Services serviceMock = ModelMappingUtils.mappingServices(serviceInput, null);
852         Optional<Services> service = Optional.of(serviceMock);
853         Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service);
854         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
855             .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, service.get());
856         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
857                 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
858                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
859                 .build();
860         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
861             .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
862                 .rev171017.ServiceDeleteOutputBuilder()
863                 .setConfigurationResponseCommon(configurationResponseCommon).build();
864         Mockito.when(
865                 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult))
866                 .thenReturn(output);
867         ServiceRerouteOutput result = this.serviceHandlerImplMock.serviceReroute(serviceRerouteinput).get().getResult();
868         Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful,
869                 result.getStatus());
870         Assert.assertEquals("Renderer service delete in progress", result.getStatusMessage());
871     }
872
873     @Test
874     public void reConfigureServiceIfserviceNotPresent() throws ExecutionException, InterruptedException {
875         ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
876         ServiceReconfigureOutput result = this.serviceHandler.serviceReconfigure(input).get().getResult();
877         Assert.assertEquals(result.getStatus(), RpcStatus.Failed);
878         Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present");
879     }
880
881     @Test
882     public void reConfigureServiceIfserviceIsPresent() throws ExecutionException, InterruptedException {
883         ServiceReconfigureInput serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput();
884         Services serviceMock = ModelMappingUtils.mappingServices(null, serviceReconfigureInput);
885         Optional<Services> service = Optional.of(serviceMock);
886         Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service);
887         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput input =
888                 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
889         ConfigurationResponseCommon configurationResponseCommon =
890                 new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES)
891                         .setRequestId("1").setResponseCode(ResponseCodes.RESPONSE_OK)
892                         .setResponseMessage("Renderer service delete in progress").build();
893         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output =
894                 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
895                     .ServiceDeleteOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon).build();
896         Mockito.when(
897                 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult))
898                 .thenReturn(output);
899         ServiceReconfigureOutput result =
900                 this.serviceHandlerImplMock.serviceReconfigure(serviceReconfigureInput).get().getResult();
901         Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful,
902                 result.getStatus());
903         Assert.assertEquals("Renderer service delete in progress", result.getStatusMessage());
904     }
905
906     @Test
907     public void restorationServiceIfServiceNotPresent() throws ExecutionException, InterruptedException {
908         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
909         ServiceRestorationOutput result = this.serviceHandler.serviceRestoration(input).get().getResult();
910         Assert.assertEquals(result.getStatus(), RpcStatus.Failed);
911         Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present");
912     }
913
914     @Test
915     public void restorationServiceIfServiceNotDown() throws ExecutionException, InterruptedException {
916         ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
917         Services serviceMock = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null);
918         ServicesBuilder builder = new ServicesBuilder(serviceMock).setAdministrativeState(State.InService)
919                 .setOperationalState(State.InService);
920         Optional<Services> service = Optional.of(builder.build());
921         Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service);
922         ServiceRestorationOutput result = this.serviceHandlerImplMock.serviceRestoration(input).get().getResult();
923         Assert.assertEquals(RpcStatus.Failed, result.getStatus());
924         Assert.assertEquals("Service 'service 1' is in 'inService' state", result.getStatusMessage());
925     }
926
927     @Test
928     public void restorationServiceIfServicePresentAndDown() throws ExecutionException, InterruptedException {
929         ServiceRestorationInput serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput();
930         Services serviceMock = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null);
931         ServicesBuilder builder = new ServicesBuilder(serviceMock).setAdministrativeState(State.OutOfService)
932                 .setOperationalState(State.OutOfService);
933         Optional<Services> service = Optional.of(builder.build());
934         Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service);
935         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput input =
936                 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, serviceMock);
937         ConfigurationResponseCommon configurationResponseCommon =
938                 new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES)
939                         .setRequestId("1").setResponseCode(ResponseCodes.RESPONSE_OK)
940                         .setResponseMessage("Renderer service delete in progress").build();
941         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output =
942                 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
943                     .ServiceDeleteOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon).build();
944         Mockito.when(
945                 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult))
946                 .thenReturn(output);
947         ServiceRestorationOutput result =
948                 this.serviceHandlerImplMock.serviceRestoration(serviceRestorationInput).get().getResult();
949         Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful,
950                 result.getStatus());
951         Assert.assertEquals("Renderer service delete in progress", result.getStatusMessage());
952     }
953 }