aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgaurav <gaurav.agrawal@huawei.com>2018-07-20 21:18:38 +0530
committergaurav <gaurav.agrawal@huawei.com>2018-07-20 21:18:38 +0530
commita5c5c72b718dedf30b53f54060eafdce1ef7c959 (patch)
tree38dd98c02ec018af38317e28ad12dffc05c95dff
parent1dc8352adce89d904e2d5a4c9422037238ecca76 (diff)
Adding testcases for new allotted resource
Addition of a testcase for new allotted resource "connectivity attachment" to generic-resource-api schema. Change-Id: Ibf4164132c187ce26ab253290f9f85b56d4633fd Issue-ID: SDNC-384 Signed-off-by: Gaurav Agrawal <gaurav.agrawal@huawei.com>
-rw-r--r--generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java6
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ConnectionAttachmentTopologyOperationRPCTest.java271
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java15
3 files changed, 289 insertions, 3 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 fc0d90ac..7f67f40f 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
@@ -1851,7 +1851,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
@Override
public Future<RpcResult<ConnectionAttachmentTopologyOperationOutput>> connectionAttachmentTopologyOperation(ConnectionAttachmentTopologyOperationInput input) {
- final String svcOperation = "connectionAttachment-topology-operation";
+ final String svcOperation = "connection-attachment-topology-operation";
Properties parms = new Properties();
log.info(CALLED_STR, svcOperation);
@@ -1909,7 +1909,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
allottedResourceId = respProps.getProperty(ALLOTTED_RESOURCE_ID_PARAM);
serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
- connectionAttachmentObjectPath = respProps.getProperty("connectionAttachment-object-path");
+ connectionAttachmentObjectPath = respProps.getProperty("connection-attachment-object-path");
}
if (failed(responseObject)) {
@@ -1955,7 +1955,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
} catch (IllegalStateException 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());
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ConnectionAttachmentTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ConnectionAttachmentTopologyOperationRPCTest.java
new file mode 100644
index 00000000..091f2de2
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ConnectionAttachmentTopologyOperationRPCTest.java
@@ -0,0 +1,271 @@
+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.INVALID_INPUT_ERROR_MESSAGE;
+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.connectionAttachmentResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.connectionAttachmentTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.connectionAttachmentTopologyOperationOutput;
+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.service;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceData;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceInformationBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceLevelOperStatus;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceStatus;
+
+import java.time.Instant;
+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.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationInput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationOutput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastAction;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastOrderStatus;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastRpcAction;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.OrderStatus;
+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.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceData;
+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.yangtools.yang.common.RpcResult;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConnectionAttachmentTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+ private static final String SVC_OPERATION = "connection-attachment-topology-operation";
+
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ svcClient.setScvOperation(SVC_OPERATION);
+ }
+
+ @Test
+ public void should_fail_when_service_instance_id_not_present() throws Exception {
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput());
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, 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_service_data() throws Exception {
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("404", output.getResponseCode());
+ assertEquals(INVALID_INPUT_ERROR_MESSAGE, 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"));
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ persistServiceInDataBroker(input);
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, 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);
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ persistServiceInDataBroker(input);
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, 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);
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("test-service-instance-id")
+ ))
+ );
+
+ persistServiceInDataBroker(input);
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("500", output.getResponseCode());
+ assertEquals("test exception", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+
+ @Test
+ public void should_success_when_no_errors_encountered() throws Exception {
+
+ svcClient.mockHasGraph(true);
+ PropBuilder svcResultProp = svcClient.createExecuteOKResult();
+ svcResultProp.set("contrail-route-object-path", "connectionAttachmentObjectPath: XYZ");
+ svcClient.mockExecute(svcResultProp);
+
+ ConnectionAttachmentTopologyOperationInput input = build(connectionAttachmentTopologyOperationInput()
+ .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")
+ ))
+ );
+
+ Service service = persistServiceInDataBroker(input);
+
+ ConnectionAttachmentTopologyOperationOutput output =
+ exec(genericResourceApiProvider::connectionAttachmentTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("200", output.getResponseCode());
+ assertEquals("OK", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+
+ ConnectionAttachmentTopologyOperationOutput expectedOutput = createExpectedOutput(svcResultProp, input);
+ assertEquals(expectedOutput, output);
+
+ Service actualService = db
+ .read(input.getServiceInformation().getServiceInstanceId(), LogicalDatastoreType.CONFIGURATION);
+
+ Service expectedService = createExpectedService(input, service.getServiceData());
+ assertEquals(expectedService, actualService);
+ }
+
+ private Service persistServiceInDataBroker(ConnectionAttachmentTopologyOperationInput input) throws Exception {
+
+ Service service = build(service()
+ .setServiceInstanceId(input.getServiceInformation().getServiceInstanceId())
+ .setServiceData(build(serviceData()
+ .setServiceLevelOperStatus(build(serviceLevelOperStatus()
+ .setOrderStatus(OrderStatus.Created)
+ .setModifyTimestamp(Instant.now().toString())
+ .setLastSvcRequestId(input.getSdncRequestHeader().getSvcRequestId())
+ .setLastRpcAction(LastRpcAction.Activate)
+ .setLastOrderStatus(LastOrderStatus.PendingAssignment)
+ .setLastAction(LastAction.ActivateNetworkInstance)
+ .setCreateTimestamp(Instant.now().toString())
+ ))
+ ))
+ );
+ db.write(true, service, LogicalDatastoreType.CONFIGURATION);
+ return service;
+ }
+
+ private ConnectionAttachmentTopologyOperationOutput createExpectedOutput(PropBuilder propBuilder,
+ ConnectionAttachmentTopologyOperationInput input) {
+
+ return build(connectionAttachmentTopologyOperationOutput()
+ .setConnectionAttachmentResponseInformation(build(connectionAttachmentResponseInformation()
+ .setObjectPath(propBuilder.get("connection-attachement-object-path"))))
+ .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(svcClient.serviceObjectPath))
+ ))
+ );
+ }
+
+ private Service createExpectedService(
+ ConnectionAttachmentTopologyOperationInput expectedInput, ServiceData expectedServiceData) {
+
+ ServiceInformation expectedServiceInformation = expectedInput.getServiceInformation();
+
+ return build(service()
+ .setServiceInstanceId(expectedServiceInformation.getServiceInstanceId())
+ .setServiceData(build(serviceData()))
+ .setServiceData(expectedServiceData)
+ .setServiceStatus(build(serviceStatus()))
+ );
+ }
+}
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 fd9a7f32..4b970475 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
@@ -26,6 +26,8 @@ import java.util.function.Consumer;
import java.util.function.Function;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
@@ -45,6 +47,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.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.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;
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;
@@ -260,6 +263,18 @@ public class MDSALUtil {
return new NetworkResponseInformationBuilder();
}
+ public static ConnectionAttachmentTopologyOperationInputBuilder connectionAttachmentTopologyOperationInput() {
+ return new ConnectionAttachmentTopologyOperationInputBuilder();
+ }
+
+ public static ConnectionAttachmentTopologyOperationOutputBuilder connectionAttachmentTopologyOperationOutput() {
+ return new ConnectionAttachmentTopologyOperationOutputBuilder();
+ }
+
+ public static ConnectionAttachmentResponseInformationBuilder connectionAttachmentResponseInformation() {
+ return new ConnectionAttachmentResponseInformationBuilder();
+ }
+
public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {
return new ServiceLevelOperStatusBuilder();
}