summaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-03-20 15:02:30 +0100
committerJakub Dudycz <jakub.dudycz@nokia.com>2018-03-20 15:03:59 +0100
commit398fdce0b850ccd7bdbed1d8098fb289400e00ab (patch)
treec820f8939f87c9744ee808183a28ee411ed4fde5 /generic-resource-api/provider
parentacdff7e4d5dd57c105ff1374d49b581da1126401 (diff)
GenericResourceApiProvider unit tests part 4.
Created unit tests for vfModuleTopologyOperation method Change-Id: I3bbd576ab85e95489c3df71e369cfe061dc4c2c3 Issue-ID: SDNC-275 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'generic-resource-api/provider')
-rw-r--r--generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java26
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VfModuleTopologyOperationRPCTest.java234
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java14
3 files changed, 261 insertions, 13 deletions
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 e8d97970..197ffdc5 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
@@ -950,7 +950,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- if (hasInvalidVfModule(input)) {
+ if (hasInvalidVfModuleId(input)) {
log.debug("exiting {} because of null or empty vf-module-id", svcOperation);
responseBuilder.setResponseCode("403");
responseBuilder.setResponseMessage("invalid input, vf-module-id is null or empty");
@@ -1007,25 +1007,25 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// 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, parms, serviceDataBuilder, responseObject);
if (respProps != null) {
- error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
- error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
+ responseObject.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
+ responseObject.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
serviceObjectPath = respProps.getProperty("vf-module-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.getStatusCode());
+ if (failed(responseObject)) {
+ responseBuilder.setResponseCode(responseObject.getStatusCode());
+ responseBuilder.setResponseMessage(responseObject.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
ServiceBuilder serviceBuilder = new ServiceBuilder();
@@ -1069,7 +1069,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());
@@ -1082,9 +1082,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());
@@ -1121,7 +1121,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
}
}
- private boolean hasInvalidVfModule(VfModuleTopologyOperationInput input) {
+ private boolean hasInvalidVfModuleId(VfModuleTopologyOperationInput input) {
return input.getVfModuleInformation() == null || input.getVfModuleInformation().getVfModuleId() == null
|| input.getVfModuleInformation().getVfModuleId().length() == 0;
}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VfModuleTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VfModuleTopologyOperationRPCTest.java
new file mode 100644
index 00000000..10b70765
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/VfModuleTopologyOperationRPCTest.java
@@ -0,0 +1,234 @@
+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.vfModuleInformationBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.vfModuleTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.vfModuleTopologyOperationOutput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.vnfInformationBuilder;
+
+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.VfModuleTopologyOperationInput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutput;
+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 VfModuleTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+ private static final String SVC_OPERATION = "vf-module-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 {
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput());
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", 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 {
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("invalid input, null or empty vnf-id", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+ @Test
+ public void should_fail_when_invalid_vf_module_id() throws Exception {
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setVnfInformation(build(vnfInformationBuilder()
+ .setVnfId("test-vnf-id")))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("invalid input, vf-module-id is null or empty", 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"));
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setVnfInformation(build(vnfInformationBuilder()
+ .setVnfId("test-vnf-id")
+ ))
+ .setVfModuleInformation(build(vfModuleInformationBuilder()
+ .setVfModuleId("test-vf-module-id")
+ ))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, 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);
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setVnfInformation(build(vnfInformationBuilder()
+ .setVnfId("test-vnf-id")
+ ))
+ .setVfModuleInformation(build(vfModuleInformationBuilder()
+ .setVfModuleId("test-vf-module-id")
+ ))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, 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);
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setVnfInformation(build(vnfInformationBuilder()
+ .setVnfId("test-vnf-id")
+ ))
+ .setVfModuleInformation(build(vfModuleInformationBuilder()
+ .setVfModuleId("test-vf-module-id")
+ ))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, 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);
+
+ VfModuleTopologyOperationInput input = build(vfModuleTopologyOperationInput()
+ .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")
+ ))
+ .setVfModuleInformation(build(vfModuleInformationBuilder()
+ .setVfModuleId("test-vf-module-id")
+ ))
+ );
+
+ VfModuleTopologyOperationOutput output =
+ exec(genericResourceApiProvider::vfModuleTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("200", output.getResponseCode());
+ assertEquals("OK", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+
+ VfModuleTopologyOperationOutput expectedOutput = createExpectedVMTOO(svcResultProp,
+ input);
+ assertEquals(expectedOutput, output);
+ }
+
+ private VfModuleTopologyOperationOutput createExpectedVMTOO(PropBuilder propBuilder,
+ VfModuleTopologyOperationInput input) {
+ return build(
+ vfModuleTopologyOperationOutput()
+ .setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(propBuilder.get(svcClient.errorCode))
+ .setAckFinalIndicator(propBuilder.get(svcClient.ackFinal))
+ .setResponseMessage(propBuilder.get(svcClient.errorMessage))
+ .setServiceResponseInformation(build(serviceResponseInformation()
+ .setInstanceId(input.getServiceInformation().getServiceInstanceId())
+ .setObjectPath(propBuilder.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 8474eab3..cea51b44 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
@@ -28,6 +28,8 @@ 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.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.VfModuleTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutputBuilder;
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;
@@ -40,6 +42,7 @@ 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.vf.module.information.VfModuleInformationBuilder;
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;
@@ -72,6 +75,14 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
*/
public class MDSALUtil {
+ public static VfModuleTopologyOperationInputBuilder vfModuleTopologyOperationInput() {
+ return new VfModuleTopologyOperationInputBuilder();
+ }
+
+ public static VfModuleTopologyOperationOutputBuilder vfModuleTopologyOperationOutput() {
+ return new VfModuleTopologyOperationOutputBuilder();
+ }
+
public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() {
return new VnfTopologyOperationInputBuilder();
}
@@ -110,6 +121,9 @@ public class MDSALUtil {
return new VnfInformationBuilder();
}
+ public static VfModuleInformationBuilder vfModuleInformationBuilder() {
+ return new VfModuleInformationBuilder();
+ }
public static ServiceBuilder service() {
return new ServiceBuilder();