2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.servicehandler.impl;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
13 import java.lang.reflect.InvocationTargetException;
14 import java.lang.reflect.Method;
15 import java.util.Arrays;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Optional;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Future;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.mockito.MockitoAnnotations;
28 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
29 import org.opendaylight.transportpce.common.OperationResult;
30 import org.opendaylight.transportpce.common.ResponseCodes;
31 import org.opendaylight.transportpce.pce.service.PathComputationService;
32 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
33 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
34 import org.opendaylight.transportpce.pce.utils.PceTestData;
35 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
36 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
37 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
38 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
39 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
40 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
41 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
42 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
43 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
44 import org.opendaylight.transportpce.test.AbstractTest;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder;
72 import org.opendaylight.yangtools.yang.common.RpcResult;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
76 public class ServiceHandlerImplTest extends AbstractTest {
78 private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class);
80 private PathComputationService pathComputationService;
81 private RendererServiceOperations rendererServiceOperations;
82 private ServicehandlerImpl serviceHandler;
85 private ServiceDataStoreOperations serviceDataStoreOperationsMock;
88 private PCEServiceWrapper pceServiceWrapperMock;
91 private RendererServiceOperations rendererServiceOperationsMock;
94 private ComplianceCheckResult complianceCheckResultMock;
97 private Optional<Services> servicesOptionalMock;
100 private ServicehandlerImpl serviceHandlerImplMock;
103 public void setUp() {
104 this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService,
105 this.rendererServiceOperations);
106 this.serviceHandlerImplMock = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
107 MockitoAnnotations.initMocks(this);
110 public ServiceHandlerImplTest() throws Exception {
111 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
112 this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService);
113 PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
114 "topologyData/NW-simple-topology.xml");
115 this.rendererServiceOperations = new StubRendererServiceOperations(notificationPublishService);
119 public void testCreateServiceValid() throws ExecutionException, InterruptedException {
121 ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput();
123 Future<RpcResult<ServiceCreateOutput>> output0 = this.serviceHandler.serviceCreate(serviceInput);
124 Assert.assertNotNull(output0);
125 Assert.assertTrue(output0.get().isSuccessful());
126 Assert.assertEquals(output0.get().getResult(),
127 ModelMappingUtils.createCreateServiceReply(serviceInput, ResponseCodes.FINAL_ACK_YES,
128 "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get().getResult());
129 Assert.assertEquals(0, output0.get().getErrors().size());
133 public void createServiceHandlerInvalidIfNameIsEmpty() throws ExecutionException, InterruptedException {
134 ServiceCreateInput emptyServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
135 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyServiceNameInput);
136 emptyServiceNameInput = builtInput.setServiceName("").build();
137 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceNameInput).get().getResult(),
138 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
139 "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
143 public void createServiceHandlerInvalidIfNameIsNull() throws ExecutionException, InterruptedException {
144 ServiceCreateInput nullServiceNameInput = ServiceDataUtils.buildServiceCreateInput();
145 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(nullServiceNameInput);
146 nullServiceNameInput = builtInput.setServiceName(null).build();
147 Assert.assertEquals(this.serviceHandler.serviceCreate(nullServiceNameInput).get().getResult(),
148 ModelMappingUtils.createCreateServiceReply(nullServiceNameInput, ResponseCodes.FINAL_ACK_YES,
149 "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
153 public void createServiceHnadlerInvalidIfConTypeIsEmpty() throws ExecutionException, InterruptedException {
154 ServiceCreateInput emptyConTypeInput = ServiceDataUtils.buildServiceCreateInput();
155 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyConTypeInput);
156 emptyConTypeInput = builtInput.setConnectionType(null).build();
157 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyConTypeInput).get().getResult(),
158 ModelMappingUtils.createCreateServiceReply(emptyConTypeInput, ResponseCodes.FINAL_ACK_YES,
159 "Service ConnectionType is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
163 public void createServiceHandlerInvalidIfSdncRequestHeaderNull() throws ExecutionException, InterruptedException {
164 ServiceCreateInput emptySdncRequestHeader = ServiceDataUtils.buildServiceCreateInput();
165 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptySdncRequestHeader);
166 emptySdncRequestHeader = buildInput.setSdncRequestHeader(null).build();
167 ServiceCreateOutput result = this.serviceHandler.serviceCreate(emptySdncRequestHeader).get().getResult();
168 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
169 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
170 ResponseCodes.FINAL_ACK_YES);
174 public void createServiceHandlerInvalidIfRequestIdEmpty() throws ExecutionException, InterruptedException {
175 ServiceCreateInput emptyRequestId = ServiceDataUtils.buildServiceCreateInput();
176 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyRequestId);
177 emptyRequestId = buildInput
178 .setSdncRequestHeader(
179 new SdncRequestHeaderBuilder(emptyRequestId.getSdncRequestHeader()).setRequestId("").build())
181 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyRequestId).get().getResult(),
183 .createCreateServiceReply(emptyRequestId, ResponseCodes.FINAL_ACK_YES,
184 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
189 public void createServiceHandlerInvalidIfRequestIdNull() throws ExecutionException, InterruptedException {
190 ServiceCreateInput nullRequestId = ServiceDataUtils.buildServiceCreateInput();
191 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(nullRequestId);
192 nullRequestId = buildInput
193 .setSdncRequestHeader(
194 new SdncRequestHeaderBuilder(nullRequestId.getSdncRequestHeader()).setRequestId(null).build())
196 Assert.assertEquals(this.serviceHandler.serviceCreate(nullRequestId).get().getResult(),
198 .createCreateServiceReply(nullRequestId, ResponseCodes.FINAL_ACK_YES,
199 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
204 public void serviceHandlerInvalidServiceActionIsNull() throws ExecutionException, InterruptedException {
205 ServiceCreateInput emptyServiceAction = ServiceDataUtils.buildServiceCreateInput();
206 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyServiceAction);
207 emptyServiceAction = buildInput.setSdncRequestHeader(
208 new SdncRequestHeaderBuilder(emptyServiceAction.getSdncRequestHeader()).setRpcAction(null).build())
210 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceAction).get().getResult(),
212 .createCreateServiceReply(emptyServiceAction, ResponseCodes.FINAL_ACK_YES,
213 "Service sndc-request-header 'rpc-action' is not set ", ResponseCodes.RESPONSE_FAILED)
218 public void serviceHandlerInvalidServiceActionIsNotCreate() throws ExecutionException, InterruptedException {
219 ServiceCreateInput notCreateServiceAction = ServiceDataUtils.buildServiceCreateInput();
220 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notCreateServiceAction);
221 notCreateServiceAction = buildInput
222 .setSdncRequestHeader(new SdncRequestHeaderBuilder(notCreateServiceAction.getSdncRequestHeader())
223 .setRpcAction(RpcActions.ServiceFeasibilityCheck).build())
225 Assert.assertEquals(this.serviceHandler.serviceCreate(notCreateServiceAction).get().getResult(),
226 ModelMappingUtils.createCreateServiceReply(notCreateServiceAction, ResponseCodes.FINAL_ACK_YES,
227 "Service sdncRequestHeader rpc-action '"
228 + notCreateServiceAction.getSdncRequestHeader().getRpcAction() + "' not equal to '"
229 + RpcActions.ServiceCreate.name() + "'",
230 ResponseCodes.RESPONSE_FAILED).get().getResult());
234 public void createServiceHandlerNotValidServiceAEndIsNull() throws ExecutionException, InterruptedException {
235 ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
236 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
237 notValidServiceAEnd = buildInput.setServiceAEnd(null).build();
238 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
239 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
240 "SERVICEAEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
244 public void createServiceHandlerNotValidServiceZEndIsNull() throws ExecutionException, InterruptedException {
245 ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
246 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
247 notValidServiceAEnd = buildInput.setServiceZEnd(null).build();
248 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
249 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
250 "SERVICEZEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
254 public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException {
255 ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
256 ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
257 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
258 notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setServiceRate(null)
260 Assert.assertEquals(servicehandler.serviceCreate(notValidServiceAEnd).get().getResult(),
261 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
262 "Service " + ServiceEndpointType.SERVICEAEND + " rate is not set",
263 ResponseCodes.RESPONSE_FAILED).get().getResult());
267 public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException {
268 ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
269 ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
270 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
271 notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setServiceRate(null)
273 Assert.assertEquals(servicehandler.serviceCreate(notValidServiceZEnd).get().getResult(),
274 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
275 "Service " + ServiceEndpointType.SERVICEZEND + " rate is not set",
276 ResponseCodes.RESPONSE_FAILED).get().getResult());
280 public void createServiceHandlerNotValidServiceAEndClliIsNull()
281 throws ExecutionException, InterruptedException {
282 ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput();
283 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
284 notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setClli(null)
286 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
287 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
288 "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set",
289 ResponseCodes.RESPONSE_FAILED).get().getResult());
293 public void createServiceHandlerNotValidServiceZEndClliIsNull()
294 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
295 ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput();
296 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
297 notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setClli(null).build())
299 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceZEnd).get().getResult(),
300 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
301 "Service" + ServiceEndpointType.SERVICEZEND + " clli format is not set",
302 ResponseCodes.RESPONSE_FAILED).get().getResult());
306 public void createServiceHandlerNotValidServiceAEndAttributes()
307 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
308 HashMap<String, Object> notValidData = new HashMap<>();
309 notValidData.put("setServiceRate", 0L);
310 notValidData.put("setServiceFormat", null);
311 notValidData.put("setClli", "");
312 notValidData.put("setTxDirection", null);
313 notValidData.put("setRxDirection", null);
314 for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
315 .ServiceAEndBuilder.class.getDeclaredMethods()) {
316 if (notValidData.containsKey(method.getName())) {
317 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
318 .buildServiceCreateInput());
319 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
320 .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
321 method.invoke(serviceAEndBuilder, notValidData.get(method.getName()));
322 ServiceCreateOutput result = this.serviceHandler
323 .serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get().getResult();
324 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
325 ResponseCodes.FINAL_ACK_YES);
326 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
327 ResponseCodes.RESPONSE_FAILED);
333 public void createServiceHandlerNotValidServiceZEndAttributes()
334 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
335 HashMap<String, Object> notValidData = new HashMap<>();
336 notValidData.put("setServiceRate", 0L);
337 notValidData.put("setServiceFormat", null);
338 notValidData.put("setClli", "");
339 notValidData.put("setTxDirection", null);
340 notValidData.put("setRxDirection", null);
341 for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
342 .ServiceZEndBuilder.class.getDeclaredMethods()) {
343 if (notValidData.containsKey(method.getName())) {
344 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(ServiceDataUtils
345 .buildServiceCreateInput());
346 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
347 .ServiceZEndBuilder serviceZEndBuilder = ServiceDataUtils.getServiceZEndBuild();
348 method.invoke(serviceZEndBuilder, notValidData.get(method.getName()));
349 ServiceCreateOutput result = this.serviceHandler
350 .serviceCreate(buildInput.setServiceZEnd(serviceZEndBuilder.build()).build()).get().getResult();
351 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
352 ResponseCodes.FINAL_ACK_YES);
353 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
354 ResponseCodes.RESPONSE_FAILED);
360 public void createServiceHandlerNotValidTxDirectionPort()
361 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
362 List<String> invalidData = Arrays.asList(null, "");
363 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
364 for (Method method : PortBuilder.class.getMethods()) {
365 if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
366 for (Object data : invalidData) {
367 PortBuilder portBuilder = new PortBuilder(
368 serviceCreateInput.getServiceAEnd().getTxDirection().getPort());
369 method.invoke(portBuilder, data);
370 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(portBuilder.build(),
371 serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
372 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
373 ResponseCodes.FINAL_ACK_YES);
374 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
375 ResponseCodes.RESPONSE_FAILED);
382 public void createServiceHandlerTxDirectionPortIsNull() throws ExecutionException, InterruptedException {
383 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(null,
384 ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getLgx());
385 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
386 ResponseCodes.FINAL_ACK_YES);
387 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
391 public void createServiceHandlerNotValidTxDirectionLgx()
392 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
393 List<String> invalidData = Arrays.asList(null, "");
394 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
395 for (Method method : LgxBuilder.class.getMethods()) {
396 if (method.getName().startsWith("set")) {
397 for (Object data : invalidData) {
398 LgxBuilder lgxBuilder = new LgxBuilder(
399 serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
400 method.invoke(lgxBuilder, data);
401 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
402 serviceCreateInput.getServiceAEnd().getTxDirection().getPort(), lgxBuilder.build());
403 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
404 ResponseCodes.FINAL_ACK_YES);
405 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
406 ResponseCodes.RESPONSE_FAILED);
413 public void createServiceHandlerTxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
414 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
415 ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getTxDirection().getPort(), null);
416 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
417 ResponseCodes.FINAL_ACK_YES);
418 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
421 private ServiceCreateOutput getTxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
422 throws InterruptedException, ExecutionException {
423 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
424 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
425 .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
426 TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder(
427 serviceCreateInput.getServiceAEnd().getTxDirection());
428 txDirectionBuilder.setPort(port);
429 txDirectionBuilder.setLgx(lgx);
430 serviceAEndBuilder.setTxDirection(txDirectionBuilder.build());
431 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
432 ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
433 return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
438 public void createServiceHandlerNotValidRxDirectionPort()
439 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
440 List<String> invalidData = Arrays.asList(null, "");
441 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
442 for (Method method : PortBuilder.class.getMethods()) {
443 if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
444 for (Object data : invalidData) {
445 PortBuilder portBuilder = new PortBuilder(
446 serviceCreateInput.getServiceAEnd().getRxDirection().getPort());
447 method.invoke(portBuilder, data);
448 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(portBuilder.build(),
449 serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
450 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
451 ResponseCodes.FINAL_ACK_YES);
452 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
453 ResponseCodes.RESPONSE_FAILED);
460 public void createServiceHandlerRxDirectionPortIsNull()
461 throws ExecutionException, InterruptedException {
462 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(null,
463 ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getLgx());
464 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
465 ResponseCodes.FINAL_ACK_YES);
466 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
470 public void createServiceHandlerNotValidRxDirectionLgx()
471 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
472 List<String> invalidData = Arrays.asList(null, "");
473 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
474 for (Method method : LgxBuilder.class.getMethods()) {
475 if (method.getName().startsWith("set")) {
476 for (Object data : invalidData) {
477 LgxBuilder lgxBuilder = new LgxBuilder(
478 serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
479 method.invoke(lgxBuilder, data);
480 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
481 serviceCreateInput.getServiceAEnd().getRxDirection().getPort(), lgxBuilder.build());
482 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
483 ResponseCodes.FINAL_ACK_YES);
484 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
485 ResponseCodes.RESPONSE_FAILED);
492 public void createServiceHandlerRxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
493 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
494 ServiceDataUtils.buildServiceCreateInput().getServiceAEnd().getRxDirection().getPort(), null);
495 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
496 ResponseCodes.FINAL_ACK_YES);
497 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
501 public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException {
502 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
504 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
505 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
506 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failed").build();
507 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
508 PceTestData.getPCE_simpletopology_test1_result((long) 5))
509 .setConfigurationResponseCommon(configurationResponseCommon).build();
510 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
511 .thenReturn(pathComputationRequestOutput);
512 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
513 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
514 ResponseCodes.FINAL_ACK_YES);
515 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
516 verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true);
520 public void createServiceHandlerOperationResultNotPassed() throws ExecutionException, InterruptedException {
521 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
522 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
523 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
524 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
525 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
526 PceTestData.getPCE_simpletopology_test1_result((long) 5))
527 .setConfigurationResponseCommon(configurationResponseCommon).build();
528 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
529 .thenReturn(pathComputationRequestOutput);
530 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
531 any(PathComputationRequestOutput.class)))
532 .thenReturn(OperationResult.failed(
533 "Failed to create service " + serviceCreateInput.getServiceName() + " to Service List"));
534 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
535 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
536 ResponseCodes.FINAL_ACK_YES);
537 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
538 verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class),
539 any(PathComputationRequestOutput.class));
543 public void createServiceHandlerOperationServicePathSaveResultNotPassed()
544 throws ExecutionException, InterruptedException {
545 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
546 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
547 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
548 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
549 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
550 PceTestData.getPCE_simpletopology_test1_result((long) 5))
551 .setConfigurationResponseCommon(configurationResponseCommon).build();
552 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
553 .thenReturn(pathComputationRequestOutput);
554 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
555 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
556 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
557 any(PathComputationRequestOutput.class)))
558 .thenReturn(OperationResult.failed("Failed to create servicePath " + serviceCreateInput.getServiceName()
559 + " to ServicePath List"));
560 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
561 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
562 ResponseCodes.FINAL_ACK_YES);
563 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
564 verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceCreateInput.class),
565 any(PathComputationRequestOutput.class));
569 public void createServiceHandlerModifyServicePassed() throws ExecutionException, InterruptedException {
570 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
571 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
572 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
573 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
574 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
575 PceTestData.getPCE_simpletopology_test1_result((long) 5))
576 .setConfigurationResponseCommon(configurationResponseCommon).build();
577 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
578 .thenReturn(pathComputationRequestOutput);
579 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
580 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
581 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
582 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
583 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
584 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
585 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
588 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
589 .thenReturn(new ServiceImplementationRequestOutputBuilder()
590 .setConfigurationResponseCommon(configurationResponseCommon2).build());
591 Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
592 State.InService, State.InService)).thenReturn(OperationResult.ok("successful"));
593 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
594 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
595 ResponseCodes.FINAL_ACK_YES);
596 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
597 verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
602 public void createServiceHandlerModifyServiceNotPassed() throws ExecutionException, InterruptedException {
603 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
604 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
605 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
606 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
607 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
608 PceTestData.getPCE_simpletopology_test1_result((long) 5))
609 .setConfigurationResponseCommon(configurationResponseCommon).build();
610 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
611 .thenReturn(pathComputationRequestOutput);
612 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
613 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
614 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
615 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
616 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
617 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
618 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
621 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
622 .thenReturn(new ServiceImplementationRequestOutputBuilder()
623 .setConfigurationResponseCommon(configurationResponseCommon2).build());
624 Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
625 State.InService, State.InService)).thenReturn(OperationResult.failed("failure"));
626 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
627 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
628 ResponseCodes.FINAL_ACK_YES);
629 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
630 verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
635 public void createServiceHandlerServiceImplementationNotPassed() throws ExecutionException, InterruptedException {
636 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
637 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
638 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
639 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
640 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
641 PceTestData.getPCE_simpletopology_test1_result((long) 5))
642 .setConfigurationResponseCommon(configurationResponseCommon).build();
643 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
644 .thenReturn(pathComputationRequestOutput);
645 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
646 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
647 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
648 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
649 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
650 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
651 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
654 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
655 .thenReturn(new ServiceImplementationRequestOutputBuilder()
656 .setConfigurationResponseCommon(configurationResponseCommon2).build());
657 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
658 .thenReturn(OperationResult.ok("successful"));
659 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
660 .thenReturn(OperationResult.ok("successful"));
661 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
662 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
663 ResponseCodes.FINAL_ACK_YES);
664 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
665 verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
666 verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
670 public void createServiceHandlerServiceImplementationNotPassed2() throws ExecutionException, InterruptedException {
671 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
672 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
673 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
674 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
675 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
676 PceTestData.getPCE_simpletopology_test1_result((long) 5))
677 .setConfigurationResponseCommon(configurationResponseCommon).build();
678 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
679 .thenReturn(pathComputationRequestOutput);
680 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
681 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
682 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
683 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
684 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
685 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
686 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
689 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
690 .thenReturn(new ServiceImplementationRequestOutputBuilder()
691 .setConfigurationResponseCommon(configurationResponseCommon2).build());
692 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
693 .thenReturn(OperationResult.failed("successful"));
694 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
695 .thenReturn(OperationResult.failed("successful"));
696 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
697 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
698 ResponseCodes.FINAL_ACK_YES);
699 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
700 verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
701 verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
704 private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
705 throws InterruptedException, ExecutionException {
706 ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
707 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
708 .ServiceAEndBuilder serviceAEndBuilder = ServiceDataUtils.getServiceAEndBuild();
709 RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder(
710 serviceCreateInput.getServiceAEnd().getRxDirection());
711 rxDirectionBuilder.setPort(port);
712 rxDirectionBuilder.setLgx(lgx);
713 serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build());
714 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
715 ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
716 return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
721 public void deleteServiceInvalidIfServiceNameIsEmpty() throws ExecutionException, InterruptedException {
723 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
724 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
725 serviceDeleteInput = builder
726 .setServiceDeleteReqInfo(
727 new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName("").build())
729 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
730 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
731 ResponseCodes.FINAL_ACK_YES);
732 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
736 public void deleteServiceInvalidIfServiceNameIsNull() throws ExecutionException, InterruptedException {
738 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
739 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
740 serviceDeleteInput = builder
741 .setServiceDeleteReqInfo(
742 new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName(null).build())
744 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
745 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
746 ResponseCodes.FINAL_ACK_YES);
747 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
751 public void deleteServiceInvalidIfSdncRequestHeaderIsNull() throws ExecutionException, InterruptedException {
752 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
753 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
754 serviceDeleteInput = builder.setSdncRequestHeader(null).build();
755 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
756 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
757 ResponseCodes.FINAL_ACK_YES);
758 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
762 public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsNull()
763 throws ExecutionException, InterruptedException {
765 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
766 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
767 serviceDeleteInput = builder
768 .setSdncRequestHeader(
769 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId(null).build())
771 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
772 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
773 ResponseCodes.FINAL_ACK_YES);
774 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
778 public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsEmpty()
779 throws ExecutionException, InterruptedException {
781 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
782 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
783 serviceDeleteInput = builder.setSdncRequestHeader(
784 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId("").build()).build();
785 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
786 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
787 ResponseCodes.FINAL_ACK_YES);
788 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
792 public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNull()
793 throws ExecutionException, InterruptedException {
795 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
796 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
797 serviceDeleteInput = builder
798 .setSdncRequestHeader(
799 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRpcAction(null).build())
801 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
802 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
803 ResponseCodes.FINAL_ACK_YES);
804 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
808 public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNotDelete()
809 throws ExecutionException, InterruptedException {
811 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
812 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
813 serviceDeleteInput = builder.setSdncRequestHeader(new SdncRequestHeaderBuilder(builder.getSdncRequestHeader())
814 .setRpcAction(RpcActions.ServiceCreate).build()).build();
815 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
816 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
817 ResponseCodes.FINAL_ACK_YES);
818 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
822 public void deleteServiceIfServiceHandlerCompliancyCheckNotPassed()
823 throws ExecutionException, InterruptedException {
825 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
827 Mockito.when(this.complianceCheckResultMock.hasPassed()).thenReturn(false);
829 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
830 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
831 ResponseCodes.FINAL_ACK_YES);
832 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
836 public void deleteServiceNotPresent() throws ExecutionException, InterruptedException {
838 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(ServiceDataUtils.buildServiceDeleteInput()).get()
840 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
841 ResponseCodes.FINAL_ACK_YES);
842 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
846 public void deleteServiceIfServiceNotPresent() throws ExecutionException, InterruptedException {
848 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
849 Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
850 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
851 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
852 ResponseCodes.FINAL_ACK_YES);
853 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
857 public void deleteServiceNotPassed() throws ExecutionException, InterruptedException {
859 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
860 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
861 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
862 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
863 .ServiceDeleteInput input = ModelMappingUtils
864 .createServiceDeleteInput(serviceDeleteInput);
865 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
866 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
867 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("success").build();
868 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
869 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
870 .servicepath.rev170426.ServiceDeleteOutputBuilder()
871 .setConfigurationResponseCommon(configurationResponseCommon).build();
872 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
873 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
874 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
875 ResponseCodes.FINAL_ACK_YES);
876 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
880 public void deleteServicePathNotPassed() throws ExecutionException, InterruptedException {
882 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
883 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
884 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
885 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
886 .ServiceDeleteInput input = ModelMappingUtils
887 .createServiceDeleteInput(serviceDeleteInput);
888 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
889 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
890 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
891 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
892 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
893 .servicepath.rev170426.ServiceDeleteOutputBuilder()
894 .setConfigurationResponseCommon(configurationResponseCommon).build();
895 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
896 Mockito.when(this.serviceDataStoreOperationsMock
897 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
898 .thenReturn(OperationResult.failed("failed"));
899 Mockito.when(this.serviceDataStoreOperationsMock
900 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
901 .thenReturn(OperationResult.failed("failed"));
902 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
903 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
904 ResponseCodes.FINAL_ACK_YES);
905 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
909 public void deleteServiceOperationNotPassed() throws ExecutionException, InterruptedException {
911 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
912 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
913 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
914 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
915 .ServiceDeleteInput input = ModelMappingUtils
916 .createServiceDeleteInput(serviceDeleteInput);
917 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
918 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
919 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
920 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
921 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
922 .servicepath.rev170426.ServiceDeleteOutputBuilder()
923 .setConfigurationResponseCommon(configurationResponseCommon).build();
924 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
925 Mockito.when(this.serviceDataStoreOperationsMock
926 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
927 .thenReturn(OperationResult.ok("success"));
928 Mockito.when(this.serviceDataStoreOperationsMock
929 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
930 .thenReturn(OperationResult.ok("success"));
931 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
932 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
933 ResponseCodes.FINAL_ACK_YES);
934 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
938 public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException {
940 ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
941 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
942 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
943 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
944 .ServiceDeleteInput input = ModelMappingUtils
945 .createServiceDeleteInput(serviceDeleteInput);
946 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
947 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
948 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
949 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
950 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
951 .servicepath.rev170426.ServiceDeleteOutputBuilder()
952 .setConfigurationResponseCommon(configurationResponseCommon).build();
953 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
954 Mockito.when(this.serviceDataStoreOperationsMock
955 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
956 .thenReturn(OperationResult.ok("success"));
957 Mockito.when(this.serviceDataStoreOperationsMock
958 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
959 .thenReturn(OperationResult.ok("success"));
960 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
961 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
962 ResponseCodes.FINAL_ACK_YES);
963 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
967 public void rerouteServiceIsNotePresent() throws ExecutionException, InterruptedException {
969 ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
970 ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult();
971 Assert.assertEquals(result.getStatus(), RpcStatus.Failed);
972 Assert.assertEquals(result.getStatusMessage(), "Failure");
977 public void rerouteServiceIfserviceIsPresent() throws ExecutionException, InterruptedException {
979 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
980 ServiceCreateOutput createOutput = this.serviceHandler.serviceCreate(createInput).get().getResult();
981 ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
982 ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult();
983 Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful,
985 Assert.assertEquals("Success", result.getStatusMessage());
989 /*@Test(expected = ReadFailedException.class)
990 public void rerouteServiceThrowsException() throws ReadFailedException, InterruptedException, ExecutionException{
991 ServiceCreateInput createInput = buildServiceCreateInput();
992 ServiceCreateOutput createOutput = serviceHandler.serviceCreate(createInput).get().getResult();
993 ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
994 Mockito.when(dataStoreService.checkedGet()).thenThrow(InterruptedException.class);
995 ServiceRerouteOutput result = serviceHandler.serviceReroute(input).get().getResult();