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