summaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider
diff options
context:
space:
mode:
Diffstat (limited to 'generic-resource-api/provider')
-rw-r--r--generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java58
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadNetworkTopologyRPCTest.java185
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadVnfTopologyOperationRPCTest.java185
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java40
4 files changed, 439 insertions, 29 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 6c6e424e..50367ce5 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
@@ -1979,7 +1979,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
String preloadType = input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfType();
// Make sure we have a preload_name and preload_type
- if (isValidPreloadData(preloadName, preloadType)) {
+ if (invalidPreloadData(preloadName, preloadType)) {
log.debug("exiting {} vnf-name or vnf-type is null or empty", svcOperation);
responseBuilder.setResponseCode("403");
responseBuilder.setResponseMessage("invalid input: vnf-name or vnf-type is null or empty");
@@ -1993,7 +1993,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- this.trySetSvcRequestId(input, responseBuilder);
+ trySetSvcRequestId(input, responseBuilder);
PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
getPreloadData(preloadName, preloadType, preloadDataBuilder);
@@ -2024,14 +2024,14 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ResponseObject error = new ResponseObject("200", "");
- Properties respProps = tryGetProperties(svcOperation, parms, error);
- String ackFinal = resolveAckFinal(error, respProps);
+ ResponseObject responseObject = new ResponseObject("200", "");
+ Properties respProps = tryGetProperties(svcOperation, parms, responseObject);
+ String ackFinal = resolveAckFinal(responseObject, respProps);
- if (failed(error)) {
+ if (failed(responseObject)) {
- responseBuilder.setResponseCode(error.getStatusCode());
- responseBuilder.setResponseMessage(error.getMessage());
+ responseBuilder.setResponseCode(responseObject.getStatusCode());
+ responseBuilder.setResponseMessage(responseObject.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
@@ -2039,7 +2039,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
preloadVnfListBuilder.setVnfType(preloadType);
preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
log.error("Returned FAILED for {} [{},{}] error code: '{}', Reason: '{}'", svcOperation, preloadName,
- preloadType, error.getStatusCode(), error.getMessage());
+ preloadType, responseObject.getStatusCode(), responseObject.getMessage());
try {
savePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
} catch (Exception e) {
@@ -2063,7 +2063,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName, preloadType,
e);
responseBuilder.setResponseCode("500");
- responseBuilder.setResponseMessage(e.toString());
+ responseBuilder.setResponseMessage(e.getMessage());
responseBuilder.setAckFinalIndicator("Y");
log.error("Returned FAILED for {} [{},{}] {}", svcOperation, preloadName, preloadType,
responseBuilder.build());
@@ -2077,9 +2077,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 MD-SAL for {} [{},{}]", svcOperation, preloadName, preloadType);
log.info("Returned SUCCESS for {} [{},{}] {}", svcOperation, preloadName, preloadType,
@@ -2093,10 +2093,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private String resolveAckFinal(ResponseObject error, Properties respProps) {
+ private String resolveAckFinal(ResponseObject responseObject, Properties respProps) {
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));
return respProps.getProperty(ACK_FINAL_PARAM, "Y");
}
return "Y";
@@ -2169,10 +2169,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
String preloadType = input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkType();
// Make sure we have a preload_name and preload_type
- if (isValidPreloadData(preloadName, preloadType)) {
- log.debug("exiting {} because of invalid preload-name", svcOperation);
+ if (invalidPreloadData(preloadName, preloadType)) {
+ log.debug("exiting {} because of invalid preload-name or preload-type", svcOperation);
responseBuilder.setResponseCode("403");
- responseBuilder.setResponseMessage("input, invalid preload-name");
+ responseBuilder.setResponseMessage("invalid input: network-name or network-type is null or empty");
responseBuilder.setAckFinalIndicator("Y");
RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
@@ -2216,15 +2216,15 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ResponseObject error = new ResponseObject("200", "");
- Properties respProps = tryGetProperties(svcOperation, parms, error);
+ ResponseObject responseObject = new ResponseObject("200", "");
+ Properties respProps = tryGetProperties(svcOperation, parms, responseObject);
- String ackFinal = resolveAckFinal(error, respProps);
+ String ackFinal = resolveAckFinal(responseObject, respProps);
- if (failed(error)) {
+ if (failed(responseObject)) {
- responseBuilder.setResponseCode(error.getStatusCode());
- responseBuilder.setResponseMessage(error.getMessage());
+ responseBuilder.setResponseCode(responseObject.getStatusCode());
+ responseBuilder.setResponseMessage(responseObject.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
@@ -2232,7 +2232,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
preloadVnfListBuilder.setVnfType(preloadType);
preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
log.error("Returned FAILED for {} [{},{}] error code: '{}', Reason: '{}'", svcOperation, preloadName,
- preloadType, error.getStatusCode(), error.getMessage());
+ preloadType, responseObject.getStatusCode(), responseObject.getMessage());
try {
savePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
} catch (Exception e) {
@@ -2256,7 +2256,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
} catch (Exception e) {
log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName, preloadType, e);
responseBuilder.setResponseCode("500");
- responseBuilder.setResponseMessage(e.toString());
+ responseBuilder.setResponseMessage(e.getMessage());
responseBuilder.setAckFinalIndicator("Y");
log.error("Returned FAILED for {} [{},{}] {}", svcOperation, preloadName, preloadType,
responseBuilder.build());
@@ -2270,9 +2270,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 MD-SAL for {} [{},{}]", svcOperation, preloadName, preloadType);
log.info("Returned SUCCESS for {} [{},{}] {}", svcOperation, preloadName, preloadType,
@@ -2300,7 +2300,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
}
}
- private boolean isValidPreloadData(String preloadName, String preloadType) {
+ private boolean invalidPreloadData(String preloadName, String preloadType) {
return preloadName == null || preloadName.length() == 0 || preloadType == null || preloadType.length() == 0;
}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadNetworkTopologyRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadNetworkTopologyRPCTest.java
new file mode 100644
index 00000000..b05f1b27
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadNetworkTopologyRPCTest.java
@@ -0,0 +1,185 @@
+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.util.MDSALUtil.build;
+import static org.onap.sdnc.northbound.util.MDSALUtil.exec;
+import static org.onap.sdnc.northbound.util.MDSALUtil.networkTopologyIdentifierBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.networkTopologyInformationBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.preloadNetworkTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.preloadNetworkTopologyOperationOutput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.sdncRequestHeader;
+
+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.PreloadNetworkTopologyOperationInput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutput;
+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 PreloadNetworkTopologyRPCTest extends GenericResourceApiProviderTest {
+
+ private static final String SVC_OPERATION = "preload-network-topology-operation";
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ svcClient.setScvOperation(SVC_OPERATION);
+ }
+
+ @Test
+ public void should_fail_when_invalid_vnf_topology() throws Exception {
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput());
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("input is null", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+
+ @Test
+ public void should_fail_when_invalid_preload_data() throws Exception {
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput()
+ .setNetworkTopologyInformation(build(networkTopologyInformationBuilder()
+ .setNetworkTopologyIdentifier(build(networkTopologyIdentifierBuilder()
+ .setNetworkName("test-network-name")))))
+ );
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("invalid input: network-name or network-type 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.mockExecuteWoServiceData(new RuntimeException("test exception"));
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput()
+ .setNetworkTopologyInformation(build(networkTopologyInformationBuilder()
+ .setNetworkTopologyIdentifier(build(networkTopologyIdentifierBuilder()
+ .setNetworkName("test-network-name")
+ .setNetworkType("test-network-type")))))
+ );
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, 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);
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput()
+ .setNetworkTopologyInformation(build(networkTopologyInformationBuilder()
+ .setNetworkTopologyIdentifier(build(networkTopologyIdentifierBuilder()
+ .setNetworkName("test-network-name")
+ .setNetworkType("test-network-type")))))
+ );
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, 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.mockExecuteWoServiceData(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);
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput()
+ .setNetworkTopologyInformation(build(networkTopologyInformationBuilder()
+ .setNetworkTopologyIdentifier(build(networkTopologyIdentifierBuilder()
+ .setNetworkName("test-network-name")
+ .setNetworkType("test-network-type")))))
+ );
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, 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);
+
+ PreloadNetworkTopologyOperationInput input = build(preloadNetworkTopologyOperationInput()
+ .setNetworkTopologyInformation(build(networkTopologyInformationBuilder()
+ .setNetworkTopologyIdentifier(build(networkTopologyIdentifierBuilder()
+ .setNetworkName("test-network-name")
+ .setNetworkType("test-network-type")))))
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setRequestInformation(build(requestInformation()
+ .setRequestId("test-request-id")
+ .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
+ ))
+ );
+
+ PreloadNetworkTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadNetworkTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("200", output.getResponseCode());
+ assertEquals("Y", output.getAckFinalIndicator());
+
+ PreloadNetworkTopologyOperationOutput expectedOutput = createExpectedOutput(svcResultProp, input);
+ assertEquals(expectedOutput, output);
+ }
+
+ private PreloadNetworkTopologyOperationOutput createExpectedOutput(PropBuilder svcResultProp,
+ PreloadNetworkTopologyOperationInput input) {
+ return build(preloadNetworkTopologyOperationOutput()
+ .setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(svcResultProp.get(svcClient.errorCode))
+ .setAckFinalIndicator(svcResultProp.get(svcClient.ackFinal))
+ );
+ }
+
+}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadVnfTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadVnfTopologyOperationRPCTest.java
new file mode 100644
index 00000000..8a854a91
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/PreloadVnfTopologyOperationRPCTest.java
@@ -0,0 +1,185 @@
+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.util.MDSALUtil.build;
+import static org.onap.sdnc.northbound.util.MDSALUtil.exec;
+import static org.onap.sdnc.northbound.util.MDSALUtil.preloadVnfTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.preloadVnfTopologyOperationOutput;
+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.vnfTopologyIdentifierBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.vnfTopologyInformationBuilder;
+
+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.PreloadVnfTopologyOperationInput;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationOutput;
+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 PreloadVnfTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+ private static final String SVC_OPERATION = "preload-vnf-topology-operation";
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ svcClient.setScvOperation(SVC_OPERATION);
+ }
+
+ @Test
+ public void should_fail_when_invalid_vnf_topology() throws Exception {
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput());
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("invalid input: input is null", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+
+ @Test
+ public void should_fail_when_invalid_preload_data() throws Exception {
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput()
+ .setVnfTopologyInformation(build(vnfTopologyInformationBuilder()
+ .setVnfTopologyIdentifier(build(vnfTopologyIdentifierBuilder()
+ .setVnfName("test-vnf-name")))))
+ );
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("403", output.getResponseCode());
+ assertEquals("invalid input: vnf-name or vnf-type 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.mockExecuteWoServiceData(new RuntimeException("test exception"));
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput()
+ .setVnfTopologyInformation(build(vnfTopologyInformationBuilder()
+ .setVnfTopologyIdentifier(build(vnfTopologyIdentifierBuilder()
+ .setVnfName("test-vnf-name")
+ .setVnfType("test-vnf-type")))))
+ );
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, 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);
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput()
+ .setVnfTopologyInformation(build(vnfTopologyInformationBuilder()
+ .setVnfTopologyIdentifier(build(vnfTopologyIdentifierBuilder()
+ .setVnfName("test-vnf-name")
+ .setVnfType("test-vnf-type")))))
+ );
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, 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.mockExecuteWoServiceData(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);
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput()
+ .setVnfTopologyInformation(build(vnfTopologyInformationBuilder()
+ .setVnfTopologyIdentifier(build(vnfTopologyIdentifierBuilder()
+ .setVnfName("test-vnf-name")
+ .setVnfType("test-vnf-type")))))
+ );
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, 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);
+
+ PreloadVnfTopologyOperationInput input = build(preloadVnfTopologyOperationInput()
+ .setVnfTopologyInformation(build(vnfTopologyInformationBuilder()
+ .setVnfTopologyIdentifier(build(vnfTopologyIdentifierBuilder()
+ .setVnfName("test-vnf-name")
+ .setVnfType("test-vnf-type")))))
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("test-svc-request-id")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setRequestInformation(build(requestInformation()
+ .setRequestId("test-request-id")
+ .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
+ ))
+ );
+
+ PreloadVnfTopologyOperationOutput output =
+ exec(genericResourceApiProvider::preloadVnfTopologyOperation, input, RpcResult::getResult);
+
+ assertEquals("200", output.getResponseCode());
+ assertEquals("Y", output.getAckFinalIndicator());
+
+ PreloadVnfTopologyOperationOutput expectedOutput = createExpectedOutput(svcResultProp, input);
+ assertEquals(expectedOutput, output);
+ }
+
+ private PreloadVnfTopologyOperationOutput createExpectedOutput(PropBuilder svcResultProp,
+ PreloadVnfTopologyOperationInput input) {
+ return build(preloadVnfTopologyOperationOutput()
+ .setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(svcResultProp.get(svcClient.errorCode))
+ .setAckFinalIndicator(svcResultProp.get(svcClient.ackFinal))
+ );
+ }
+
+}
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 1c3c5969..fd9a7f32 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
@@ -30,6 +30,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.ContrailRouteTopologyOperationOutputBuilder;
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.PreloadNetworkTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
@@ -44,6 +48,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.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;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.topology.identifier.NetworkTopologyIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.topology.information.NetworkTopologyInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.security.zone.response.information.SecurityZoneResponseInformationBuilder;
@@ -57,6 +63,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.vf.module.information.VfModuleInformationBuilder;
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.VnfTopologyIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.topology.information.VnfTopologyInformationBuilder;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -88,6 +96,22 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
*/
public class MDSALUtil {
+ public static PreloadVnfTopologyOperationInputBuilder preloadVnfTopologyOperationInput() {
+ return new PreloadVnfTopologyOperationInputBuilder();
+ }
+
+ public static PreloadVnfTopologyOperationOutputBuilder preloadVnfTopologyOperationOutput() {
+ return new PreloadVnfTopologyOperationOutputBuilder();
+ }
+
+ public static PreloadNetworkTopologyOperationInputBuilder preloadNetworkTopologyOperationInput() {
+ return new PreloadNetworkTopologyOperationInputBuilder();
+ }
+
+ public static PreloadNetworkTopologyOperationOutputBuilder preloadNetworkTopologyOperationOutput() {
+ return new PreloadNetworkTopologyOperationOutputBuilder();
+ }
+
public static BrgTopologyOperationInputBuilder brgTopologyOperationInput() {
return new BrgTopologyOperationInputBuilder();
}
@@ -182,6 +206,22 @@ public class MDSALUtil {
return new ServiceInformationBuilder();
}
+ public static VnfTopologyInformationBuilder vnfTopologyInformationBuilder() {
+ return new VnfTopologyInformationBuilder();
+ }
+
+ public static NetworkTopologyInformationBuilder networkTopologyInformationBuilder() {
+ return new NetworkTopologyInformationBuilder();
+ }
+
+ public static NetworkTopologyIdentifierBuilder networkTopologyIdentifierBuilder(){
+ return new NetworkTopologyIdentifierBuilder();
+ }
+
+ public static VnfTopologyIdentifierBuilder vnfTopologyIdentifierBuilder() {
+ return new VnfTopologyIdentifierBuilder();
+ }
+
public static VnfInformationBuilder vnfInformationBuilder() {
return new VnfInformationBuilder();
}