summaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'generic-resource-api/provider/src/test')
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PnfTopologyOperationRPCTest.java208
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java2
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java25
3 files changed, 235 insertions, 0 deletions
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PnfTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PnfTopologyOperationRPCTest.java
new file mode 100644
index 00000000..60a0e1fc
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PnfTopologyOperationRPCTest.java
@@ -0,0 +1,208 @@
+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.pnfDetailsBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.pnfResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.pnfTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.pnfTopologyOperationOutput;
+
+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.PnfTopologyOperationInput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationOutput;
+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 PnfTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+ private static final String SVC_OPERATION = "pnf-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 {
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput());
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, 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_pnf_id() throws Exception {
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder().
+ setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("404", output.getResponseCode());
+ assertEquals("invalid input, null or empty pnf-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"));
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setPnfDetails(build(pnfDetailsBuilder()
+ .setPnfId("test-pnf-id")
+ ))
+ );
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, 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);
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setPnfDetails(build(pnfDetailsBuilder()
+ .setPnfId("test-pnf-id")
+ ))
+ );
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, 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);
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput()
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ .setPnfDetails(build(pnfDetailsBuilder()
+ .setPnfId("test-pnf-id")
+ ))
+ );
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, 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);
+
+ PnfTopologyOperationInput input = build(pnfTopologyOperationInput()
+ .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")
+ ))
+ .setPnfDetails(build(pnfDetailsBuilder()
+ .setPnfId("test-pnf-id")
+ ))
+ );
+
+ PnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::pnfTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("200", output.getResponseCode());
+ assertEquals("OK", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+
+ PnfTopologyOperationOutput expectedPnfTopologyOperationOutput = createExpectedOutput(svcResultProp,
+ input);
+ assertEquals(expectedPnfTopologyOperationOutput, output);
+ }
+
+ private PnfTopologyOperationOutput createExpectedOutput(PropBuilder svcResultProp,
+ PnfTopologyOperationInput pnfTopologyOperationInput) {
+ return build(
+ pnfTopologyOperationOutput()
+ .setSvcRequestId(pnfTopologyOperationInput.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(svcResultProp.get(svcClient.errorCode))
+ .setAckFinalIndicator(svcResultProp.get(svcClient.ackFinal))
+ .setResponseMessage(svcResultProp.get(svcClient.errorMessage))
+ .setServiceResponseInformation(build(serviceResponseInformation()
+ .setInstanceId(pnfTopologyOperationInput.getServiceInformation().getServiceInstanceId())
+ .setObjectPath(svcResultProp.get(svcClient.serviceObjectPath))
+ ))
+ .setPnfResponseInformation(build(pnfResponseInformation()
+ .setInstanceId(pnfTopologyOperationInput.getPnfDetails().getPnfId())
+ .setObjectPath(svcResultProp.get(svcClient.pnfObjectPath))
+ ))
+ );
+ }
+}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
index 36c6c7ff..b0cd627e 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
@@ -50,6 +50,7 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
public final String ackFinal = "ack-final";
public final String serviceObjectPath = "service-object-path";
public final String networkObjectPath = "network-object-path";
+ public final String pnfObjectPath = "pnf-object-path";
public final String vnfObjectPath = "vnf-object-path";
public final String vfModuleObjectPath = "vf-module-object-path";
public final String networkId = "networkId";
@@ -98,6 +99,7 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
.set(ackFinal, "Y")
.set(serviceObjectPath, "serviceObjectPath: XYZ")
.set(networkObjectPath, "networkObjectPath: XYZ")
+ .set(pnfObjectPath, "pnfObjectPath: XYZ")
.set(vnfObjectPath, "vnfObjectPath: XYZ")
.set(vfModuleObjectPath, "vfModuleObjectPath: XYZ")
.set(networkId, "networkId: XYZ");
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 9ed690ca..d959b9f2 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
@@ -46,6 +46,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.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.PnfTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.brg.response.information.BrgResponseInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.connection.attachment.response.information.ConnectionAttachmentResponseInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.contrail.route.response.information.ContrailRouteResponseInformationBuilder;
@@ -71,6 +73,9 @@ 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.vnf.information.VnfInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.response.information.VnfResponseInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.topology.identifier.structure.VnfTopologyIdentifierStructureBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.pnf.details.PnfDetailsBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.pnf.response.information.PnfResponseInformationBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.pnf.topology.identifier.structure.PnfTopologyIdentifierStructureBuilder;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -158,6 +163,14 @@ public class MDSALUtil {
return new VfModuleTopologyOperationOutputBuilder();
}
+ public static PnfTopologyOperationInputBuilder pnfTopologyOperationInput() {
+ return new PnfTopologyOperationInputBuilder();
+ }
+
+ public static PnfTopologyOperationOutputBuilder pnfTopologyOperationOutput() {
+ return new PnfTopologyOperationOutputBuilder();
+ }
+
public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() {
return new VnfTopologyOperationInputBuilder();
}
@@ -204,6 +217,10 @@ public class MDSALUtil {
return new ContrailRouteResponseInformationBuilder();
}
+ public static PnfResponseInformationBuilder pnfResponseInformation() {
+ return new PnfResponseInformationBuilder();
+ }
+
public static VnfResponseInformationBuilder vnfResponseInformation() {
return new VnfResponseInformationBuilder();
}
@@ -224,6 +241,10 @@ public class MDSALUtil {
return new NetworkTopologyIdentifierStructureBuilder();
}
+ public static PnfDetailsBuilder pnfDetailsBuilder() {
+ return new PnfDetailsBuilder();
+ }
+
public static VnfInformationBuilder vnfInformationBuilder() {
return new VnfInformationBuilder();
}
@@ -256,6 +277,10 @@ public class MDSALUtil {
return new NetworkTopologyOperationOutputBuilder();
}
+ public static PnfTopologyIdentifierStructureBuilder pnfTopologyIdentifierStructureBuilder() {
+ return new PnfTopologyIdentifierStructureBuilder();
+ }
+
public static VnfTopologyIdentifierStructureBuilder vnfTopologyIdentifierStructureBuilder() {
return new VnfTopologyIdentifierStructureBuilder();
}