From 9bf3b59219e9140024ccbec9157da22c9be184d6 Mon Sep 17 00:00:00 2001 From: "pawel.kadlubanski" Date: Mon, 19 Feb 2018 14:20:19 +0100 Subject: Refactoring VnfApiProvider part 1 Move VnfInstanceTopologyOperationInput validation from vnfInstanceTopologyOperation to seperate method. Change-Id: I56e3999a92323c745f6d0aa8b4417b9e7acb277a Issue-ID: SDNC-268 Signed-off-by: pawel.kadlubanski --- .../java/org/onap/sdnc/vnfapi/VnfApiProvider.java | 49 +++++++++++----------- .../org/onap/sdnc/vnfapi/VnfApiProviderTest.java | 19 ++++++++- 2 files changed, 41 insertions(+), 27 deletions(-) (limited to 'vnfapi/provider') diff --git a/vnfapi/provider/src/main/java/org/onap/sdnc/vnfapi/VnfApiProvider.java b/vnfapi/provider/src/main/java/org/onap/sdnc/vnfapi/VnfApiProvider.java index 1031cfad..42d02419 100644 --- a/vnfapi/provider/src/main/java/org/onap/sdnc/vnfapi/VnfApiProvider.java +++ b/vnfapi/provider/src/main/java/org/onap/sdnc/vnfapi/VnfApiProvider.java @@ -949,6 +949,26 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataChangeL } //1610 vnf-instance-topology-operation + + private Boolean validateVnfInstanceTopologyOperationInput(VnfInstanceTopologyOperationInput input) { + return input != null + && input.getVnfInstanceRequestInformation() != null + && input.getVnfInstanceRequestInformation().getVnfInstanceId() != null + && input.getVnfInstanceRequestInformation().getVnfInstanceId().length() != 0; + } + + private Future> buildVnfInstanceTopologyOperationOutputWithtError( + String responseCode, String responseMessage, String ackFinalIndicator) { + VnfInstanceTopologyOperationOutputBuilder responseBuilder = new VnfInstanceTopologyOperationOutputBuilder(); + responseBuilder.setResponseCode(responseCode); + responseBuilder.setResponseMessage(responseMessage); + responseBuilder.setAckFinalIndicator(ackFinalIndicator); + return Futures.immediateFuture(RpcResultBuilder + .status(true) + .withResult(responseBuilder.build()) + .build()); + } + @Override public Future> vnfInstanceTopologyOperation( VnfInstanceTopologyOperationInput input) { @@ -962,18 +982,11 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataChangeL // create a new response object VnfInstanceTopologyOperationOutputBuilder responseBuilder = new VnfInstanceTopologyOperationOutputBuilder(); - if (input == null || input.getVnfInstanceRequestInformation() == null - || input.getVnfInstanceRequestInformation().getVnfInstanceId() == null) { + if (!validateVnfInstanceTopologyOperationInput(input)) { log.debug(EXITING_STR + svcOperation + " because of " + INVALID_INPUT_VNF_INSTANCE_STR); - responseBuilder.setResponseCode("403"); - responseBuilder.setResponseMessage(INVALID_INPUT_VNF_INSTANCE_STR); - responseBuilder.setAckFinalIndicator("Y"); - RpcResult rpcResult = RpcResultBuilder - .status(true) - .withResult(responseBuilder.build()) - .build(); - // return error - return Futures.immediateFuture(rpcResult); + return buildVnfInstanceTopologyOperationOutputWithtError("403", + INVALID_INPUT_VNF_INSTANCE_STR, + "Y" ); } // Grab the service instance ID from the input buffer @@ -981,20 +994,6 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataChangeL String preloadName = input.getVnfInstanceRequestInformation().getVnfInstanceName(); String preloadType = input.getVnfInstanceRequestInformation().getVnfModelId(); - // Make sure we have a valid viid - if (viid == null || viid.length() == 0) { - log.debug(EXITING_STR + svcOperation + " because of invalid vnf-instance-id"); - responseBuilder.setResponseCode("403"); - responseBuilder.setResponseMessage(INVALID_INPUT_VNF_INSTANCE_STR); - responseBuilder.setAckFinalIndicator("Y"); - RpcResult rpcResult = RpcResultBuilder - .status(true) - .withResult(responseBuilder.build()) - .build(); - // return error - return Futures.immediateFuture(rpcResult); - } - if (input.getSdncRequestHeader() != null) { responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId()); setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId()); diff --git a/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java b/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java index 7a0d5185..72c244d5 100644 --- a/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java +++ b/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java @@ -41,7 +41,6 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTop import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformation; import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformationBuilder; - import java.util.concurrent.Future; @@ -123,6 +122,22 @@ public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest { checkVnfInstanceTopologyOperationOutput(result); } + @Test + public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationVnfInstanceIdIsZero() throws Exception { + VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder(); + builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder() + .setVnfInstanceId("") + .build()); + + VnfInstanceTopologyOperationInput input = builder.build(); + VnfInstanceTopologyOperationOutput result = vnfapiProvider + .vnfInstanceTopologyOperation(input) + .get() + .getResult(); + + checkVnfInstanceTopologyOperationOutput(result); + } + private void checkVnfInstanceTopologyOperationOutput(VnfInstanceTopologyOperationOutput result) { String expectedResponseCode = "403"; String expectedResponseMessage = "invalid input, null or empty vnf-instance-id"; @@ -132,4 +147,4 @@ public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest { Assert.assertEquals(result.getResponseMessage(), expectedResponseMessage); Assert.assertEquals(result.getAckFinalIndicator(), expectedAckFinalIndicator); } - } + } \ No newline at end of file -- cgit 1.2.3-korg