From 0c65e4dc6476c3817b8873db69603d5e2ef0cacd Mon Sep 17 00:00:00 2001 From: "doha.khaled" Date: Thu, 14 Jun 2018 13:35:19 +0200 Subject: [PATCH] ServiceHandler unit tests init Change-Id: I4cd1989fea6971e7d06874978fe05d33407c0f78 Signed-off-by: guillaume.lambert Signed-off-by: doha.khaled --- deploy-site.iml | 6 + servicehandler/pom.xml | 1 + .../impl/ServiceHandlerImplTest.java | 1096 +++++++++++++++++ .../mappers/PathDescriptionConverter.java | 34 + .../mappers/ServiceAEndConverter.java | 42 + .../mappers/ServiceDeleteInputConverter.java | 34 + .../mappers/ServiceDeleteOutputConverter.java | 37 + ...ceImplementationRequestInputConverter.java | 40 + ...eImplementationRequestOutputConverter.java | 32 + .../mappers/ServiceZEndConverter.java | 43 + .../stub/StubRendererServiceOperations.java | 65 + .../org.mockito.plugins.MockMaker | 1 + 12 files changed, 1431 insertions(+) create mode 100644 deploy-site.iml create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java create mode 100644 servicehandler/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/deploy-site.iml b/deploy-site.iml new file mode 100644 index 000000000..7f43ada9d --- /dev/null +++ b/deploy-site.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/servicehandler/pom.xml b/servicehandler/pom.xml index 22835be82..43085f679 100644 --- a/servicehandler/pom.xml +++ b/servicehandler/pom.xml @@ -101,6 +101,7 @@ Author: Martial Coulibaly on behalf of Orange org.mockito mockito-core + 2.19.0 test diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java new file mode 100644 index 000000000..5be6576e3 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java @@ -0,0 +1,1096 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.impl; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.pce.service.PathComputationService; +import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl; +import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock; +import org.opendaylight.transportpce.pce.utils.PceTestData; +import org.opendaylight.transportpce.pce.utils.PceTestUtils; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; +import org.opendaylight.transportpce.servicehandler.ServiceEndpointType; +import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; +import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult; +import org.opendaylight.transportpce.test.AbstractTest; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServiceHandlerImplTest extends AbstractTest { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class); + + private NotificationPublishService notificationPublishService; + private PathComputationService pathComputationService; + private RendererServiceOperations rendererServiceOperations; + private ServicehandlerImpl serviceHandler; + + @Mock + private ServiceDataStoreOperations serviceDataStoreOperationsMock; + + @Mock + private PCEServiceWrapper pceServiceWrapperMock; + + @Mock + private RendererServiceOperations rendererServiceOperationsMock; + + @Mock + private ComplianceCheckResult complianceCheckResultMock; + + @Mock + private Optional servicesOptionalMock; + + @InjectMocks + private ServicehandlerImpl serviceHandlerImplMock; + + @Before + public void setUp() throws Exception { + this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, + this.rendererServiceOperations); + this.serviceHandlerImplMock = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null); + MockitoAnnotations.initMocks(this); + } + + public ServiceHandlerImplTest() throws Exception { + this.notificationPublishService = new NotificationPublishServiceMock(); + this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), this.notificationPublishService); + PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), + "topologyData/NW-simple-topology.xml"); + this.rendererServiceOperations = new StubRendererServiceOperations(this.notificationPublishService); + } + + @Test + public void testCreateServiceValid() throws ExecutionException, InterruptedException { + + ServiceCreateInput serviceInput = buildServiceCreateInput(); + + Future> output0 = this.serviceHandler.serviceCreate(serviceInput); + Assert.assertNotNull(output0); + Assert.assertTrue(output0.get().isSuccessful()); + Assert.assertEquals(output0.get().getResult(), + ModelMappingUtils.createCreateServiceReply(serviceInput, ResponseCodes.FINAL_ACK_YES, + "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get().getResult()); + Assert.assertEquals(0, output0.get().getErrors().size()); + } + + @Test + public void createServiceHandlerInvalidIfNameIsEmpty() throws ExecutionException, InterruptedException { + ServiceCreateInput emptyServiceNameInput = buildServiceCreateInput(); + ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyServiceNameInput); + emptyServiceNameInput = builtInput.setServiceName("").build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceNameInput).get().getResult(), + ModelMappingUtils.createCreateServiceReply(emptyServiceNameInput, ResponseCodes.FINAL_ACK_YES, + "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerInvalidIfNameIsNull() throws ExecutionException, InterruptedException { + ServiceCreateInput nullServiceNameInput = buildServiceCreateInput(); + ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(nullServiceNameInput); + nullServiceNameInput = builtInput.setServiceName(null).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(nullServiceNameInput).get().getResult(), + ModelMappingUtils.createCreateServiceReply(nullServiceNameInput, ResponseCodes.FINAL_ACK_YES, + "Service Name is not set", ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHnadlerInvalidIfConTypeIsEmpty() throws ExecutionException, InterruptedException { + ServiceCreateInput emptyConTypeInput = buildServiceCreateInput(); + ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(emptyConTypeInput); + emptyConTypeInput = builtInput.setConnectionType(null).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(emptyConTypeInput).get().getResult(), + ModelMappingUtils.createCreateServiceReply(emptyConTypeInput, ResponseCodes.FINAL_ACK_YES, + "Service ConnectionType is not set", ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerInvalidIfSdncRequestHeaderNull() throws ExecutionException, InterruptedException { + ServiceCreateInput emptySdncRequestHeader = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptySdncRequestHeader); + emptySdncRequestHeader = buildInput.setSdncRequestHeader(null).build(); + ServiceCreateOutput result = this.serviceHandler.serviceCreate(emptySdncRequestHeader).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + } + + @Test + public void createServiceHandlerInvalidIfRequestIdEmpty() throws ExecutionException, InterruptedException { + ServiceCreateInput emptyRequestId = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyRequestId); + emptyRequestId = buildInput + .setSdncRequestHeader( + new SdncRequestHeaderBuilder(emptyRequestId.getSdncRequestHeader()).setRequestId("").build()) + .build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(emptyRequestId).get().getResult(), + ModelMappingUtils + .createCreateServiceReply(emptyRequestId, ResponseCodes.FINAL_ACK_YES, + "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED) + .get().getResult()); + } + + @Test + public void createServiceHandlerInvalidIfRequestIdNull() throws ExecutionException, InterruptedException { + ServiceCreateInput nullRequestId = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(nullRequestId); + nullRequestId = buildInput + .setSdncRequestHeader( + new SdncRequestHeaderBuilder(nullRequestId.getSdncRequestHeader()).setRequestId(null).build()) + .build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(nullRequestId).get().getResult(), + ModelMappingUtils + .createCreateServiceReply(nullRequestId, ResponseCodes.FINAL_ACK_YES, + "Service sdncRequestHeader 'request-id' is not set", ResponseCodes.RESPONSE_FAILED) + .get().getResult()); + } + + @Test + public void serviceHandlerInvalidServiceActionIsNull() throws ExecutionException, InterruptedException { + ServiceCreateInput emptyServiceAction = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(emptyServiceAction); + emptyServiceAction = buildInput.setSdncRequestHeader( + new SdncRequestHeaderBuilder(emptyServiceAction.getSdncRequestHeader()).setRpcAction(null).build()) + .build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(emptyServiceAction).get().getResult(), + ModelMappingUtils + .createCreateServiceReply(emptyServiceAction, ResponseCodes.FINAL_ACK_YES, + "Service sndc-request-header 'rpc-action' is not set ", ResponseCodes.RESPONSE_FAILED) + .get().getResult()); + } + + @Test + public void serviceHandlerInvalidServiceActionIsNotCreate() throws ExecutionException, InterruptedException { + ServiceCreateInput notCreateServiceAction = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notCreateServiceAction); + notCreateServiceAction = buildInput + .setSdncRequestHeader(new SdncRequestHeaderBuilder(notCreateServiceAction.getSdncRequestHeader()) + .setRpcAction(RpcActions.ServiceFeasibilityCheck).build()) + .build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(notCreateServiceAction).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notCreateServiceAction, ResponseCodes.FINAL_ACK_YES, + "Service sdncRequestHeader rpc-action '" + + notCreateServiceAction.getSdncRequestHeader().getRpcAction() + "' not equal to '" + + RpcActions.ServiceCreate.name() + "'", + ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceAEndIsNull() throws ExecutionException, InterruptedException { + ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd); + notValidServiceAEnd = buildInput.setServiceAEnd(null).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES, + "SERVICEAEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceZEndIsNull() throws ExecutionException, InterruptedException { + ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd); + notValidServiceAEnd = buildInput.setServiceZEnd(null).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES, + "SERVICEZEND is not set", ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null); + ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd); + notValidServiceAEnd = buildInput.setServiceAEnd(getServiceAEndBuild().setServiceRate(null).build()).build(); + Assert.assertEquals(servicehandler.serviceCreate(notValidServiceAEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES, + "Service " + ServiceEndpointType.SERVICEAEND + " rate is not set", + ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null); + ServiceCreateInput notValidServiceZEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd); + notValidServiceZEnd = buildInput.setServiceZEnd(getServiceZEndBuild().setServiceRate(null).build()).build(); + Assert.assertEquals(servicehandler.serviceCreate(notValidServiceZEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES, + "Service " + ServiceEndpointType.SERVICEZEND + " rate is not set", + ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceAEndClliIsNull() + throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException { + ServiceCreateInput notValidServiceAEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd); + notValidServiceAEnd = buildInput.setServiceAEnd(getServiceAEndBuild().setClli(null).build()).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceAEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceAEnd, ResponseCodes.FINAL_ACK_YES, + "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set", + ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceZEndClliIsNull() + throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException { + ServiceCreateInput notValidServiceZEnd = buildServiceCreateInput(); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd); + notValidServiceZEnd = buildInput.setServiceZEnd(getServiceZEndBuild().setClli(null).build()).build(); + Assert.assertEquals(this.serviceHandler.serviceCreate(notValidServiceZEnd).get().getResult(), + ModelMappingUtils.createCreateServiceReply(notValidServiceZEnd, ResponseCodes.FINAL_ACK_YES, + "Service" + ServiceEndpointType.SERVICEZEND + " clli format is not set", + ResponseCodes.RESPONSE_FAILED).get().getResult()); + } + + @Test + public void createServiceHandlerNotValidServiceAEndAttributes() + throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException { + HashMap notValidData = new HashMap<>(); + notValidData.put("setServiceRate", 0L); + notValidData.put("setServiceFormat", null); + notValidData.put("setClli", ""); + notValidData.put("setTxDirection", null); + notValidData.put("setRxDirection", null); + for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder.class.getDeclaredMethods()) { + if (notValidData.containsKey(method.getName())) { + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(buildServiceCreateInput()); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild(); + method.invoke(serviceAEndBuilder, notValidData.get(method.getName())); + ServiceCreateOutput result = this.serviceHandler + .serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + + @Test + public void createServiceHandlerNotValidServiceZEndAttributes() + throws ExecutionException, InterruptedException, InvocationTargetException, IllegalAccessException { + HashMap notValidData = new HashMap<>(); + notValidData.put("setServiceRate", 0L); + notValidData.put("setServiceFormat", null); + notValidData.put("setClli", ""); + notValidData.put("setTxDirection", null); + notValidData.put("setRxDirection", null); + for (Method method : org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceZEndBuilder.class.getDeclaredMethods()) { + if (notValidData.containsKey(method.getName())) { + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(buildServiceCreateInput()); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceZEndBuilder serviceZEndBuilder = getServiceZEndBuild(); + method.invoke(serviceZEndBuilder, notValidData.get(method.getName())); + ServiceCreateOutput result = this.serviceHandler + .serviceCreate(buildInput.setServiceZEnd(serviceZEndBuilder.build()).build()).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + + @Test + public void createServiceHandlerNotValidTxDirectionPort() + throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException { + List invalidData = Arrays.asList(null, ""); + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + for (Method method : PortBuilder.class.getMethods()) { + if (method.getName().startsWith("set") && !method.getName().contains("Slot")) { + for (Object data : invalidData) { + PortBuilder portBuilder = new PortBuilder( + serviceCreateInput.getServiceAEnd().getTxDirection().getPort()); + method.invoke(portBuilder, data); + ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(portBuilder.build(), + serviceCreateInput.getServiceAEnd().getTxDirection().getLgx()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + } + + @Test + public void createServiceHandlerTxDirectionPortIsNull() throws ExecutionException, InterruptedException { + ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput(null, + buildServiceCreateInput().getServiceAEnd().getTxDirection().getLgx()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void createServiceHandlerNotValidTxDirectionLgx() + throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException { + List invalidData = Arrays.asList(null, ""); + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + for (Method method : LgxBuilder.class.getMethods()) { + if (method.getName().startsWith("set")) { + for (Object data : invalidData) { + LgxBuilder lgxBuilder = new LgxBuilder( + serviceCreateInput.getServiceAEnd().getTxDirection().getLgx()); + method.invoke(lgxBuilder, data); + ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput( + serviceCreateInput.getServiceAEnd().getTxDirection().getPort(), lgxBuilder.build()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + } + + @Test + public void createServiceHandlerTxDirectionLgxIsNull() throws ExecutionException, InterruptedException { + ServiceCreateOutput result = getTxDirectionPortServiceCreateOutput( + buildServiceCreateInput().getServiceAEnd().getTxDirection().getPort(), null); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + private ServiceCreateOutput getTxDirectionPortServiceCreateOutput(Port port, Lgx lgx) + throws InterruptedException, ExecutionException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild(); + TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder( + serviceCreateInput.getServiceAEnd().getTxDirection()); + txDirectionBuilder.setPort(port); + txDirectionBuilder.setLgx(lgx); + serviceAEndBuilder.setTxDirection(txDirectionBuilder.build()); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput); + ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null); + return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get() + .getResult(); + } + + @Test + public void createServiceHandlerNotValidRxDirectionPort() + throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException { + List invalidData = Arrays.asList(null, ""); + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + for (Method method : PortBuilder.class.getMethods()) { + if (method.getName().startsWith("set") && !method.getName().contains("Slot")) { + for (Object data : invalidData) { + PortBuilder portBuilder = new PortBuilder( + serviceCreateInput.getServiceAEnd().getRxDirection().getPort()); + method.invoke(portBuilder, data); + ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(portBuilder.build(), + serviceCreateInput.getServiceAEnd().getRxDirection().getLgx()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + } + + @Test + public void createServiceHandlerRxDirectionPortIsNull() + throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException { + ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput(null, + buildServiceCreateInput().getServiceAEnd().getRxDirection().getLgx()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void createServiceHandlerNotValidRxDirectionLgx() + throws InvocationTargetException, IllegalAccessException, ExecutionException, InterruptedException { + List invalidData = Arrays.asList(null, ""); + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + for (Method method : LgxBuilder.class.getMethods()) { + if (method.getName().startsWith("set")) { + for (Object data : invalidData) { + LgxBuilder lgxBuilder = new LgxBuilder( + serviceCreateInput.getServiceAEnd().getRxDirection().getLgx()); + method.invoke(lgxBuilder, data); + ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput( + serviceCreateInput.getServiceAEnd().getRxDirection().getPort(), lgxBuilder.build()); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), + ResponseCodes.RESPONSE_FAILED); + } + } + } + } + + @Test + public void createServiceHandlerRxDirectionLgxIsNull() throws ExecutionException, InterruptedException { + ServiceCreateOutput result = getRxDirectionPortServiceCreateOutput( + buildServiceCreateInput().getServiceAEnd().getRxDirection().getPort(), null); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failed").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true); + } + + @Test + public void createServiceHandlerOperationResultNotPassed() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))) + .thenReturn(OperationResult.failed( + "Failed to create service " + serviceCreateInput.getServiceName() + " to Service List")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class)); + } + + @Test + public void createServiceHandlerOperationServicePathSaveResultNotPassed() + throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))) + .thenReturn(OperationResult.failed("Failed to create servicePath " + serviceCreateInput.getServiceName() + + " to ServicePath List")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class)); + } + + @Test + public void createServiceHandlerModifyServicePassed() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); + + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build()); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(), + State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService, + State.InService); + } + + @Test + public void createServiceHandlerModifyServiceNotPassed() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); + + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build()); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(), + State.InService, State.InService)).thenReturn(OperationResult.failed("failure")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService, + State.InService); + } + + @Test + public void createServiceHandlerServiceImplementationNotPassed() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build(); + + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName())) + .thenReturn(OperationResult.ok("successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName())) + .thenReturn(OperationResult.ok("successful")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName()); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName()); + } + + @Test + public void createServiceHandlerServiceImplementationNotPassed2() throws ExecutionException, InterruptedException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build(); + + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName())) + .thenReturn(OperationResult.failed("successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName())) + .thenReturn(OperationResult.failed("successful")); + ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName()); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName()); + } + + private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx) + throws InterruptedException, ExecutionException { + ServiceCreateInput serviceCreateInput = buildServiceCreateInput(); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder serviceAEndBuilder = getServiceAEndBuild(); + RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder( + serviceCreateInput.getServiceAEnd().getRxDirection()); + rxDirectionBuilder.setPort(port); + rxDirectionBuilder.setLgx(lgx); + serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build()); + ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput); + ServicehandlerImpl serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null); + return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get() + .getResult(); + } + + private static ServiceCreateInput buildServiceCreateInput() { + + ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder(); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEnd serviceAEnd = getServiceAEndBuild() + .build(); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service + .create.input.ServiceZEndBuilder() + .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-3-2") + .setTxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.TxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()) + .setRxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.RxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()) + .build(); + + builtInput.setCommonId("commonId"); + builtInput.setConnectionType(ConnectionType.Service); + builtInput.setCustomer("Customer"); + builtInput.setServiceName("service 1"); + builtInput.setServiceAEnd(serviceAEnd); + builtInput.setServiceZEnd(serviceZEnd); + builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request 1") + .setRpcAction(RpcActions.ServiceCreate).build()); + + return builtInput.build(); + } + + private static org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder getServiceAEndBuild() { + return new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceAEndBuilder() + .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-1-2") + .setTxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.TxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()) + .setRxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.RxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()); + } + + private static org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceZEndBuilder getServiceZEndBuild() { + return new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input + .ServiceZEndBuilder() + .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-1-2") + .setTxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.TxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()) + .setRxDirection( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .endpoint.RxDirectionBuilder() + .setPort(new PortBuilder().setPortDeviceName("device name").setPortName("port name") + .setPortRack("port rack").setPortShelf("port shelf").setPortSlot("port slot") + .setPortSubSlot("port subslot").setPortType("port type").build()) + .setLgx(new LgxBuilder().setLgxDeviceName("lgx device name") + .setLgxPortName("lgx port name").setLgxPortRack("lgx port rack") + .setLgxPortShelf("lgx port shelf").build()) + .build()); + } + + @Test + public void deleteServiceInvalidIfServiceNameIsEmpty() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder + .setServiceDeleteReqInfo( + new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName("").build()) + .build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfServiceNameIsNull() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder + .setServiceDeleteReqInfo( + new ServiceDeleteReqInfoBuilder(builder.getServiceDeleteReqInfo()).setServiceName(null).build()) + .build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfSdncRequestHeaderIsNull() throws ExecutionException, InterruptedException { + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder.setSdncRequestHeader(null).build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsNull() + throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder + .setSdncRequestHeader( + new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId(null).build()) + .build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfSdncRequestHeaderRequestIdIsEmpty() + throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder.setSdncRequestHeader( + new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRequestId("").build()).build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNull() + throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder + .setSdncRequestHeader( + new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()).setRpcAction(null).build()) + .build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceInvalidIfSdncRequestHeaderServiceActionIsNotDelete() + throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(serviceDeleteInput); + serviceDeleteInput = builder.setSdncRequestHeader(new SdncRequestHeaderBuilder(builder.getSdncRequestHeader()) + .setRpcAction(RpcActions.ServiceCreate).build()).build(); + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceIfServiceHandlerCompliancyCheckNotPassed() + throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + ComplianceCheckResult res = new ComplianceCheckResult(false, ""); + + Mockito.when(this.complianceCheckResultMock.hasPassed()).thenReturn(false); + + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceNotPresent() throws ExecutionException, InterruptedException { + + ServiceDeleteOutput result = this.serviceHandler.serviceDelete(buildNotPresentServiceDeleteInput()).get() + .getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceIfServiceNotPresent() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + Mockito.when(this.servicesOptionalMock.isPresent()).thenReturn(false); + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServiceNotPassed() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput input = ModelMappingUtils + .createServiceDeleteInput(serviceDeleteInput); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("success").build(); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output); + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); + } + + @Test + public void deleteServicePathNotPassed() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput input = ModelMappingUtils + .createServiceDeleteInput(serviceDeleteInput); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.failed("failed")); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.failed("failed")); + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + } + + @Test + public void deleteServiceOperationNotPassed() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput input = ModelMappingUtils + .createServiceDeleteInput(serviceDeleteInput); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + } + + @Test + public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException { + + ServiceDeleteInput serviceDeleteInput = buildPresentServiceDeleteInput(); + Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput input = ModelMappingUtils + .createServiceDeleteInput(serviceDeleteInput); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); + Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), + ResponseCodes.FINAL_ACK_YES); + Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + } + + private ServiceDeleteInput buildPresentServiceDeleteInput() { + ServiceCreateInput serviceInput = buildServiceCreateInput(); + Future> output0 = this.serviceHandler.serviceCreate(serviceInput); + ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("service 1") + .setDueDate(datetime).setTailRetention(ServiceDeleteReqInfo.TailRetention.No).build()); + SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder(); + sdncBuilder.setNotificationUrl("notification url"); + sdncBuilder.setRequestId("request 1"); + sdncBuilder.setRequestSystemId("request system 1"); + sdncBuilder.setRpcAction(RpcActions.ServiceDelete); + deleteInputBldr.setSdncRequestHeader(sdncBuilder.build()); + return deleteInputBldr.build(); + } + + private ServiceDeleteInput buildNotPresentServiceDeleteInput() { + ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("service 2") + .setDueDate(datetime).setTailRetention(ServiceDeleteReqInfo.TailRetention.No).build()); + SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder(); + sdncBuilder.setNotificationUrl("notification url"); + sdncBuilder.setRequestId("request 1"); + sdncBuilder.setRequestSystemId("request system 1"); + sdncBuilder.setRpcAction(RpcActions.ServiceDelete); + deleteInputBldr.setSdncRequestHeader(sdncBuilder.build()); + return deleteInputBldr.build(); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java new file mode 100644 index 000000000..92d8f3a25 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.PathDescriptionBuilder; + +public class PathDescriptionConverter { + + public static PathDescription getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.service.implementation.request.input.PathDescription concrete) { + PathDescriptionBuilder stubBuilder = new PathDescriptionBuilder(); + stubBuilder.setAToZDirection(concrete.getAToZDirection()); + stubBuilder.setZToADirection(concrete.getZToADirection()); + return stubBuilder.build(); + } + + + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service + .implementation.request.input.PathDescription getConcrete(PathDescription stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service + .implementation.request.input.PathDescriptionBuilder concreteBuilder = new org.opendaylight.yang.gen.v1 + .http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation.request.input + .PathDescriptionBuilder(); + concreteBuilder.setAToZDirection(stub.getAToZDirection()); + concreteBuilder.setZToADirection(stub.getZToADirection()); + return concreteBuilder.build(); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java new file mode 100644 index 000000000..79439a7d1 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceAEnd; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceAEndBuilder; + +public class ServiceAEndConverter { + + public static ServiceAEnd getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath + .rev170426.service.implementation.request.input.ServiceAEnd concrete) { + ServiceAEndBuilder stubBuilder = new ServiceAEndBuilder(); + stubBuilder.setClli(concrete.getClli()); + stubBuilder.setNodeId(concrete.getNodeId()); + stubBuilder.setRxDirection(concrete.getRxDirection()); + stubBuilder.setServiceFormat(concrete.getServiceFormat()); + stubBuilder.setServiceRate(concrete.getServiceRate()); + stubBuilder.setTxDirection(concrete.getTxDirection()); + return stubBuilder.build(); + } + + + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service + .implementation.request.input.ServiceAEnd getConcrete(ServiceAEnd stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation + .request.input.ServiceAEndBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org + .transportpce.b.c._interface.servicepath.rev170426.service.implementation.request.input + .ServiceAEndBuilder(); + concreteBuilder.setClli(stub.getClli()); + concreteBuilder.setNodeId(stub.getNodeId()); + concreteBuilder.setRxDirection(stub.getRxDirection()); + concreteBuilder.setServiceFormat(stub.getServiceFormat()); + concreteBuilder.setServiceRate(stub.getServiceRate()); + concreteBuilder.setTxDirection(stub.getTxDirection()); + return concreteBuilder.build(); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java new file mode 100644 index 000000000..1f4b59e6b --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInputBuilder; + +public class ServiceDeleteInputConverter { + + public static ServiceDeleteInput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteInput concrete) { + ServiceDeleteInputBuilder stubBuilder = new ServiceDeleteInputBuilder(); + stubBuilder.setServiceHandlerHeader(concrete.getServiceHandlerHeader()); + stubBuilder.setServiceName(concrete.getServiceName()); + return stubBuilder.build(); + } + + + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput getConcrete(ServiceDeleteInput stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org.transportpce + .b.c._interface.servicepath.rev170426.ServiceDeleteInputBuilder(); + concreteBuilder.setServiceHandlerHeader(stub.getServiceHandlerHeader()); + concreteBuilder.setServiceName(stub.getServiceName()); + return concreteBuilder.build(); + } + +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java new file mode 100644 index 000000000..9de86cf78 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder; + +public class ServiceDeleteOutputConverter { + + public static ServiceDeleteOutput + getStub( + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput + concrete + ) { + ServiceDeleteOutputBuilder stubBuilder = new ServiceDeleteOutputBuilder(); + stubBuilder.setConfigurationResponseCommon(concrete.getConfigurationResponseCommon()); + return stubBuilder.build(); + } + + + public static + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput + getConcrete(ServiceDeleteOutput stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutputBuilder concreteBuilder = + new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutputBuilder(); + concreteBuilder.setConfigurationResponseCommon(stub.getConfigurationResponseCommon()); + return concreteBuilder.build(); + } + +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java new file mode 100644 index 000000000..cea7a31c4 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInputBuilder; + +public class ServiceImplementationRequestInputConverter { + + public static ServiceImplementationRequestInput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce + .b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput concrete) { + ServiceImplementationRequestInputBuilder stubBuilder = new ServiceImplementationRequestInputBuilder(); + stubBuilder.setServiceHandlerHeader(concrete.getServiceHandlerHeader()); + stubBuilder.setPathDescription(PathDescriptionConverter.getStub(concrete.getPathDescription())); + stubBuilder.setServiceName(concrete.getServiceName()); + stubBuilder.setServiceAEnd(ServiceAEndConverter.getStub(concrete.getServiceAEnd())); + stubBuilder.setServiceZEnd(ServiceZEndConverter.getStub(concrete.getServiceZEnd())); + return stubBuilder.build(); + } + + + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceImplementationRequestInput getConcrete(ServiceImplementationRequestInput stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceImplementationRequestInputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org + .transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInputBuilder(); + concreteBuilder.setServiceHandlerHeader(stub.getServiceHandlerHeader()); + concreteBuilder.setPathDescription(PathDescriptionConverter.getConcrete(stub.getPathDescription())); + concreteBuilder.setServiceName(stub.getServiceName()); + concreteBuilder.setServiceAEnd(ServiceAEndConverter.getConcrete(stub.getServiceAEnd())); + concreteBuilder.setServiceZEnd(ServiceZEndConverter.getConcrete(stub.getServiceZEnd())); + return concreteBuilder.build(); + } + +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java new file mode 100644 index 000000000..d44e4848f --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutputBuilder; + +public class ServiceImplementationRequestOutputConverter { + + public static ServiceImplementationRequestOutput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce + .b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput concrete) { + ServiceImplementationRequestOutputBuilder stubBuilder = new ServiceImplementationRequestOutputBuilder(); + stubBuilder.setConfigurationResponseCommon(concrete.getConfigurationResponseCommon()); + return stubBuilder.build(); + } + + + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceImplementationRequestOutput getConcrete(ServiceImplementationRequestOutput stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceImplementationRequestOutputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org + .transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder(); + concreteBuilder.setConfigurationResponseCommon(stub.getConfigurationResponseCommon()); + return concreteBuilder.build(); + } + +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java new file mode 100644 index 000000000..ed76c320c --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.mappers; + +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceZEnd; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceZEndBuilder; + +public class ServiceZEndConverter { + public static ServiceZEnd getStub( + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation + .request.input.ServiceZEnd concrete) { + ServiceZEndBuilder stubBuilder = new ServiceZEndBuilder(); + stubBuilder.setClli(concrete.getClli()); + stubBuilder.setNodeId(concrete.getNodeId()); + stubBuilder.setRxDirection(concrete.getRxDirection()); + stubBuilder.setServiceFormat(concrete.getServiceFormat()); + stubBuilder.setServiceRate(concrete.getServiceRate()); + stubBuilder.setTxDirection(concrete.getTxDirection()); + return stubBuilder.build(); + } + + + public static + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation + .request.input.ServiceZEnd getConcrete(ServiceZEnd stub) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation + .request.input.ServiceZEndBuilder concreteBuilder = + new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service + .implementation.request.input.ServiceZEndBuilder(); + concreteBuilder.setClli(stub.getClli()); + concreteBuilder.setNodeId(stub.getNodeId()); + concreteBuilder.setRxDirection(stub.getRxDirection()); + concreteBuilder.setServiceFormat(stub.getServiceFormat()); + concreteBuilder.setServiceRate(stub.getServiceRate()); + concreteBuilder.setTxDirection(stub.getTxDirection()); + return concreteBuilder.build(); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java new file mode 100644 index 000000000..6db468c39 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java @@ -0,0 +1,65 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.stub; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteInputConverter; +import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteOutputConverter; +import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestInputConverter; +import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestOutputConverter; +import org.opendaylight.transportpce.stubrenderer.impl.StubrendererImpl; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StubRendererServiceOperations implements RendererServiceOperations { + private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class); + private StubrendererImpl stubrenderer; + + public StubRendererServiceOperations(NotificationPublishService notificationPublishService) { + this.stubrenderer = new StubrendererImpl(notificationPublishService); + } + + @Override + public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) { + Future> rpcResultFuture = this.stubrenderer + .serviceImplementationRequest(ServiceImplementationRequestInputConverter.getStub(input)); + try { + return ServiceImplementationRequestOutputConverter.getConcrete(rpcResultFuture.get().getResult()); + } catch (InterruptedException e) { + LOG.error("RPC serviceImplementation failed !",e); + } catch (ExecutionException e) { + LOG.error("RPC serviceImplementation failed !",e); + } + return null; + } + + @Override + public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) { + Future> rpcResultFuture = this.stubrenderer + .serviceDelete(ServiceDeleteInputConverter.getStub(input)); + try { + return ServiceDeleteOutputConverter.getConcrete(rpcResultFuture.get().getResult()); + } catch (InterruptedException e) { + LOG.error("RPC serviceDelete failed !",e); + } catch (ExecutionException e) { + LOG.error("RPC serviceDelete failed !",e); + } + return null; + } +} diff --git a/servicehandler/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/servicehandler/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 000000000..ca6ee9cea --- /dev/null +++ b/servicehandler/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file -- 2.36.6