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.time.OffsetDateTime;
16 import java.time.ZoneOffset;
17 import java.time.format.DateTimeFormatter;
18 import java.util.Arrays;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Optional;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.Future;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
32 import org.opendaylight.transportpce.common.OperationResult;
33 import org.opendaylight.transportpce.common.ResponseCodes;
34 import org.opendaylight.transportpce.pce.service.PathComputationService;
35 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
36 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
37 import org.opendaylight.transportpce.pce.utils.PceTestData;
38 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
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.service.PCEServiceWrapper;
43 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
44 import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations;
45 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
46 import org.opendaylight.transportpce.test.AbstractTest;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder;
74 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
75 import org.opendaylight.yangtools.yang.common.RpcResult;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
79 public class ServiceHandlerImplTest extends AbstractTest {
81 private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class);
83 private NotificationPublishService notificationPublishService;
84 private PathComputationService pathComputationService;
85 private RendererServiceOperations rendererServiceOperations;
86 private ServicehandlerImpl serviceHandler;
89 private ServiceDataStoreOperations serviceDataStoreOperationsMock;
92 private PCEServiceWrapper pceServiceWrapperMock;
95 private RendererServiceOperations rendererServiceOperationsMock;
98 private ComplianceCheckResult complianceCheckResultMock;
101 private Optional<Services> servicesOptionalMock;
104 private ServicehandlerImpl serviceHandlerImplMock;
107 public void setUp() throws Exception {
108 this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService,
109 this.rendererServiceOperations);
110 this.serviceHandlerImplMock = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
111 MockitoAnnotations.initMocks(this);
114 public ServiceHandlerImplTest() throws Exception {
115 this.notificationPublishService = new NotificationPublishServiceMock();
116 this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), this.notificationPublishService);
117 PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
118 "topologyData/NW-simple-topology.xml");
119 this.rendererServiceOperations = new StubRendererServiceOperations(this.notificationPublishService);
123 public void testCreateServiceValid() throws ExecutionException, InterruptedException {
125 ServiceCreateInput serviceInput = buildServiceCreateInput();
127 Future<RpcResult<ServiceCreateOutput>> output0 = this.serviceHandler.serviceCreate(serviceInput);
128 Assert.assertNotNull(output0);
129 Assert.assertTrue(output0.get().isSuccessful());
130 Assert.assertEquals(output0.get().getResult(),
131 ModelMappingUtils.createCreateServiceReply(serviceInput, ResponseCodes.FINAL_ACK_YES,
132 "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get().getResult());
133 Assert.assertEquals(0, output0.get().getErrors().size());
137 public void createServiceHandlerInvalidIfNameIsEmpty() throws ExecutionException, InterruptedException {
138 ServiceCreateInput emptyServiceNameInput = buildServiceCreateInput();
139 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyServiceNameInput);
140 emptyServiceNameInput = builtInput.setServiceName("").build();
141 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceNameInput).get().getResult(),
142 ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES,
143 "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
147 public void createServiceHandlerInvalidIfNameIsNull() throws ExecutionException, InterruptedException {
148 ServiceCreateInput nullServiceNameInput = buildServiceCreateInput();
149 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(nullServiceNameInput);
150 nullServiceNameInput = builtInput.setServiceName(null).build();
151 Assert.assertEquals(this.serviceHandler.serviceCreate(nullServiceNameInput).get().getResult(),
152 ModelMappingUtils.createCreateServiceReply(nullServiceNameInput, ResponseCodes.FINAL_ACK_YES,
153 "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
157 public void createServiceHnadlerInvalidIfConTypeIsEmpty() throws ExecutionException, InterruptedException {
158 ServiceCreateInput emptyConTypeInput = buildServiceCreateInput();
159 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyConTypeInput);
160 emptyConTypeInput = builtInput.setConnectionType(null).build();
161 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyConTypeInput).get().getResult(),
162 ModelMappingUtils.createCreateServiceReply(emptyConTypeInput, ResponseCodes.FINAL_ACK_YES,
163 "Service ConnectionType is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
167 public void createServiceHandlerInvalidIfSdncRequestHeaderNull() throws ExecutionException, InterruptedException {
168 ServiceCreateInput emptySdncRequestHeader = buildServiceCreateInput();
169 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptySdncRequestHeader);
170 emptySdncRequestHeader = buildInput.setSdncRequestHeader(null).build();
171 ServiceCreateOutput result = this.serviceHandler.serviceCreate(emptySdncRequestHeader).get().getResult();
172 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
173 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
174 ResponseCodes.FINAL_ACK_YES);
178 public void createServiceHandlerInvalidIfRequestIdEmpty() throws ExecutionException, InterruptedException {
179 ServiceCreateInput emptyRequestId = buildServiceCreateInput();
180 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyRequestId);
181 emptyRequestId = buildInput
182 .setSdncRequestHeader(
183 new SdncRequestHeaderBuilder(emptyRequestId.getSdncRequestHeader()).setRequestId("").build())
185 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyRequestId).get().getResult(),
187 .createCreateServiceReply(emptyRequestId, ResponseCodes.FINAL_ACK_YES,
188 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
193 public void createServiceHandlerInvalidIfRequestIdNull() throws ExecutionException, InterruptedException {
194 ServiceCreateInput nullRequestId = buildServiceCreateInput();
195 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(nullRequestId);
196 nullRequestId = buildInput
197 .setSdncRequestHeader(
198 new SdncRequestHeaderBuilder(nullRequestId.getSdncRequestHeader()).setRequestId(null).build())
200 Assert.assertEquals(this.serviceHandler.serviceCreate(nullRequestId).get().getResult(),
202 .createCreateServiceReply(nullRequestId, ResponseCodes.FINAL_ACK_YES,
203 "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED)
208 public void serviceHandlerInvalidServiceActionIsNull() throws ExecutionException, InterruptedException {
209 ServiceCreateInput emptyServiceAction = buildServiceCreateInput();
210 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyServiceAction);
211 emptyServiceAction = buildInput.setSdncRequestHeader(
212 new SdncRequestHeaderBuilder(emptyServiceAction.getSdncRequestHeader()).setRpcAction(null).build())
214 Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceAction).get().getResult(),
216 .createCreateServiceReply(emptyServiceAction, ResponseCodes.FINAL_ACK_YES,
217 "Service sndc-request-header 'rpc-action' is not set ", ResponseCodes.RESPONSE_FAILED)
222 public void serviceHandlerInvalidServiceActionIsNotCreate() throws ExecutionException, InterruptedException {
223 ServiceCreateInput notCreateServiceAction = buildServiceCreateInput();
224 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notCreateServiceAction);
225 notCreateServiceAction = buildInput
226 .setSdncRequestHeader(new SdncRequestHeaderBuilder(notCreateServiceAction.getSdncRequestHeader())
227 .setRpcAction(RpcActions.ServiceFeasibilityCheck).build())
229 Assert.assertEquals(this.serviceHandler.serviceCreate(notCreateServiceAction).get().getResult(),
230 ModelMappingUtils.createCreateServiceReply(notCreateServiceAction, ResponseCodes.FINAL_ACK_YES,
231 "Service sdncRequestHeader rpc-action '"
232 + notCreateServiceAction.getSdncRequestHeader().getRpcAction() + "' not equal to '"
233 + RpcActions.ServiceCreate.name() + "'",
234 ResponseCodes.RESPONSE_FAILED).get().getResult());
238 public void createServiceHandlerNotValidServiceAEndIsNull() throws ExecutionException, InterruptedException {
239 ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput();
240 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
241 notValidServiceAEnd = buildInput.setServiceAEnd(null).build();
242 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
243 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
244 "SERVICEAEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
248 public void createServiceHandlerNotValidServiceZEndIsNull() throws ExecutionException, InterruptedException {
249 ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput();
250 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
251 notValidServiceAEnd = buildInput.setServiceZEnd(null).build();
252 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
253 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
254 "SERVICEZEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult());
258 public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException {
259 ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
260 ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput();
261 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
262 notValidServiceAEnd = buildInput.setServiceAEnd(getServiceAEndBuild().setServiceRate(null).build()).build();
263 Assert.assertEquals(servicehandler.serviceCreate(notValidServiceAEnd).get().getResult(),
264 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
265 "Service " + ServiceEndpointType.SERVICEAEND + " rate is not set",
266 ResponseCodes.RESPONSE_FAILED).get().getResult());
270 public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException {
271 ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
272 ServiceCreateInput notValidServiceZEnd = buildServiceCreateInput();
273 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
274 notValidServiceZEnd = buildInput.setServiceZEnd(getServiceZEndBuild().setServiceRate(null).build()).build();
275 Assert.assertEquals(servicehandler.serviceCreate(notValidServiceZEnd).get().getResult(),
276 ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES,
277 "Service " + ServiceEndpointType.SERVICEZEND + " rate is not set",
278 ResponseCodes.RESPONSE_FAILED).get().getResult());
282 public void createServiceHandlerNotValidServiceAEndClliIsNull()
283 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
284 ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput();
285 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd);
286 notValidServiceAEnd = buildInput.setServiceAEnd(getServiceAEndBuild().setClli(null).build()).build();
287 Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(),
288 ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES,
289 "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set",
290 ResponseCodes.RESPONSE_FAILED).get().getResult());
294 public void createServiceHandlerNotValidServiceZEndClliIsNull()
295 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
296 ServiceCreateInput notValidServiceZEnd = buildServiceCreateInput();
297 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd);
298 notValidServiceZEnd = buildInput.setServiceZEnd(getServiceZEndBuild().setClli(null).build()).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(buildServiceCreateInput());
318 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
319 .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild();
320 method.invoke(serviceAEndBuilder, notValidData.get(method.getName()));
321 ServiceCreateOutput result = this.serviceHandler
322 .serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get().getResult();
323 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
324 ResponseCodes.FINAL_ACK_YES);
325 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
326 ResponseCodes.RESPONSE_FAILED);
332 public void createServiceHandlerNotValidServiceZEndAttributes()
333 throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException {
334 HashMap<String, Object> notValidData = new HashMap<>();
335 notValidData.put("setServiceRate", 0L);
336 notValidData.put("setServiceFormat", null);
337 notValidData.put("setClli", "");
338 notValidData.put("setTxDirection", null);
339 notValidData.put("setRxDirection", null);
340 for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
341 .ServiceZEndBuilder.class.getDeclaredMethods()) {
342 if (notValidData.containsKey(method.getName())) {
343 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(buildServiceCreateInput());
344 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
345 .ServiceZEndBuilder serviceZEndBuilder = getServiceZEndBuild();
346 method.invoke(serviceZEndBuilder, notValidData.get(method.getName()));
347 ServiceCreateOutput result = this.serviceHandler
348 .serviceCreate(buildInput.setServiceZEnd(serviceZEndBuilder.build()).build()).get().getResult();
349 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
350 ResponseCodes.FINAL_ACK_YES);
351 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
352 ResponseCodes.RESPONSE_FAILED);
358 public void createServiceHandlerNotValidTxDirectionPort()
359 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
360 List<String> invalidData = Arrays.asList(null, "");
361 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
362 for (Method method : PortBuilder.class.getMethods()) {
363 if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
364 for (Object data : invalidData) {
365 PortBuilder portBuilder = new PortBuilder(
366 serviceCreateInput.getServiceAEnd().getTxDirection().getPort());
367 method.invoke(portBuilder, data);
368 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(portBuilder.build(),
369 serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
370 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
371 ResponseCodes.FINAL_ACK_YES);
372 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
373 ResponseCodes.RESPONSE_FAILED);
380 public void createServiceHandlerTxDirectionPortIsNull() throws ExecutionException, InterruptedException {
381 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(null,
382 buildServiceCreateInput().getServiceAEnd().getTxDirection().getLgx());
383 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
384 ResponseCodes.FINAL_ACK_YES);
385 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
389 public void createServiceHandlerNotValidTxDirectionLgx()
390 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
391 List<String> invalidData = Arrays.asList(null, "");
392 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
393 for (Method method : LgxBuilder.class.getMethods()) {
394 if (method.getName().startsWith("set")) {
395 for (Object data : invalidData) {
396 LgxBuilder lgxBuilder = new LgxBuilder(
397 serviceCreateInput.getServiceAEnd().getTxDirection().getLgx());
398 method.invoke(lgxBuilder, data);
399 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
400 serviceCreateInput.getServiceAEnd().getTxDirection().getPort(), lgxBuilder.build());
401 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
402 ResponseCodes.FINAL_ACK_YES);
403 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
404 ResponseCodes.RESPONSE_FAILED);
411 public void createServiceHandlerTxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
412 ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(
413 buildServiceCreateInput().getServiceAEnd().getTxDirection().getPort(), null);
414 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
415 ResponseCodes.FINAL_ACK_YES);
416 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
419 private ServiceCreateOutput getTxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
420 throws InterruptedException, ExecutionException {
421 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
422 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
423 .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild();
424 TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder(
425 serviceCreateInput.getServiceAEnd().getTxDirection());
426 txDirectionBuilder.setPort(port);
427 txDirectionBuilder.setLgx(lgx);
428 serviceAEndBuilder.setTxDirection(txDirectionBuilder.build());
429 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
430 ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
431 return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
436 public void createServiceHandlerNotValidRxDirectionPort()
437 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
438 List<String> invalidData = Arrays.asList(null, "");
439 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
440 for (Method method : PortBuilder.class.getMethods()) {
441 if (method.getName().startsWith("set") && !method.getName().contains("Slot")) {
442 for (Object data : invalidData) {
443 PortBuilder portBuilder = new PortBuilder(
444 serviceCreateInput.getServiceAEnd().getRxDirection().getPort());
445 method.invoke(portBuilder, data);
446 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(portBuilder.build(),
447 serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
448 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
449 ResponseCodes.FINAL_ACK_YES);
450 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
451 ResponseCodes.RESPONSE_FAILED);
458 public void createServiceHandlerRxDirectionPortIsNull()
459 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
460 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(null,
461 buildServiceCreateInput().getServiceAEnd().getRxDirection().getLgx());
462 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
463 ResponseCodes.FINAL_ACK_YES);
464 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
468 public void createServiceHandlerNotValidRxDirectionLgx()
469 throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException {
470 List<String> invalidData = Arrays.asList(null, "");
471 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
472 for (Method method : LgxBuilder.class.getMethods()) {
473 if (method.getName().startsWith("set")) {
474 for (Object data : invalidData) {
475 LgxBuilder lgxBuilder = new LgxBuilder(
476 serviceCreateInput.getServiceAEnd().getRxDirection().getLgx());
477 method.invoke(lgxBuilder, data);
478 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
479 serviceCreateInput.getServiceAEnd().getRxDirection().getPort(), lgxBuilder.build());
480 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
481 ResponseCodes.FINAL_ACK_YES);
482 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(),
483 ResponseCodes.RESPONSE_FAILED);
490 public void createServiceHandlerRxDirectionLgxIsNull() throws ExecutionException, InterruptedException {
491 ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(
492 buildServiceCreateInput().getServiceAEnd().getRxDirection().getPort(), null);
493 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
494 ResponseCodes.FINAL_ACK_YES);
495 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
499 public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException {
500 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
502 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
503 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
504 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failed").build();
505 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
506 PceTestData.getPCE_simpletopology_test1_result((long) 5))
507 .setConfigurationResponseCommon(configurationResponseCommon).build();
508 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
509 .thenReturn(pathComputationRequestOutput);
510 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
511 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
512 ResponseCodes.FINAL_ACK_YES);
513 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
514 verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true);
518 public void createServiceHandlerOperationResultNotPassed() throws ExecutionException, InterruptedException {
519 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
520 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
521 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
522 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
523 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
524 PceTestData.getPCE_simpletopology_test1_result((long) 5))
525 .setConfigurationResponseCommon(configurationResponseCommon).build();
526 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
527 .thenReturn(pathComputationRequestOutput);
528 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
529 any(PathComputationRequestOutput.class)))
530 .thenReturn(OperationResult.failed(
531 "Failed to create service " + serviceCreateInput.getServiceName() + " to Service List"));
532 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
533 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
534 ResponseCodes.FINAL_ACK_YES);
535 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
536 verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class),
537 any(PathComputationRequestOutput.class));
541 public void createServiceHandlerOperationServicePathSaveResultNotPassed()
542 throws ExecutionException, InterruptedException {
543 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
544 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
545 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
546 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
547 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
548 PceTestData.getPCE_simpletopology_test1_result((long) 5))
549 .setConfigurationResponseCommon(configurationResponseCommon).build();
550 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
551 .thenReturn(pathComputationRequestOutput);
552 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
553 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
554 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
555 any(PathComputationRequestOutput.class)))
556 .thenReturn(OperationResult.failed("Failed to create servicePath " + serviceCreateInput.getServiceName()
557 + " to ServicePath List"));
558 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
559 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
560 ResponseCodes.FINAL_ACK_YES);
561 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
562 verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceCreateInput.class),
563 any(PathComputationRequestOutput.class));
567 public void createServiceHandlerModifyServicePassed() throws ExecutionException, InterruptedException {
568 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
569 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
570 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
571 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
572 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
573 PceTestData.getPCE_simpletopology_test1_result((long) 5))
574 .setConfigurationResponseCommon(configurationResponseCommon).build();
575 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
576 .thenReturn(pathComputationRequestOutput);
577 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
578 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
579 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
580 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
581 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
582 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
583 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
586 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
587 .thenReturn(new ServiceImplementationRequestOutputBuilder()
588 .setConfigurationResponseCommon(configurationResponseCommon2).build());
589 Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
590 State.InService, State.InService)).thenReturn(OperationResult.ok("successful"));
591 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
592 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
593 ResponseCodes.FINAL_ACK_YES);
594 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
595 verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
600 public void createServiceHandlerModifyServiceNotPassed() throws ExecutionException, InterruptedException {
601 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
602 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
603 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
604 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
605 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
606 PceTestData.getPCE_simpletopology_test1_result((long) 5))
607 .setConfigurationResponseCommon(configurationResponseCommon).build();
608 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
609 .thenReturn(pathComputationRequestOutput);
610 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
611 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
612 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
613 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
614 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
615 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
616 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build();
619 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
620 .thenReturn(new ServiceImplementationRequestOutputBuilder()
621 .setConfigurationResponseCommon(configurationResponseCommon2).build());
622 Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(),
623 State.InService, State.InService)).thenReturn(OperationResult.failed("failure"));
624 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
625 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
626 ResponseCodes.FINAL_ACK_YES);
627 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
628 verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService,
633 public void createServiceHandlerServiceImplementationNotPassed() throws ExecutionException, InterruptedException {
634 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
635 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
636 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
637 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
638 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
639 PceTestData.getPCE_simpletopology_test1_result((long) 5))
640 .setConfigurationResponseCommon(configurationResponseCommon).build();
641 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
642 .thenReturn(pathComputationRequestOutput);
643 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
644 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
645 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
646 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
647 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
648 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
649 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
652 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
653 .thenReturn(new ServiceImplementationRequestOutputBuilder()
654 .setConfigurationResponseCommon(configurationResponseCommon2).build());
655 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
656 .thenReturn(OperationResult.ok("successful"));
657 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
658 .thenReturn(OperationResult.ok("successful"));
659 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
660 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
661 ResponseCodes.FINAL_ACK_YES);
662 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
663 verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
664 verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
668 public void createServiceHandlerServiceImplementationNotPassed2() throws ExecutionException, InterruptedException {
669 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
670 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
671 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
672 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
673 PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder(
674 PceTestData.getPCE_simpletopology_test1_result((long) 5))
675 .setConfigurationResponseCommon(configurationResponseCommon).build();
676 Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true))
677 .thenReturn(pathComputationRequestOutput);
678 Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class),
679 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
680 Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class),
681 any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful"));
682 ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder()
683 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1")
684 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build();
687 this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class)))
688 .thenReturn(new ServiceImplementationRequestOutputBuilder()
689 .setConfigurationResponseCommon(configurationResponseCommon2).build());
690 Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName()))
691 .thenReturn(OperationResult.failed("successful"));
692 Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName()))
693 .thenReturn(OperationResult.failed("successful"));
694 ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult();
695 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
696 ResponseCodes.FINAL_ACK_YES);
697 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
698 verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName());
699 verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName());
702 private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx)
703 throws InterruptedException, ExecutionException {
704 ServiceCreateInput serviceCreateInput = buildServiceCreateInput();
705 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
706 .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild();
707 RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder(
708 serviceCreateInput.getServiceAEnd().getRxDirection());
709 rxDirectionBuilder.setPort(port);
710 rxDirectionBuilder.setLgx(lgx);
711 serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build());
712 ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput);
713 ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null);
714 return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get()
718 private static ServiceCreateInput buildServiceCreateInput() {
720 ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder();
721 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
722 .ServiceAEnd serviceAEnd = getServiceAEndBuild()
724 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
725 .ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service
726 .create.input.ServiceZEndBuilder()
727 .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-3-2")
729 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
730 .endpoint.TxDirectionBuilder()
731 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
732 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
733 .setPortSubSlot("port subslot").setPortType("port type").build())
734 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
735 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
736 .setLgxPortShelf("lgx port shelf").build())
739 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
740 .endpoint.RxDirectionBuilder()
741 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
742 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
743 .setPortSubSlot("port subslot").setPortType("port type").build())
744 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
745 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
746 .setLgxPortShelf("lgx port shelf").build())
750 builtInput.setCommonId("commonId");
751 builtInput.setConnectionType(ConnectionType.Service);
752 builtInput.setCustomer("Customer");
753 builtInput.setServiceName("service 1");
754 builtInput.setServiceAEnd(serviceAEnd);
755 builtInput.setServiceZEnd(serviceZEnd);
756 builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request 1")
757 .setRpcAction(RpcActions.ServiceCreate).build());
759 return builtInput.build();
762 private static org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
763 .ServiceAEndBuilder getServiceAEndBuild() {
764 return new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
765 .ServiceAEndBuilder()
766 .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-1-2")
768 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
769 .endpoint.TxDirectionBuilder()
770 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
771 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
772 .setPortSubSlot("port subslot").setPortType("port type").build())
773 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
774 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
775 .setLgxPortShelf("lgx port shelf").build())
778 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
779 .endpoint.RxDirectionBuilder()
780 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
781 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
782 .setPortSubSlot("port subslot").setPortType("port type").build())
783 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
784 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
785 .setLgxPortShelf("lgx port shelf").build())
789 private static org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
790 .ServiceZEndBuilder getServiceZEndBuild() {
791 return new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
792 .ServiceZEndBuilder()
793 .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-1-2")
795 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
796 .endpoint.TxDirectionBuilder()
797 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
798 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
799 .setPortSubSlot("port subslot").setPortType("port type").build())
800 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
801 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
802 .setLgxPortShelf("lgx port shelf").build())
805 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service
806 .endpoint.RxDirectionBuilder()
807 .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name")
808 .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot")
809 .setPortSubSlot("port subslot").setPortType("port type").build())
810 .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name")
811 .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack")
812 .setLgxPortShelf("lgx port shelf").build())
817 public void deleteServiceInvalidIfServiceNameIsEmpty() throws ExecutionException, InterruptedException {
819 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
820 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
821 serviceDeleteInput = builder
822 .setServiceDeleteReqInfo(
823 new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName("").build())
825 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
826 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
827 ResponseCodes.FINAL_ACK_YES);
828 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
832 public void deleteServiceInvalidIfServiceNameIsNull() throws ExecutionException, InterruptedException {
834 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
835 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
836 serviceDeleteInput = builder
837 .setServiceDeleteReqInfo(
838 new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName(null).build())
840 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
841 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
842 ResponseCodes.FINAL_ACK_YES);
843 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
847 public void deleteServiceInvalidIfSdncRequestHeaderIsNull() throws ExecutionException, InterruptedException {
848 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
849 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
850 serviceDeleteInput = builder.setSdncRequestHeader(null).build();
851 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
852 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
853 ResponseCodes.FINAL_ACK_YES);
854 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
858 public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsNull()
859 throws ExecutionException, InterruptedException {
861 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
862 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
863 serviceDeleteInput = builder
864 .setSdncRequestHeader(
865 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId(null).build())
867 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
868 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
869 ResponseCodes.FINAL_ACK_YES);
870 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
874 public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsEmpty()
875 throws ExecutionException, InterruptedException {
877 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
878 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
879 serviceDeleteInput = builder.setSdncRequestHeader(
880 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId("").build()).build();
881 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
882 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
883 ResponseCodes.FINAL_ACK_YES);
884 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
888 public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNull()
889 throws ExecutionException, InterruptedException {
891 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
892 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
893 serviceDeleteInput = builder
894 .setSdncRequestHeader(
895 new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRpcAction(null).build())
897 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
898 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
899 ResponseCodes.FINAL_ACK_YES);
900 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
904 public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNotDelete()
905 throws ExecutionException, InterruptedException {
907 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
908 ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput);
909 serviceDeleteInput = builder.setSdncRequestHeader(new SdncRequestHeaderBuilder(builder.getSdncRequestHeader())
910 .setRpcAction(RpcActions.ServiceCreate).build()).build();
911 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult();
912 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
913 ResponseCodes.FINAL_ACK_YES);
914 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
918 public void deleteServiceIfServiceHandlerCompliancyCheckNotPassed()
919 throws ExecutionException, InterruptedException {
921 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
922 ComplianceCheckResult res = new ComplianceCheckResult(false, "");
924 Mockito.when(this.complianceCheckResultMock.hasPassed()).thenReturn(false);
926 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
927 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
928 ResponseCodes.FINAL_ACK_YES);
929 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
933 public void deleteServiceNotPresent() throws ExecutionException, InterruptedException {
935 ServiceDeleteOutput result = this.serviceHandler.serviceDelete(buildNotPresentServiceDeleteInput()).get()
937 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
938 ResponseCodes.FINAL_ACK_YES);
939 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
943 public void deleteServiceIfServiceNotPresent() throws ExecutionException, InterruptedException {
945 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
946 Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false);
947 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
948 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
949 ResponseCodes.FINAL_ACK_YES);
950 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
954 public void deleteServiceNotPassed() throws ExecutionException, InterruptedException {
956 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
957 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
958 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
959 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
960 .ServiceDeleteInput input = ModelMappingUtils
961 .createServiceDeleteInput(serviceDeleteInput);
962 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
963 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
964 .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("success").build();
965 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
966 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
967 .servicepath.rev170426.ServiceDeleteOutputBuilder()
968 .setConfigurationResponseCommon(configurationResponseCommon).build();
969 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
970 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
971 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
972 ResponseCodes.FINAL_ACK_YES);
973 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED);
977 public void deleteServicePathNotPassed() throws ExecutionException, InterruptedException {
979 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
980 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
981 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
982 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
983 .ServiceDeleteInput input = ModelMappingUtils
984 .createServiceDeleteInput(serviceDeleteInput);
985 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
986 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
987 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
988 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
989 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
990 .servicepath.rev170426.ServiceDeleteOutputBuilder()
991 .setConfigurationResponseCommon(configurationResponseCommon).build();
992 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
993 Mockito.when(this.serviceDataStoreOperationsMock
994 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
995 .thenReturn(OperationResult.failed("failed"));
996 Mockito.when(this.serviceDataStoreOperationsMock
997 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
998 .thenReturn(OperationResult.failed("failed"));
999 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1000 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1001 ResponseCodes.FINAL_ACK_YES);
1002 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1006 public void deleteServiceOperationNotPassed() throws ExecutionException, InterruptedException {
1008 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
1009 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1010 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1011 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
1012 .ServiceDeleteInput input = ModelMappingUtils
1013 .createServiceDeleteInput(serviceDeleteInput);
1014 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1015 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1016 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1017 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
1018 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1019 .servicepath.rev170426.ServiceDeleteOutputBuilder()
1020 .setConfigurationResponseCommon(configurationResponseCommon).build();
1021 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
1022 Mockito.when(this.serviceDataStoreOperationsMock
1023 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1024 .thenReturn(OperationResult.ok("success"));
1025 Mockito.when(this.serviceDataStoreOperationsMock
1026 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1027 .thenReturn(OperationResult.ok("success"));
1028 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1029 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1030 ResponseCodes.FINAL_ACK_YES);
1031 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1035 public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException {
1037 ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput();
1038 Optional<Services> service = Optional.of(new ServicesBuilder().setServiceName("service 1").build());
1039 Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service);
1040 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
1041 .ServiceDeleteInput input = ModelMappingUtils
1042 .createServiceDeleteInput(serviceDeleteInput);
1043 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1044 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1")
1045 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build();
1046 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
1047 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1048 .servicepath.rev170426.ServiceDeleteOutputBuilder()
1049 .setConfigurationResponseCommon(configurationResponseCommon).build();
1050 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output);
1051 Mockito.when(this.serviceDataStoreOperationsMock
1052 .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1053 .thenReturn(OperationResult.ok("success"));
1054 Mockito.when(this.serviceDataStoreOperationsMock
1055 .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName()))
1056 .thenReturn(OperationResult.ok("success"));
1057 ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult();
1058 Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(),
1059 ResponseCodes.FINAL_ACK_YES);
1060 Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK);
1063 private ServiceDeleteInput buildPresentServiceDeleteInput() {
1064 ServiceCreateInput serviceInput = buildServiceCreateInput();
1065 Future<RpcResult<ServiceCreateOutput>> output0 = this.serviceHandler.serviceCreate(serviceInput);
1066 ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
1067 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
1068 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
1069 DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
1070 deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("service 1")
1071 .setDueDate(datetime).setTailRetention(ServiceDeleteReqInfo.TailRetention.No).build());
1072 SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder();
1073 sdncBuilder.setNotificationUrl("notification url");
1074 sdncBuilder.setRequestId("request 1");
1075 sdncBuilder.setRequestSystemId("request system 1");
1076 sdncBuilder.setRpcAction(RpcActions.ServiceDelete);
1077 deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
1078 return deleteInputBldr.build();
1081 private ServiceDeleteInput buildNotPresentServiceDeleteInput() {
1082 ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
1083 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
1084 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
1085 DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
1086 deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("service 2")
1087 .setDueDate(datetime).setTailRetention(ServiceDeleteReqInfo.TailRetention.No).build());
1088 SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder();
1089 sdncBuilder.setNotificationUrl("notification url");
1090 sdncBuilder.setRequestId("request 1");
1091 sdncBuilder.setRequestSystemId("request system 1");
1092 sdncBuilder.setRpcAction(RpcActions.ServiceDelete);
1093 deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
1094 return deleteInputBldr.build();