From 7e2a79d09429101a16fa1011770651a1880afd74 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Mon, 19 Mar 2018 15:40:51 +0100 Subject: GenericResourceApiProvider unit tests part 2. Unit tests for vnfTopologyOperation method Change-Id: I60c73f31eb070cf554e55779d1d18631ce9b7147 Issue-ID: SDNC-275 Signed-off-by: Jakub Dudycz --- .../northbound/GenericResourceApiProvider.java | 59 ++++--- .../ServiceTopologyOperationRPCTest.java | 32 ++-- .../northbound/VnfTopologyOperationRPCTest.java | 194 +++++++++++++++++++++ .../org/onap/sdnc/northbound/util/MDSALUtil.java | 77 +++++--- 4 files changed, 289 insertions(+), 73 deletions(-) create mode 100644 generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VnfTopologyOperationRPCTest.java (limited to 'generic-resource-api/provider') diff --git a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java index ba3f1b5f..021daddb 100644 --- a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java +++ b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java @@ -1,5 +1,8 @@ package org.onap.sdnc.northbound; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -9,7 +12,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; @@ -93,10 +95,6 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; - /** * Defines a base implementation for your provider. This class extends from a helper class which provides storage for * the most commonly used components of the MD-SAL. Additionally the base class provides some basic logging and @@ -704,7 +702,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC final String svcOperation = "vnf-topology-operation"; ServiceData serviceData; ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder(); - Properties parms = new Properties(); + Properties properties = new Properties(); log.info(CALLED_STR, svcOperation); // create a new response object @@ -727,7 +725,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC trySetSvcRequestId(input, responseBuilder); - if (hasInvalidVnf(input)) { + if (hasInvalidVnfId(input)) { log.debug("exiting {} because of null or empty vnf-id", svcOperation); responseBuilder.setResponseCode("404"); responseBuilder.setResponseMessage("invalid input, null or empty vnf-id"); @@ -770,34 +768,34 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input); VnfTopologyOperationInputBuilder inputBuilder = new VnfTopologyOperationInputBuilder(input); - GenericResourceApiUtil.toProperties(parms, inputBuilder.build()); + GenericResourceApiUtil.toProperties(properties, inputBuilder.build()); log.info(ADDING_OPERATIONAL_DATA_LOG, svcOperation, siid, operDataBuilder.build()); - GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder); + GenericResourceApiUtil.toProperties(properties, OPERATIONAL_DATA_PARAM, operDataBuilder); // Call SLI sync method // Get SvcLogicService reference - ResponseObject error = new ResponseObject("200", ""); + ResponseObject responseObject = new ResponseObject("200", ""); String ackFinal = "Y"; String serviceObjectPath = null; - Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error); + Properties respProps = tryGetProperties(svcOperation, properties, serviceDataBuilder, responseObject); if (respProps != null) { - error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM)); - error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM)); + responseObject.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM)); + responseObject.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM)); ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y"); serviceObjectPath = respProps.getProperty("vnf-object-path"); } - setServiceStatus(serviceStatusBuilder, error.getStatusCode(), error.getMessage(), ackFinal); + setServiceStatus(serviceStatusBuilder, responseObject.getStatusCode(), responseObject.getMessage(), ackFinal); serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete); serviceStatusBuilder.setRpcName(svcOperation); - if (failed(error)) { - responseBuilder.setResponseCode(error.getStatusCode()); - responseBuilder.setResponseMessage(error.getMessage()); + if (failed(responseObject)) { + responseBuilder.setResponseCode(responseObject.getStatusCode()); + responseBuilder.setResponseMessage(responseObject.getMessage()); responseBuilder.setAckFinalIndicator(ackFinal); ServiceBuilder serviceBuilder = new ServiceBuilder(); @@ -847,7 +845,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } catch (Exception e) { log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e); responseBuilder.setResponseCode("500"); - responseBuilder.setResponseMessage(e.toString()); + responseBuilder.setResponseMessage(e.getMessage()); responseBuilder.setAckFinalIndicator("Y"); log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build()); @@ -860,9 +858,9 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } // Update succeeded - responseBuilder.setResponseCode(error.getStatusCode()); + responseBuilder.setResponseCode(responseObject.getStatusCode()); responseBuilder.setAckFinalIndicator(ackFinal); - trySetResponseMessage(responseBuilder, error); + trySetResponseMessage(responseBuilder, responseObject); log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid); log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build()); @@ -892,7 +890,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } } - private boolean hasInvalidVnf(VnfTopologyOperationInput input) { + private boolean hasInvalidVnfId(VnfTopologyOperationInput input) { return input.getVnfInformation() == null || input.getVnfInformation().getVnfId() == null || input.getVnfInformation().getVnfId().length() == 0; } @@ -942,7 +940,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC return Futures.immediateFuture(rpcResult); } - if (hasInvalidVnf(input)) { + if (hasInvalidVnfId(input)) { log.debug("exiting {} because of null or empty vnf-id", svcOperation); responseBuilder.setResponseCode("403"); responseBuilder.setResponseMessage("invalid input, null or empty vnf-id"); @@ -1128,7 +1126,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC || input.getVfModuleInformation().getVfModuleId().length() == 0; } - private boolean hasInvalidVnf(VfModuleTopologyOperationInput input) { + private boolean hasInvalidVnfId(VfModuleTopologyOperationInput input) { return input.getVnfInformation() == null || input.getVnfInformation().getVnfId() == null || input.getVnfInformation().getVnfId().length() == 0; } @@ -1439,7 +1437,8 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC return Futures.immediateFuture(rpcResult); } - private void trySetResponseMessage(ContrailRouteTopologyOperationOutputBuilder responseBuilder, ResponseObject error) { + private void trySetResponseMessage(ContrailRouteTopologyOperationOutputBuilder responseBuilder, + ResponseObject error) { if (!error.getMessage().isEmpty()) { responseBuilder.setResponseMessage(error.getMessage()); } @@ -1469,7 +1468,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } private Future> - buildRpcResultFuture(ContrailRouteTopologyOperationOutputBuilder responseBuilder, String responseMessage) { + buildRpcResultFuture(ContrailRouteTopologyOperationOutputBuilder responseBuilder, String responseMessage) { responseBuilder.setResponseCode("404"); responseBuilder.setResponseMessage(responseMessage); @@ -1631,7 +1630,8 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC return Futures.immediateFuture(rpcResult); } - private void trySetResponseMessage(SecurityZoneTopologyOperationOutputBuilder responseBuilder, ResponseObject error) { + private void trySetResponseMessage(SecurityZoneTopologyOperationOutputBuilder responseBuilder, + ResponseObject error) { if (!error.getMessage().isEmpty()) { responseBuilder.setResponseMessage(error.getMessage()); } @@ -1665,7 +1665,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } private Future> - buildRpcResultFuture(SecurityZoneTopologyOperationOutputBuilder responseBuilder, String responseMessage) { + buildRpcResultFuture(SecurityZoneTopologyOperationOutputBuilder responseBuilder, String responseMessage) { responseBuilder.setResponseCode("404"); responseBuilder.setResponseMessage(responseMessage); @@ -1786,7 +1786,8 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC return Futures.immediateFuture(rpcResult); } - private void trySetResponseMessage(TunnelxconnTopologyOperationOutputBuilder responseBuilder, ResponseObject error) { + private void trySetResponseMessage(TunnelxconnTopologyOperationOutputBuilder responseBuilder, + ResponseObject error) { if (!error.getMessage().isEmpty()) { responseBuilder.setResponseMessage(error.getMessage()); } @@ -2087,7 +2088,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC if (respProps != null) { error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM)); error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM)); - return respProps.getProperty(ACK_FINAL_PARAM, "Y"); + return respProps.getProperty(ACK_FINAL_PARAM, "Y"); } return "Y"; } diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java index b4ce214a..ee0bdb50 100644 --- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java +++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java @@ -22,7 +22,6 @@ package org.onap.sdnc.northbound; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.onap.sdnc.northbound.GenericResourceApiProvider.APP_NAME; @@ -40,8 +39,6 @@ import static org.onap.sdnc.northbound.util.MDSALUtil.serviceStatus; import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationInput; import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationOutput; -import javax.xml.crypto.Data; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,8 +57,6 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.re import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformation; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.Service; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatus; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -71,17 +66,14 @@ import org.opendaylight.yangtools.yang.common.RpcResult; @RunWith(MockitoJUnitRunner.class) public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderTest { - final String SVC_OPERATION = "service-topology-operation"; - @Before public void setUp() throws Exception { super.setUp(); svcClient.setScvOperation(SVC_OPERATION); } - /** * Verify ServiceTopologyOperation RPC executes a DG then produces the expected {@link * ServiceTopologyOperationOutput} and persisted the expected {@link Service} in the {@link DataBroker} @@ -122,18 +114,18 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT } @Test - public void serviceTopologyOperation_should_fail_when_service_info_not_present() throws Exception { + public void should_fail_when_service_info_not_present() throws Exception { // create the ServiceTopologyOperationInput from the template ServiceTopologyOperationInput input = build( serviceTopologyOperationInput() .setSdncRequestHeader(build(sdncRequestHeader() - .setSvcRequestId("svc-request-id: xyz") - .setSvcAction(SvcAction.Assign) - )) - .setRequestInformation(build(requestInformation() - .setRequestId("request-id: xyz") - .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance) - ))); + .setSvcRequestId("svc-request-id: xyz") + .setSvcAction(SvcAction.Assign) + )) + .setRequestInformation(build(requestInformation() + .setRequestId("request-id: xyz") + .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance) + ))); //execute the mdsal exec ServiceTopologyOperationOutput output = exec( @@ -149,7 +141,7 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT @Test - public void serviceTopologyOperation_should_fail_when_client_execution_failed() throws Exception { + public void should_fail_when_client_execution_failed() throws Exception { svcClient.mockHasGraph(true); svcClient.mockExecute(new RuntimeException("test exception")); @@ -168,7 +160,7 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT } @Test - public void serviceTopologyOperation_should_fail_when_client_has_no_graph() throws Exception { + public void should_fail_when_client_has_no_graph() throws Exception { svcClient.mockHasGraph(false); ServiceTopologyOperationInput input = createSTOI(); @@ -187,7 +179,7 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT @Test - public void serviceTopologyOperation_should_fail_when_failed_to_update_mdsal() throws Exception { + public void should_fail_when_failed_to_update_mdsal() throws Exception { svcClient.mockHasGraph(true); WriteTransaction mockWriteTransaction = mock(WriteTransaction.class); @@ -211,8 +203,6 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT assertEquals("Y", output.getAckFinalIndicator()); } - - private ServiceTopologyOperationInput createSTOI() { return build( diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VnfTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VnfTopologyOperationRPCTest.java new file mode 100644 index 00000000..a39146b2 --- /dev/null +++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VnfTopologyOperationRPCTest.java @@ -0,0 +1,194 @@ +package org.onap.sdnc.northbound; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.onap.sdnc.northbound.GenericResourceApiProvider.APP_NAME; +import static org.onap.sdnc.northbound.GenericResourceApiProvider.NO_SERVICE_LOGIC_ACTIVE; +import static org.onap.sdnc.northbound.GenericResourceApiProvider.NULL_OR_EMPTY_ERROR_PARAM; +import static org.onap.sdnc.northbound.util.MDSALUtil.build; +import static org.onap.sdnc.northbound.util.MDSALUtil.exec; +import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation; +import static org.onap.sdnc.northbound.util.MDSALUtil.sdncRequestHeader; +import static org.onap.sdnc.northbound.util.MDSALUtil.serviceInformationBuilder; +import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation; +import static org.onap.sdnc.northbound.util.MDSALUtil.vnfInformationBuilder; +import static org.onap.sdnc.northbound.util.MDSALUtil.vnfTopologyOperationInput; +import static org.onap.sdnc.northbound.util.MDSALUtil.vnfTopologyOperationOutput; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdnc.northbound.util.PropBuilder; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@RunWith(MockitoJUnitRunner.class) +public class VnfTopologyOperationRPCTest extends GenericResourceApiProviderTest { + + private static final String SVC_OPERATION = "vnf-topology-operation"; + + @Before + public void setUp() throws Exception { + super.setUp(); + svcClient.setScvOperation(SVC_OPERATION); + } + + @Test + public void should_fail_when_service_info_not_present() throws Exception { + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput()); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("404", output.getResponseCode()); + assertEquals(NULL_OR_EMPTY_ERROR_PARAM, output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + } + + + @Test + public void should_fail_when_invalid_vnf_id() throws Exception { + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput() + .setServiceInformation(build(serviceInformationBuilder(). + setServiceInstanceId("test-service-instance-id"))) + ); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("404", output.getResponseCode()); + assertEquals("invalid input, null or empty vnf-id", output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + } + + + @Test + public void should_fail_when_client_execution_failed() throws Exception { + + svcClient.mockHasGraph(true); + svcClient.mockExecute(new RuntimeException("test exception")); + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput() + .setServiceInformation(build(serviceInformationBuilder() + .setServiceInstanceId("test-service-instance-id"))) + .setVnfInformation(build(vnfInformationBuilder() + .setVnfId("test-vnf-id"))) + ); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("500", output.getResponseCode()); + assertEquals("test exception", output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + } + + @Test + public void should_fail_when_client_has_no_graph() throws Exception { + + svcClient.mockHasGraph(false); + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput() + .setServiceInformation(build(serviceInformationBuilder() + .setServiceInstanceId("test-service-instance-id"))) + .setVnfInformation(build(vnfInformationBuilder() + .setVnfId("test-vnf-id"))) + ); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("503", output.getResponseCode()); + assertEquals(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + SVC_OPERATION + "'", output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + } + + @Test + public void should_fail_when_failed_to_update_mdsal() throws Exception { + + PropBuilder svcResultProp = svcClient.createExecuteOKResult(); + svcClient.mockExecute(svcResultProp); + svcClient.mockHasGraph(true); + WriteTransaction mockWriteTransaction = mock(WriteTransaction.class); + when(mockWriteTransaction.submit()).thenThrow(new TransactionChainClosedException("test exception")); + + DataBroker spyDataBroker = Mockito.spy(dataBroker); + when(spyDataBroker.newWriteOnlyTransaction()).thenReturn(mockWriteTransaction); + genericResourceApiProvider.setDataBroker(spyDataBroker); + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput() + .setServiceInformation(build(serviceInformationBuilder() + .setServiceInstanceId("test-service-instance-id"))) + .setVnfInformation(build(vnfInformationBuilder() + .setVnfId("test-vnf-id"))) + ); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("500", output.getResponseCode()); + assertEquals("test exception", output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + } + + @Test + public void should_complete_with_success_when_no_errors() throws Exception { + + svcClient.mockHasGraph(true); + PropBuilder svcResultProp = svcClient.createExecuteOKResult(); + svcClient.mockExecute(svcResultProp); + + VnfTopologyOperationInput input = build(vnfTopologyOperationInput() + .setSdncRequestHeader(build(sdncRequestHeader() + .setSvcRequestId("test-svc-request-id") + .setSvcAction(SvcAction.Assign) + )) + .setRequestInformation(build(requestInformation() + .setRequestId("test-request-id") + .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance) + )) + .setServiceInformation(build(serviceInformationBuilder() + .setServiceInstanceId("test-service-instance-id"))) + .setVnfInformation(build(vnfInformationBuilder() + .setVnfId("test-vnf-id"))) + + ); + + VnfTopologyOperationOutput output = + exec(genericResourceApiProvider::vnfTopologyOperation, input, RpcResult::getResult); + + assertEquals("200", output.getResponseCode()); + assertEquals("OK", output.getResponseMessage()); + assertEquals("Y", output.getAckFinalIndicator()); + + VnfTopologyOperationOutput expectedVnfTopologyOperationOutput = createExpectedVTOO(svcResultProp, + input); + assertEquals(expectedVnfTopologyOperationOutput, output); + } + + private VnfTopologyOperationOutput createExpectedVTOO(PropBuilder expectedSvcResultProp, + VnfTopologyOperationInput vnfTopologyOperationInput) { + return build( + vnfTopologyOperationOutput() + .setSvcRequestId(vnfTopologyOperationInput.getSdncRequestHeader().getSvcRequestId()) + .setResponseCode(expectedSvcResultProp.get(svcClient.errorCode)) + .setAckFinalIndicator(expectedSvcResultProp.get(svcClient.ackFinal)) + .setResponseMessage(expectedSvcResultProp.get(svcClient.errorMessage)) + .setServiceResponseInformation(build(serviceResponseInformation() + .setInstanceId(vnfTopologyOperationInput.getServiceInformation().getServiceInstanceId()) + .setObjectPath(expectedSvcResultProp.get("vnf-object-path")) + )) + ); + } +} diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java index 11610659..8474eab3 100644 --- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java +++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java @@ -21,10 +21,15 @@ package org.onap.sdnc.northbound.util; +import java.util.concurrent.Future; +import java.util.function.Consumer; +import java.util.function.Function; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutputBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder; @@ -35,13 +40,10 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.re import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.information.VnfInformationBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.common.RpcResult; -import java.util.concurrent.Future; -import java.util.function.Consumer; -import java.util.function.Function; - /** * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure @@ -70,12 +72,19 @@ import java.util.function.Function; */ public class MDSALUtil { + public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() { + return new VnfTopologyOperationInputBuilder(); + } + + public static VnfTopologyOperationOutputBuilder vnfTopologyOperationOutput() { + return new VnfTopologyOperationOutputBuilder(); + } + public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() { return new ServiceTopologyOperationInputBuilder(); } - - public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput(){ + public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput() { return new ServiceTopologyOperationOutputBuilder(); } @@ -89,47 +98,68 @@ public class MDSALUtil { return new RequestInformationBuilder(); } - public static ServiceResponseInformationBuilder serviceResponseInformation(){ - return new ServiceResponseInformationBuilder(); + public static ServiceResponseInformationBuilder serviceResponseInformation() { + return new ServiceResponseInformationBuilder(); } public static ServiceInformationBuilder serviceInformationBuilder() { - return new ServiceInformationBuilder(); + return new ServiceInformationBuilder(); } + public static VnfInformationBuilder vnfInformationBuilder() { + return new VnfInformationBuilder(); + } - public static ServiceBuilder service(){return new ServiceBuilder();} + public static ServiceBuilder service() { + return new ServiceBuilder(); + } - public static ServiceDataBuilder serviceData(){return new ServiceDataBuilder();} + public static ServiceDataBuilder serviceData() { + return new ServiceDataBuilder(); + } - public static ServiceStatusBuilder serviceStatus(){return new ServiceStatusBuilder();} - public static NetworkInformationBuilder networkInformation(){return new NetworkInformationBuilder();} + public static ServiceStatusBuilder serviceStatus() { + return new ServiceStatusBuilder(); + } - public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {return new NetworkTopologyOperationInputBuilder();} + public static NetworkInformationBuilder networkInformation() { + return new NetworkInformationBuilder(); + } - public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {return new NetworkTopologyOperationOutputBuilder();} + public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() { + return new NetworkTopologyOperationInputBuilder(); + } - public static NetworkResponseInformationBuilder networkResponseInformation(){return new NetworkResponseInformationBuilder();} + public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() { + return new NetworkTopologyOperationOutputBuilder(); + } - public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {return new ServiceLevelOperStatusBuilder();} + public static NetworkResponseInformationBuilder networkResponseInformation() { + return new NetworkResponseInformationBuilder(); + } + + public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() { + return new ServiceLevelOperStatusBuilder(); + } public static

P build(Builder

b) { - return b == null? null :b.build(); + return b == null ? null : b.build(); } - public static > P build(Function builderConstructor,P sourceDataObject){ - if(sourceDataObject == null){ + public static > P build(Function builderConstructor, P sourceDataObject) { + if (sourceDataObject == null) { return null; } B bp = builderConstructor.apply(sourceDataObject); return bp.build(); } - public static > P build(Function builderConstructor,P sourceDataObject,Consumer builder){ - if(sourceDataObject == null){ + public static > P build(Function builderConstructor, P sourceDataObject, + Consumer builder) { + if (sourceDataObject == null) { return null; } B bp = builderConstructor.apply(sourceDataObject); @@ -137,7 +167,8 @@ public class MDSALUtil { return bp.build(); } - public static O exec(Function>> rpc,I rpcParameter,Function,O> rpcResult) throws Exception { + public static O exec(Function>> rpc, I rpcParameter, + Function, O> rpcResult) throws Exception { Future> future = rpc.apply(rpcParameter); return rpcResult.apply(future.get()); } -- cgit 1.2.3-korg