summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy14
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy36
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java14
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java8
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java6
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java55
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java3
-rw-r--r--bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml11
-rw-r--r--bpmn/MSOCoreBPMN/pom.xml7
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java126
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java1
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java70
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java211
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java30
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java1
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java438
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/RollbackDataTest.java85
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java1
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java)5
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy3
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java118
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java4
22 files changed, 625 insertions, 622 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy
index 06cc284620..2645ea3c02 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy
@@ -17,7 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.bpmn.common.scripts;
+package org.openecomp.mso.bpmn.common.scripts
+
+import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
import static org.apache.commons.lang3.StringUtils.*;
@@ -96,12 +98,12 @@ public class DecomposeService extends AbstractServiceTaskProcessor {
// check for input
String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
String modelVersion = execution.getVariable("DDS_modelVersion")
-
+
utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
- utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled)
-
+ utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled)
+
JSONObject catalogDbResponse = null
-
+
if (modelVersion != null && modelVersion.length() > 0)
catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2")
else
@@ -140,7 +142,7 @@ public class DecomposeService extends AbstractServiceTaskProcessor {
utils.log("DEBUG", "getting service decomposition", isDebugEnabled)
String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse")
- ServiceDecomposition serviceDecomposition = new ServiceDecomposition(catalogDbResponse, serviceInstanceId)
+ ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.jsonToServiceDecomposition(catalogDbResponse, serviceInstanceId)
execution.setVariable("serviceDecomposition", serviceDecomposition)
execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy
index 14f9135826..cfc5171dca 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy
@@ -20,14 +20,14 @@
package org.openecomp.mso.bpmn.common.scripts
-import static org.apache.commons.lang3.StringUtils.*
-
-import org.apache.commons.lang3.*
+import org.apache.commons.lang3.StringEscapeUtils
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.runtime.Execution
import org.openecomp.mso.rest.APIResponse
import org.springframework.web.util.UriUtils
+import static org.apache.commons.lang3.StringUtils.isBlank
+
/**
* This class supports the GenericGetService Sub Flow.
@@ -301,7 +301,9 @@ class GenericGetService extends AbstractServiceTaskProcessor{
if(responseCode == 200){
utils.log("DEBUG", " Query for Service Instance Url Received a Good Response Code", isDebugEnabled)
execution.setVariable("GENGS_SuccessIndicator", true)
- if(utils.nodeExists(aaiResponse, "result-data")){
+ String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")
+ boolean nodeExists = isBlank(globalCustomerId) ? utils.nodeExists(aaiResponse, "result-data") : hasCustomerServiceInstance(aaiResponse, globalCustomerId)
+ if(nodeExists){
utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled)
execution.setVariable("GENGS_FoundIndicator", true)
String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")
@@ -439,4 +441,30 @@ class GenericGetService extends AbstractServiceTaskProcessor{
utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled)
}
+ /**
+ * An utility method which check whether a service(by name) is already present within a globalCustomerId or not.
+ * @param jsonResponse raw response received from AAI by searching ServiceInstance by Name.
+ * @param globalCustomerId
+ * @return {@code true} if globalCustomerId is found at 6th position within "resource-link", {@code false} in any other cases.
+ */
+ public boolean hasCustomerServiceInstance(String aaiResponse, final String globalCustomerId) {
+ if (isBlank(aaiResponse)) {
+ return false
+ }
+ aaiResponse = utils.removeXmlNamespaces(aaiResponse)
+ ArrayList<String> linksArray = utils.getMultNodeObjects(aaiResponse, "resource-link")
+ if (linksArray == null || linksArray.size() == 0) {
+ return false
+ }
+ for (String resourceLink : linksArray) {
+ int custStart = resourceLink.indexOf("customer/")
+ int custEnd = resourceLink.indexOf("/service-subscriptions/")
+ String receivedCustomerId = resourceLink.substring(custStart + 9, custEnd)
+ if (globalCustomerId.equals(receivedCustomerId)) {
+ return true
+ }
+ }
+ return false
+ }
+
} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java
index ca815cf904..214be060e3 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java
@@ -32,13 +32,9 @@ import com.fasterxml.jackson.databind.JsonMappingException;
public interface AAIRestClient {
- Pservers getPhysicalServers(String hostName, String uuid);
-
- List<Pserver> getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid) throws UnsupportedEncodingException, JsonParseException, JsonMappingException, IOException;
-
- void updateMaintenceFlag(String vnfId,boolean inMaint, String transactionLoggingUuid) throws Exception;
-
- void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws Exception;
-
- GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws Exception;
+Pservers getPhysicalServers(String hostName, String uuid);
+List<Pserver> getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid) throws UnsupportedEncodingException, JsonParseException, JsonMappingException, IOException;
+void updateMaintenceFlag(String vnfId,boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException;
+void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException , IOException;
+GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws JsonParseException, JsonMappingException , IOException;
}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
index ae8638f0b7..af1eddf491 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
@@ -139,14 +139,14 @@ public class AAIRestClientImpl implements AAIRestClient {
}
@Override
- public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws Exception {
+ public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException {
GenericVnfs genericVnfs = webTarget.register(AAIResourcesObjectMapperProvider.class).path(ENDPOINT_GET_ALL_VNFS)
.queryParam("vnf-name", vnfName).request().header("X-FromAppId", "MSO")
.header("X-TransactionId", transactionLoggingUuid).header("Content-Type", "application/json")
.accept(MediaType.APPLICATION_JSON_TYPE).get().readEntity(GenericVnfs.class);
if (genericVnfs.getGenericVnf().size() > 1)
- throw new Exception("Multiple Generic Vnfs Returned");
+ throw new IndexOutOfBoundsException ("Multiple Generic Vnfs Returned");
GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
updateMaintenceFlagVnfId(genericVnf.getVnfId(), inMaint, transactionLoggingUuid);
@@ -154,7 +154,7 @@ public class AAIRestClientImpl implements AAIRestClient {
@Override
public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid)
- throws Exception {
+ throws JsonParseException, JsonMappingException, IOException {
GenericVnf genericVnf = new GenericVnf();
genericVnf.setInMaint(inMaint);
webTarget.register(AAIResourcesObjectMapperProvider.class).path(GENERIC_VNF_PATH + "/" + vnfId).request()
@@ -165,7 +165,7 @@ public class AAIRestClientImpl implements AAIRestClient {
}
@Override
- public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws Exception {
+ public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException {
return webTarget.register(AAIResourcesObjectMapperProvider.class).path(GENERIC_VNF_PATH + "/" + vnfId).request()
.header("X-FromAppId", "MSO").header("X-TransactionId", transactionLoggingUuid)
.header("Content-Type", "application/json").accept(MediaType.APPLICATION_JSON_TYPE).get()
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java
index 26c1c4acd2..f66034f5e9 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java
@@ -76,7 +76,7 @@ public class ApplicationControllerClient {
private LifeCycleManagerStateful client;
public Status runCommand(Action action, ActionIdentifiers identifier, Flags flags, Payload payload,
- String requestID) throws Exception {
+ String requestID) throws IllegalAccessException,NoSuchMethodException,AppcClientException,JsonProcessingException,InvocationTargetException {
Object requestObject = createRequest(action, identifier, flags, payload, requestID);
client = getAppCClient();
Method lcmMethod = appCSupport.getAPIMethod(action.name(), client, false);
@@ -118,7 +118,7 @@ public class ApplicationControllerClient {
}
public Object createRequest(Action action, ActionIdentifiers identifier, Flags flags, Payload payload,
- String requestId) throws Exception {
+ String requestId) throws IllegalAccessException,NoSuchMethodException,InvocationTargetException {
Object requestObject = appCSupport.getInput(action.name());
try {
org.openecomp.appc.client.lcm.model.CommonHeader commonHeader = buildCommonHeader(requestId);
@@ -129,7 +129,7 @@ public class ApplicationControllerClient {
.invoke(requestObject, identifier);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOGGER.debug("Exception:", e);
- throw new Exception("Error Building AppC Request: " + e.getMessage());
+ throw new IllegalAccessException("Error Building AppC Request: " + e.getMessage());
}
return requestObject;
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java
index b1172837cf..82cceb0b70 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java
@@ -482,6 +482,61 @@ public class GenericGetServiceTest extends WorkflowTest {
assertEquals(expectedWorkflowException, workflowException);
}
+ @Test
+ @Deployment(resources = {"subprocess/GenericGetService.bpmn"})
+ public void testGenericGetService_success_serviceInstance_byNameServicePresent() throws Exception{
+
+ MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByNameMultiCustomer.xml");
+ MockGetServiceInstance("XyCorporation", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
+
+ Map<String, String> variables = new HashMap<String, String>();
+ setVariablesInstance(variables, null, "1604-MVM-26", "XyCorporation", null);
+
+ WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetService", variables);
+ waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
+
+ String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_SuccessIndicator");
+ String found = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_FoundIndicator");
+ String resourceLink = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_resourceLink");
+ String response = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowResponse");
+ String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowException");
+ String siUrlResponseCode = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_obtainSIUrlResponseCode");
+
+ assertEquals("true", successIndicator);
+ assertEquals("true", found);
+ assertNotNull(resourceLink);
+ assertNotNull(response);
+ assertEquals("200", siUrlResponseCode);
+ assertEquals(null, workflowException);
+ }
+
+ @Test
+ @Deployment(resources = {"subprocess/GenericGetService.bpmn"})
+ public void testGenericGetService_success_serviceInstance_byNameServiceNotPresent() throws Exception{
+
+ MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByNameMultiCustomer.xml");
+ MockGetServiceInstance("CorporationNotPresent", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
+
+ Map<String, String> variables = new HashMap<String, String>();
+ setVariablesInstance(variables, null, "1604-MVM-26", "CorporationNotPresent", null);
+
+ WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetService", variables);
+ waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
+
+ String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_SuccessIndicator");
+ String found = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_FoundIndicator");
+ String resourceLink = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_resourceLink");
+ String response = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowResponse");
+ String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowException");
+ String siUrlResponseCode = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_obtainSIUrlResponseCode");
+
+ assertEquals("true", successIndicator);
+ assertEquals("false", found);
+ assertEquals(null, resourceLink);
+ assertEquals(" ", response);
+ assertEquals("200", siUrlResponseCode);
+ assertEquals(null, workflowException);
+ }
private void setVariablesInstance(Map<String, String> variables, String siId, String siName, String globalCustId, String serviceType) {
variables.put("isDebugLogEnabled", "true");
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
index 15dc4f4609..ce8eb7afec 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
@@ -61,7 +61,6 @@ import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.XMLUnit;
import org.jboss.resteasy.spi.AsynchronousResponse;
import org.json.JSONArray;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.openecomp.mso.bpmn.common.adapter.sdnc.CallbackHeader;
@@ -78,7 +77,7 @@ import org.openecomp.mso.bpmn.common.workflow.service.VnfAdapterNotifyServiceImp
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
-import org.openecomp.mso.bpmn.core.CamundaDBSetup;
+import org.openecomp.mso.bpmn.core.utils.CamundaDBSetup;
import org.openecomp.mso.bpmn.core.PropertyConfigurationSetup;
import org.openecomp.mso.bpmn.core.domain.Resource;
import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml b/bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml
new file mode 100644
index 0000000000..fce47fcd0d
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<search-results xmlns="http://org.openecomp.aai.inventory/v11">
+ <result-data>
+ <resource-type>service-instance</resource-type>
+ <resource-link>/aai/v11/business/customers/customer/AbcBank/service-subscriptions/service-subscription/ABC-ST/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET</resource-link>
+ </result-data>
+ <result-data>
+ <resource-type>service-instance</resource-type>
+ <resource-link>/aai/v11/business/customers/customer/XyCorporation/service-subscriptions/service-subscription/XY-ST/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET</resource-link>
+ </result-data>
+</search-results> \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/pom.xml b/bpmn/MSOCoreBPMN/pom.xml
index 6884c1e33b..267f175533 100644
--- a/bpmn/MSOCoreBPMN/pom.xml
+++ b/bpmn/MSOCoreBPMN/pom.xml
@@ -158,9 +158,10 @@
<version>20160212</version>
</dependency>
<dependency>
- <groupId>xmlunit</groupId>
- <artifactId>xmlunit</artifactId>
- <version>1.6</version>
+ <groupId>org.xmlunit</groupId>
+ <artifactId>xmlunit-core</artifactId>
+ <version>2.5.1</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.openecomp.so</groupId>
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java
index 66edaaae3c..64068d2b90 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java
@@ -23,6 +23,7 @@ package org.openecomp.mso.bpmn.core;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* An object that stores data for rollbacks. Data is organized by type. A
@@ -30,79 +31,72 @@ import java.util.Map;
* in the same object for separate rollback operations.
*/
public class RollbackData implements Serializable {
- private static final long serialVersionUID = 1L;
- private Map<String, Map<String, Serializable>> dictionary =
- new HashMap<String, Map<String, Serializable>>();
-
- /**
- * Returns true if the specified type is stored in this object.
- * @param type the data type
- */
- public boolean hasType(String type) {
- return dictionary.containsKey(type);
- }
+ private static final long serialVersionUID = 1L;
- /**
- * Stores a single item.
- * @param type the data type
- * @param key the key
- * @param value the value
- */
- public void put(String type, String key, String value) {
- Map<String, Serializable> mapForType = dictionary.get(type);
+ private Map<String, Map<String, Serializable>> dictionary =
+ new HashMap<String, Map<String, Serializable>>();
- if (mapForType == null) {
- mapForType = new HashMap<String, Serializable>();
- dictionary.put(type, mapForType);
- }
+ /**
+ * Returns true if the specified type is stored in this object.
+ *
+ * @param type the data type
+ */
+ public boolean hasType(String type) {
+ return dictionary.containsKey(type);
+ }
- mapForType.put(key, value);
- }
+ /**
+ * Stores a single item.
+ *
+ * @param type the data type
+ * @param key the key
+ * @param value the value
+ */
+ public void put(String type, String key, String value) {
+ Map<String, Serializable> mapForType = dictionary.get(type);
- /**
- * Gets a single item.
- * @param type the data type
- * @param key the key
- * @return the item or null if there is no item for the specified type and key
- */
- public Serializable get(String type, String key) {
- Map<String, Serializable> mapForType = dictionary.get(type);
+ if (mapForType == null) {
+ mapForType = new HashMap<String, Serializable>();
+ dictionary.put(type, mapForType);
+ }
- if (mapForType == null) {
- return null;
- }
+ mapForType.put(key, value);
+ }
- return mapForType.get(key);
- }
+ /**
+ * Gets a single item.
+ *
+ * @param type the data type
+ * @param key the key
+ * @return the item or null if there is no item for the specified type and key
+ */
+ public Serializable get(String type, String key) {
+ Map<String, Serializable> mapForType = dictionary.get(type);
- /**
- * Gets a map containing all items associated with the specified data type.
- * @param type the data type
- * @return a map, or null if there are no items associated with the specified
- * data type
- */
- public Map<String, Serializable> get(String type) {
- return dictionary.get(type);
- }
+ if (mapForType == null) {
+ return null;
+ }
- /**
- * Returns a string representation of this object.
- */
- public String toString() {
- StringBuilder out = new StringBuilder();
- out.append(getClass().getSimpleName());
- out.append('[');
- boolean hasOne = false;
- for (String type : dictionary.keySet()) {
- if (hasOne) {
- out.append(',');
- }
- out.append(type);
- out.append(dictionary.get(type));
- hasOne = true;
- }
- out.append(']');
- return out.toString();
- }
+ return mapForType.get(key);
+ }
+
+ /**
+ * Gets a map containing all items associated with the specified data type.
+ *
+ * @param type the data type
+ * @return a map, or null if there are no items associated with the specified data type
+ */
+ public Map<String, Serializable> get(String type) {
+ return dictionary.get(type);
+ }
+
+ /**
+ * Returns a string representation of this object.
+ */
+ @Override
+ public String toString() {
+ return dictionary.entrySet().stream().map(entry -> entry.getKey() + entry.getValue())
+ .collect(Collectors.joining(",", "[", "]"));
+ }
}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java
index ce66e06089..4d895f3279 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java
@@ -142,6 +142,7 @@ public abstract class JsonWrapper implements Serializable {
/**
* Returns a string representation of this object.
*/
+ @Override
public String toString() {
return this.toJsonString();
}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java
index 1e68c84878..0e985cc8f1 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java
@@ -31,9 +31,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
-import org.json.JSONObject;
import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
-
+import org.openecomp.mso.bpmn.core.json.JsonDecomposingException;
/**
@@ -50,7 +49,6 @@ import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
public class ServiceDecomposition extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
- DecomposeJsonUtil jsonUtils = new DecomposeJsonUtil();
@JsonProperty("modelInfo")
private ModelInfo modelInfo;
@@ -67,48 +65,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
private List <AllottedResource> allottedResources;
public ServiceDecomposition () {
- super();
- }
-
- public ServiceDecomposition (String catalogRestOutput) {
-
- ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
- this.modelInfo = serviceDecomposition.getModelInfo();
- this.vnfResources = serviceDecomposition.getServiceVnfs();
- this.allottedResources = serviceDecomposition.getServiceAllottedResources();
- this.networkResources = serviceDecomposition.getServiceNetworks();
- this.serviceRole = serviceDecomposition.getServiceRole();
- this.serviceType = serviceDecomposition.getServiceType();
- }
-
- /**
- * Constructor taking Catalog DB Adapter REST output (serviceResources model) + service Instance ID
- * @param catalogRestOutput
- * @param serviceInstanceId
- */
- public ServiceDecomposition (String catalogRestOutput, String serviceInstanceId) {
-
- ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
- this.modelInfo = serviceDecomposition.getModelInfo();
- this.vnfResources = serviceDecomposition.getServiceVnfs();
- this.allottedResources = serviceDecomposition.getServiceAllottedResources();
- this.networkResources = serviceDecomposition.getServiceNetworks();
-
- this.serviceRole = serviceDecomposition.getServiceRole();
- this.serviceType = serviceDecomposition.getServiceType();
-
- this.serviceInstance = new ServiceInstance();
- this.serviceInstance.setInstanceId(serviceInstanceId);
- }
-
- /**
- * Constructor taking a Service Decomposition JSON serialization
- * @param catalogRestOutput
- * @param serviceInstanceId
- */
- public ServiceDecomposition (JSONObject jsonServiceDecomposition, String serviceInstanceId) {
- //TODO provide constructor implementation
-
}
//*****
@@ -278,7 +234,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
* Add resource to the list
* Given a ResourceDecomposition (subclass) object, add it to the Service Decomposition (in the appropriate category, e.g. as a VNF, Network, or Allotted Resource).
* As dependencies are not currently supported, add it to the end of any ordered lists.
- * @param Resource
+ * @param resource
*/
public void addResource(Resource resource) {
//create resource based upon type
@@ -299,36 +255,36 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addVnfResource(String jsonResource) {
+ public void addVnfResource(String jsonResource) throws JsonDecomposingException {
VnfResource vnfResource = null;
- vnfResource = DecomposeJsonUtil.JsonToVnfResource(jsonResource);
+ vnfResource = DecomposeJsonUtil.jsonToVnfResource(jsonResource);
this.addVnfResource(vnfResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addNetworkResource(String jsonResource) {
+ public void addNetworkResource(String jsonResource) throws JsonDecomposingException {
NetworkResource networkResource = null;
- networkResource = DecomposeJsonUtil.JsonToNetworkResource(jsonResource);
+ networkResource = DecomposeJsonUtil.jsonToNetworkResource(jsonResource);
this.addVnfResource(networkResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addAllottedResource(String jsonResource) {
+ public void addAllottedResource(String jsonResource) throws JsonDecomposingException {
AllottedResource allottedResource = null;
- allottedResource = DecomposeJsonUtil.JsonToAllottedResource(jsonResource);
+ allottedResource = DecomposeJsonUtil.jsonToAllottedResource(jsonResource);
this.addVnfResource(allottedResource);
}
/**
* Given a ResourceDecomposition (subclass) object, locate it in the Service Decomposition by its unique ID, and replace the current version with the new one.
* This method should support concurrency control via an auto-incrementing field in the ResourceDecomposition class.
- * @param Resource
+ * @param newResource
* @return TRUE if replacement was a success
*/
public boolean replaceResource(Resource newResource){
@@ -365,7 +321,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
/**
* Given a resource object ID, locate it in the Service Decomposition by its unique ID, and delete it.
- * @param Resource
+ * @param resource
* @return TRUE if delete was a success
*/
public boolean deleteResource(Resource resource){
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java
index 71ef09ce33..dcd9e3b39a 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java
@@ -20,139 +20,102 @@
package org.openecomp.mso.bpmn.core.json;
-import java.io.Serializable;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
-
-
import org.openecomp.mso.bpmn.core.domain.AllottedResource;
import org.openecomp.mso.bpmn.core.domain.NetworkResource;
import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
+import org.openecomp.mso.bpmn.core.domain.ServiceInstance;
import org.openecomp.mso.bpmn.core.domain.VnfResource;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+public class DecomposeJsonUtil {
-import org.openecomp.mso.logger.MsoLogger;
+ private static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
-public class DecomposeJsonUtil implements Serializable {
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+ private DecomposeJsonUtil() {
+ }
- /**
- * Method to construct Service Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ServiceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {
-
- ServiceDecomposition serviceDecomposition = new ServiceDecomposition();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);
- } catch (JsonParseException e) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
-
- return serviceDecomposition;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static VnfResource JsonToVnfResource(String jsonString) {
-
- VnfResource vnfResource = new VnfResource();
+ private static ObjectMapper createObjectMapper() {
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- vnfResource = om.readValue(jsonString, VnfResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
- return vnfResource;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static NetworkResource JsonToNetworkResource(String jsonString) {
-
- NetworkResource networkResource = new NetworkResource();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- networkResource = om.readValue(jsonString, NetworkResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- return networkResource;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static AllottedResource JsonToAllottedResource(String jsonString) {
-
- AllottedResource allottedResource = new AllottedResource();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- allottedResource = om.readValue(jsonString, AllottedResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- return allottedResource;
- }
+ return om;
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, ServiceDecomposition.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to service decomposition", e);
+ }
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @param serviceInstanceId service instance id to be put in decoded ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString, String serviceInstanceId)
+ throws JsonDecomposingException {
+ ServiceDecomposition serviceDecomposition = jsonToServiceDecomposition(jsonString);
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstanceId(serviceInstanceId);
+ serviceDecomposition.setServiceInstance(serviceInstance);
+ return serviceDecomposition;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static VnfResource jsonToVnfResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, VnfResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to vnf resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static NetworkResource jsonToNetworkResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, NetworkResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to network resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static AllottedResource jsonToAllottedResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, AllottedResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
+ }
+ }
} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java
new file mode 100644
index 0000000000..352979e7dd
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.bpmn.core.json;
+
+import java.io.IOException;
+
+public class JsonDecomposingException extends IOException {
+
+ public JsonDecomposingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java
index 71ed0eae5e..c346308e2b 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java
@@ -323,6 +323,7 @@ public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin {
private void loadFromDB(DelegateExecution execution, ProcessEngineConfigurationImpl processEngineConfiguration) {
Command<List<URNMapping>> command = new Command<List<URNMapping>>() {
@SuppressWarnings("unchecked")
+ @Override
public List<URNMapping> execute(CommandContext commandContext) {
return (List<URNMapping>) commandContext.getDbSqlSession().selectList(
"mso.urnMapping.selectAll", null);
diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
index 7f922ce30e..58f1ae264d 100644
--- a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
@@ -36,26 +36,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- */
+ */
package org.openecomp.mso.bpmn.core;
-import java.io.BufferedReader;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.CharBuffer;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.xml.sax.SAXException;
-import org.custommonkey.xmlunit.Diff;
-
import org.openecomp.mso.bpmn.core.json.JsonUtils;
import org.openecomp.mso.bpmn.core.xml.XmlTool;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.DefaultNodeMatcher;
+import org.xmlunit.diff.Diff;
+import org.xmlunit.diff.ElementSelectors;
/**
* @version 1.0
@@ -63,8 +61,8 @@ import org.openecomp.mso.bpmn.core.xml.XmlTool;
public class JsonUtilsTest {
private static final String EOL = "\n";
- private String xmlReq =
- "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
+ private static final String XML_REQ =
+ "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
" <request-info>" + EOL +
" <request-id>DEV-VF-0021</request-id>" + EOL +
" <action>CREATE_VF_MODULE</action>" + EOL +
@@ -93,9 +91,9 @@ public class JsonUtilsTest {
" <param name=\"server\">server1111</param>" + EOL +
" </vnf-params> " + EOL +
"</vnf-request>" + EOL;
-
- private String xmlReqNoAttrs =
- "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
+
+ private static final String XML_REQ_NO_ATTRS =
+ "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
" <request-info>" + EOL +
" <action>DELETE_VF_MODULE</action>" + EOL +
" <source>PORTAL</source>" + EOL +
@@ -115,246 +113,214 @@ public class JsonUtilsTest {
" <vnf-params xmlns:tns=\"http://org.openecomp/mso/infra/vnf-request/v1\"/>" + EOL +
"</vnf-request>" + EOL;
- private String xmlArrayReq =
- "<ucpeInfo>" + EOL +
+ private static final String XML_ARRAY_REQ =
+ "<ucpeInfo>" + EOL +
" <outOfBandManagementModem>BROADBAND</outOfBandManagementModem>" + EOL +
- " <internetTopology>IVLAN</internetTopology>" + EOL +
- " <ucpeAliasHostName>SHELLUCPE31</ucpeAliasHostName>" + EOL +
- " <wanList>" + EOL +
- " <wanInfo>" + EOL +
- " <wanType>AVPN</wanType>" + EOL +
- " <interfaceType>1000BASE-T</interfaceType>" + EOL +
- " <transportProviderName>ATT</transportProviderName>" + EOL +
- " <circuitId>BT/SLIR/70911</circuitId>" + EOL +
- " <dualMode>Active</dualMode>" + EOL +
- " <wanPortNumber>WAN1</wanPortNumber>" + EOL +
- " <transportManagementOption>ATT</transportManagementOption>" + EOL +
- " <transportVendorTotalBandwidth>100</transportVendorTotalBandwidth>" + EOL +
- " <mediaType>ELECTRICAL</mediaType>" + EOL +
- " </wanInfo>" + EOL +
- " <wanInfo>" + EOL +
- " <wanType>AVPN</wanType>" + EOL +
- " <interfaceType>10/100/1000BASE-T</interfaceType>" + EOL +
- " <transportProviderName>ATT</transportProviderName>" + EOL +
- " <circuitId>AS/KRFN/34611</circuitId>" + EOL +
- " <dualMode>Active</dualMode>" + EOL +
- " <wanPortNumber>WAN2</wanPortNumber>" + EOL +
- " <transportManagementOption>ATT</transportManagementOption>" + EOL +
- " <transportVendorTotalBandwidth>10000</transportVendorTotalBandwidth>" + EOL +
- " <mediaType>MMF</mediaType>" + EOL +
- " </wanInfo>" + EOL +
- " </wanList>" + EOL +
- " <ucpeActivationCode>ASD-987-M31</ucpeActivationCode>" + EOL +
- " <ucpeHostName>USOSTCDALTX0101UJZZ31</ucpeHostName>" + EOL +
- " <ucpePartNumber>FG-VM00*</ucpePartNumber>" + EOL +
+ " <internetTopology>IVLAN</internetTopology>" + EOL +
+ " <ucpeAliasHostName>SHELLUCPE31</ucpeAliasHostName>" + EOL +
+ " <wanList>" + EOL +
+ " <wanInfo>" + EOL +
+ " <wanType>AVPN</wanType>" + EOL +
+ " <interfaceType>1000BASE-T</interfaceType>" + EOL +
+ " <transportProviderName>ATT</transportProviderName>" + EOL +
+ " <circuitId>BT/SLIR/70911</circuitId>" + EOL +
+ " <dualMode>Active</dualMode>" + EOL +
+ " <wanPortNumber>WAN1</wanPortNumber>" + EOL +
+ " <transportManagementOption>ATT</transportManagementOption>" + EOL +
+ " <transportVendorTotalBandwidth>100</transportVendorTotalBandwidth>" + EOL +
+ " <mediaType>ELECTRICAL</mediaType>" + EOL +
+ " </wanInfo>" + EOL +
+ " <wanInfo>" + EOL +
+ " <wanType>AVPN</wanType>" + EOL +
+ " <interfaceType>10/100/1000BASE-T</interfaceType>" + EOL +
+ " <transportProviderName>ATT</transportProviderName>" + EOL +
+ " <circuitId>AS/KRFN/34611</circuitId>" + EOL +
+ " <dualMode>Active</dualMode>" + EOL +
+ " <wanPortNumber>WAN2</wanPortNumber>" + EOL +
+ " <transportManagementOption>ATT</transportManagementOption>" + EOL +
+ " <transportVendorTotalBandwidth>10000</transportVendorTotalBandwidth>" + EOL +
+ " <mediaType>MMF</mediaType>" + EOL +
+ " </wanInfo>" + EOL +
+ " </wanList>" + EOL +
+ " <ucpeActivationCode>ASD-987-M31</ucpeActivationCode>" + EOL +
+ " <ucpeHostName>USOSTCDALTX0101UJZZ31</ucpeHostName>" + EOL +
+ " <ucpePartNumber>FG-VM00*</ucpePartNumber>" + EOL +
"</ucpeInfo>";
// JSON request w/ embedded XML will be read from a file
- private String jsonReq = null;
- private String jsonReqArray = null;
-
- @Before
- public void initialize() {
- File file = new File("src/test/resources/request.json");
- File file2 = new File("src/test/resources/requestArray.json");
- FileInputStream fis = null;
+ private static String jsonReq;
+ private static String jsonReqArray;
+
+ @BeforeClass
+ public static void initialize() throws Exception {
+ jsonReq = readFileToString("src/test/resources/request.json");
+ jsonReqArray = readFileToString("src/test/resources/requestArray.json");
+ }
- try {
- fis = new FileInputStream(file);
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- CharBuffer cbuf = CharBuffer.allocate((int)file.length()+1);
- br.read(cbuf);
- cbuf.flip();
- jsonReq = cbuf.toString();
- if (jsonReq != null) {
- System.out.println("initialize(): json request: " + jsonReq);
- } else {
- System.out.println("initialize(): failed to read json request from src/test/resources/request.json");
- }
- fis.close();
- fis = new FileInputStream(file2);
- br = new BufferedReader(new InputStreamReader(fis));
- cbuf = CharBuffer.allocate((int)file.length()+1);
- br.read(cbuf);
- cbuf.flip();
- jsonReqArray = cbuf.toString();
- if (jsonReq != null) {
- System.out.println("initialize(): json request w/ array: " + jsonReqArray);
- } else {
- System.out.println("initialize(): failed to read json request from src/test/resources/request2.json");
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (fis != null)
- fis.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
+ private static String readFileToString(String path) throws IOException {
+ File file = new File(path);
+ return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
}
-
- @After
- public void cleanup(){
+
+ @Test
+ public void shouldConvertXmlToJsonAndBackToSameXml() throws Exception {
+ // Note: the current version of the JsonUtils.json2xml() method
+ // does not support converting the JSONObject representation
+ // of XML attributes (JSONArray) back to XML. So this test will
+ // only succeed if the original XML does not contain attributes
+
+ // given
+ String xmlIn = XmlTool.removeNamespaces(XML_REQ_NO_ATTRS);
+ // when
+ String json = JsonUtils.xml2json(XML_REQ_NO_ATTRS);
+ String xmlOut = JsonUtils.json2xml(json);
+ // then
+ Diff diffXml = DiffBuilder.compare(xmlIn).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
}
@Test
-// @Ignore
- public void testConversion() {
- // Note: the current version of the JsonUtils.json2xml() method
- // does not support converting the JSONObject representation
- // of XML attributes (JSONArray) back to XML. So this test will
- // only succeed if the original XML does not contain attributes
-
- // save a copy of the xml with the namespaces removed
- String xmlIn = XmlTool.removeNamespaces(xmlReqNoAttrs);
- // strip all the non-data whitespace
- xmlIn = xmlIn.replaceAll(">\\s*<", "><");
- String json = JsonUtils.xml2json(xmlReqNoAttrs);
- System.out.println("testConversion(): xml request to json: " + json);
- String xmlOut = JsonUtils.json2xml(json);
- System.out.println("testConversion(): json request back to xml: " + xmlOut);
-
- // strip all the non-data whitespace
- xmlOut = xmlOut.replaceAll(">\\s*<", "><");
+ public void shouldReadValuesForAbsoluteJsonPaths() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-name")).isEqualTo("STMTN5MMSC21");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.request-info.action")).isEqualTo("CREATE_VF_MODULE");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.persona-model-version")).isEqualTo("1");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-persona-model-version")).isEqualTo("1.5");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.is-base-module")).isEqualTo("true");
+ }
- Diff diffXml;
- try {
- diffXml = new Diff(xmlIn, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ @Test
+ public void shouldReturnValueForJsonKey() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValueForKey(json, "source")).isEqualTo("PORTAL");
}
@Test
-// @Ignore
- public void testRetrieval() {
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testRetrieval(): xml request to json: " + json);
- // full JSON path
- String value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC21");
- value = JsonUtils.getJsonValue(json, "vnf-request.request-info.action");
- Assert.assertEquals(value, "CREATE_VF_MODULE");
- // retrieving an integer
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.persona-model-version");
- Assert.assertEquals(value, "1");
- // retrieving a float
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-persona-model-version");
- Assert.assertEquals(value, "1.5");
- // retrieving a boolean
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.is-base-module");
- Assert.assertEquals(value, "true");
- // attempt to retrieve a value for a non-existent field
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.bad");
- Assert.assertEquals(value, null);
- // retrieving a parameter/array value (originally a XML attribute)
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name");
- Assert.assertEquals(value, "network");
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content");
- Assert.assertEquals(value, "network1111");
- // retrieving a parameter/array value by index
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content", 1);
- Assert.assertEquals(value, "server1111");
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 1);
- Assert.assertEquals(value, "server");
- // failure due to invalid parameter name
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "badParam");
- Assert.assertEquals(value, null);
- // failure due to array index out of bounds
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 2);
- Assert.assertEquals(value, null);
- // by field name/key
- value = JsonUtils.getJsonValueForKey(json, "source");
- Assert.assertEquals(value, "PORTAL");
- value = JsonUtils.getJsonValueForKey(json, "vnf-module");
- Assert.assertEquals(value, null);
+ public void shouldReturnNullForNonexistentJsonNode() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValueForKey(json, "nonexistent-node")).isNull();
}
@Test
-// @Ignore
- public void testUpdate() {
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testUpdate(): xml request to json: " + json);
- // the add should be successful
- String jsonUpd = JsonUtils.addJsonValue(json, "vnf-request.request-info.comment", "Some comment");
- String value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.request-info.comment");
- Assert.assertEquals(value, "Some comment");
- // the add should be ignored as the field already exists
- jsonUpd = JsonUtils.addJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name", "STMTN5MMSC22");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC21");
- // the update should be successful
- jsonUpd = JsonUtils.updJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name", "STMTN5MMSC22");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC22");
- // the delete should be successful
- jsonUpd = JsonUtils.delJsonValue(jsonUpd, "vnf-request.request-info.comment");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.request-info.comment");
- Assert.assertEquals(value, null);
- // the delete should fail as field 'vnf-model' does not exist
- String jsonCur = jsonUpd;
- jsonUpd = JsonUtils.delJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-module");
- Assert.assertEquals(jsonCur, jsonUpd);
+ public void shouldReturnNullForNonExistentParameter() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.bad")).isNull();
}
-
+
@Test
-// @Ignore
- public void testEmbededXmlRetrievalConversion() {
- try {
- // extract the embedded XML from the request
- String value = JsonUtils.getJsonValue(jsonReq, "variables.bpmnRequest.value");
- String xmlReq = XmlTool.removeNamespaces(XmlTool.normalize(value));
- System.out.println("testEmbededXmlRetrievalConversion(): xml payload: " + xmlReq);
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testEmbededXmlRetrievalConversion(): xml request to json: " + json);
- String xmlOut = JsonUtils.json2xml(json);
- System.out.println("testEmbededXmlRetrievalConversion(): json request back to xml: " + xmlOut);
- Diff diffXml;
- try {
- // compare the XML before and after
- diffXml = new Diff(xmlReq, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public void shouldGetJasonParametersFromArray() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name")).isEqualTo("network");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content"))
+ .isEqualTo("network1111");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 1)).isEqualTo("server");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content", 1))
+ .isEqualTo("server1111");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "badParam"))
+ .withFailMessage("Expected null for nonexistent param").isNull();
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 2))
+ .withFailMessage("Expected null for index out of bound").isNull();
}
@Test
-// @Ignore
- // Tests the conversion of a JSON Doc containing a JSON Array to XML
- public void testConversionArray() {
- try {
- String jsonParm = JsonUtils.getJsonNodeValue(jsonReqArray, "requestDetails.requestParameters.ucpeInfo");
- System.out.println("testConversionArray(): json value: " + JsonUtils.prettyJson(jsonParm));
- String xmlOut = JsonUtils.json2xml(jsonParm);
- System.out.println("testConversionArray(): json parameters to xml: " + xmlOut);
- // strip all the non-data whitespace
- xmlOut = xmlOut.replaceAll(">\\s*<", "><");
- System.out.println("testConversionArray(): XML after removing whitespace:" + xmlOut);
- String xmlTest = xmlArrayReq.replaceAll(">\\s*<", "><");
+ public void shouldAddJsonValue() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.request-info.comment";
+ String value = "Some comment";
+ // when
+ String jsonUpd = JsonUtils.addJsonValue(json, key, value);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isEqualTo(value);
+ }
- Diff diffXml;
- try {
- diffXml = new Diff(xmlTest, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ @Test
+ public void shouldIgnoreAddIfFieldAlreadyExists() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String newValue = "STMTN5MMSC22";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.addJsonValue(json, key, newValue);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isEqualTo(oldValue).isNotEqualTo(newValue);
+ }
+
+ @Test
+ public void shouldUpdateValueInJson() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String newValue = "STMTN5MMSC22";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.updJsonValue(json, key, newValue);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isNotEqualTo(oldValue).isEqualTo(newValue);
+ }
+
+ @Test
+ public void shouldDeleteValue() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.delJsonValue(json, key);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isNotEqualTo(oldValue).isNull();
+ }
+
+ @Test
+ public void shouldReturnOriginalJsonWhenTryingToRemoveNonexistentField() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.does-not-exist";
+ // when
+ String jsonUpd = JsonUtils.delJsonValue(json, key);
+ // then
+ assertThat(jsonUpd).isEqualTo(json);
+ }
+
+ @Test
+ public void shouldConvertXmlToJsonAndBackToSameXmlExtractedFromTheRequest() throws Exception {
+ // given
+ String value = JsonUtils.getJsonValue(jsonReq, "variables.bpmnRequest.value");
+ String xmlReq = XmlTool.removeNamespaces(XmlTool.normalize(value));
+ // when
+ String json = JsonUtils.xml2json(xmlReq);
+ String xmlOut = JsonUtils.json2xml(json);
+ // then
+ Diff diffXml = DiffBuilder.compare(xmlReq).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
+ }
+
+ @Test
+ public void shouldConvertJsonContainingArrayToXml() throws Exception {
+ // when
+ String jsonParm = JsonUtils.getJsonNodeValue(jsonReqArray, "requestDetails.requestParameters.ucpeInfo");
+ String xmlOut = JsonUtils.json2xml(jsonParm);
+ // then
+ Diff diffXml = DiffBuilder.compare(XML_ARRAY_REQ).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
}
}
diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/RollbackDataTest.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/RollbackDataTest.java
new file mode 100644
index 0000000000..c51af23e30
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/RollbackDataTest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.bpmn.core;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+import org.junit.Test;
+
+public class RollbackDataTest {
+
+ private final static String TYPE_A = "typeA";
+ private final static String TYPE_B = "typeB";
+ private static final String KEY_1 = "key1";
+ private static final String VALUE_1 = "value1";
+ private static final String VALUE_2 = "value2";
+
+ @Test
+ public void shouldReturnStringRepresentationOfDataInAnyPermutation() throws Exception {
+ // given
+ RollbackData data = new RollbackData();
+ data.put(TYPE_A, KEY_1, VALUE_1);
+ data.put(TYPE_A, "key2", "value2");
+ data.put(TYPE_B, "key3", "value3");
+ // when, then
+ assertThat(data.toString()).isIn(
+ "[typeB{key3=value3},typeA{key1=value1, key2=value2}]",
+ "[typeB{key3=value3},typeA{key2=value2, key1=value1}]",
+ "[typeA{key1=value1, key2=value2},typeB{key3=value3}]",
+ "[typeA{key2=value2, key1=value1},typeB{key3=value3}]");
+ }
+
+ @Test
+ public void shouldBeEmptyOnCreation() throws Exception {
+ // given
+ RollbackData data = new RollbackData();
+ // then
+ assertThat(data.hasType(TYPE_A)).isFalse();
+ assertThat(data.get(TYPE_A, KEY_1)).isNull();
+ }
+
+ @Test
+ public void shouldHaveTypeAfterPuttingDataOfThatType() throws Exception {
+ // given
+ RollbackData data = new RollbackData();
+ // when
+ data.put(TYPE_A, KEY_1, VALUE_1);
+ // then
+ assertThat(data.hasType(TYPE_A)).isTrue();
+ assertThat(data.hasType(TYPE_B)).isFalse();
+ assertThat(data.get(TYPE_A, KEY_1)).isEqualTo(VALUE_1);
+ }
+
+ @Test
+ public void shouldKeepTwoValuesWithSameKeysButDifferentTypes() throws Exception {
+ // given
+ RollbackData data = new RollbackData();
+ // when
+ data.put(TYPE_A, KEY_1, VALUE_1);
+ data.put(TYPE_B, KEY_1, VALUE_2);
+ // then
+ assertThat(data.get(TYPE_A, KEY_1)).isEqualTo(VALUE_1);
+ assertThat(data.get(TYPE_A)).containsExactly(entry(KEY_1, VALUE_1));
+ assertThat(data.get(TYPE_B, KEY_1)).isEqualTo(VALUE_2);
+ assertThat(data.get(TYPE_B)).containsExactly(entry(KEY_1, VALUE_2));
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
index 862cb76146..9730b129be 100644
--- a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.openecomp.mso.bpmn.core.utils.CamundaDBSetup;
import org.openecomp.mso.logger.MsoLogger;
/**
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java
index 9a8cad6b86..f29ccc75e0 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.bpmn.core;
+package org.openecomp.mso.bpmn.core.utils;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -35,9 +35,6 @@ public class CamundaDBSetup {
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
private CamundaDBSetup() {
- /**
- * Constructor.
- */
}
public static synchronized void configure() throws SQLException {
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy
index 862c46ad19..308834038e 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy
+++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy
@@ -54,7 +54,6 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor {
JsonUtils jsonUtil = new JsonUtils()
VidUtils vidUtils = new VidUtils(this)
CatalogDbUtils cutils = new CatalogDbUtils()
- DecomposeJsonUtil decomposeJsonUtil = new DecomposeJsonUtil()
/**
* This method gets and validates the incoming
@@ -185,7 +184,7 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor {
utils.log("DEBUG", "obtained VNF list")
// Only one match here
JSONObject vnfObject = vnfs[0]
- vnf = decomposeJsonUtil.JsonToVnfResource(vnfObject.toString())
+ vnf = DecomposeJsonUtil.jsonToVnfResource(vnfObject.toString())
}
utils.log("DEBUG", "Read vnfResource", isDebugLogEnabled)
if (vnf == null) {
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
index 823223fbd8..dfa390c296 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
+++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
@@ -115,14 +115,11 @@ public abstract class AbstractSdncOperationTask extends BaseTask {
protected String httpPost(String url, HttpPost httpPost) throws RouteException {
logger.info("AbstractSdncOperationTask.httpPost begin!");
- CloseableHttpClient httpClient = HttpClients.createDefault();
String result = null;
- boolean var15 = false;
String errorMsg;
label91: {
- try {
- var15 = true;
+ try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
result = EntityUtils.toString(closeableHttpResponse.getEntity());
logger.info("result = {}", result);
@@ -133,42 +130,14 @@ public abstract class AbstractSdncOperationTask extends BaseTask {
}
closeableHttpResponse.close();
- var15 = false;
break label91;
- } catch (IOException var19) {
+ } catch (IOException e) {
errorMsg = url + ":httpPostWithJSON connect faild";
logger.info("exception: POST_CONNECT_FAILD : {}", errorMsg);
- throwsRouteException(errorMsg, var19, "POST_CONNECT_FAILD");
- var15 = false;
- } finally {
- if(var15) {
- try {
- httpClient.close();
- } catch (IOException var16) {
- String errorMsg1 = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg1);
- throwsRouteException(errorMsg1, var16, "CLOSE_CONNECT_FAILD");
- }
-
- }
- }
-
- try {
- httpClient.close();
- } catch (IOException var17) {
- errorMsg = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg);
- throwsRouteException(errorMsg, var17, "CLOSE_CONNECT_FAILD");
+ throwsRouteException(errorMsg, e, "POST_CONNECT_FAILD");
}
}
- try {
- httpClient.close();
- } catch (IOException var18) {
- errorMsg = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg);
- throwsRouteException(errorMsg, var18, "CLOSE_CONNECT_FAILD");
- }
logger.info("AbstractSdncOperationTask.httpPost end!");
return result;
}
@@ -223,78 +192,27 @@ public abstract class AbstractSdncOperationTask extends BaseTask {
private String httpGet(String url, HttpGet httpGet) throws RouteException {
logger.info("AbstractSdncOperationTask.httpGet begin!");
- boolean var16 = false;
- CloseableHttpClient httpClient = HttpClients.createDefault();
String result = "";
String errorMsg;
- label109:
- {
- label110:
- {
- try {
- var16 = true;
- CloseableHttpResponse e = httpClient.execute(httpGet);
- result = EntityUtils.toString(e.getEntity());
- logger.info("result = {}", result);
- if (e.getStatusLine().getStatusCode() != 200) {
- logger.info("exception: fail for status code = {}", e.getStatusLine().getStatusCode());
+ try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
+ CloseableHttpResponse e = httpClient.execute(httpGet);
+ result = EntityUtils.toString(e.getEntity());
+ logger.info("result = {}", result);
+ if (e.getStatusLine().getStatusCode() != 200) {
+ logger.info("exception: fail for status code = {}", e.getStatusLine().getStatusCode());
throw new RouteException(result, "SERVICE_GET_ERR");
}
-
e.close();
- var16 = false;
- break label110;
- } catch (ClientProtocolException var21) {
- errorMsg = url + ":httpGetWithJSON connect faild";
- logger.info("exception: GET_CONNECT_FAILD {}", errorMsg);
- throwsRouteException(errorMsg, var21, "GET_CONNECT_FAILD");
- var16 = false;
- } catch (IOException var22) {
- errorMsg = url + ":httpGetWithJSON connect faild";
- logger.info("exception: GET_CONNECT_FAILD {}", errorMsg);
- throwsRouteException(errorMsg, var22, "GET_CONNECT_FAILD");
- var16 = false;
- break label109;
- } finally {
- if (var16) {
- try {
- httpClient.close();
- } catch (IOException var17) {
- String errorMsg1 = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg1);
- throwsRouteException(errorMsg1, var17, "CLOSE_CONNECT_FAILD");
- }
-
- }
- }
+ } catch (ClientProtocolException e) {
+ errorMsg = url + ":httpGetWithJSON connect faild";
+ logger.info("exception: GET_CONNECT_FAILD {}", errorMsg);
+ throwsRouteException(errorMsg, e, "GET_CONNECT_FAILD");
+ } catch (IOException e) {
+ errorMsg = url + ":httpGetWithJSON connect faild";
+ logger.info("exception: GET_CONNECT_FAILD {}", errorMsg);
+ throwsRouteException(errorMsg, e, "GET_CONNECT_FAILD");
+ }
- try {
- httpClient.close();
- } catch (IOException var19) {
- errorMsg = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg);
- throwsRouteException(errorMsg, var19, "CLOSE_CONNECT_FAILD");
- }
-
- }
-
- try {
- httpClient.close();
- } catch (IOException var20) {
- errorMsg = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg);
- throwsRouteException(errorMsg, var20, "CLOSE_CONNECT_FAILD");
- }
-
- }
-
- try {
- httpClient.close();
- } catch (IOException var18) {
- errorMsg = url + ":close httpClient faild";
- logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg);
- throwsRouteException(errorMsg, var18, "CLOSE_CONNECT_FAILD");
- }
logger.info("AbstractSdncOperationTask.httpGet end!");
return result;
}
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java
index 21c00918d3..571db76399 100644
--- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java
+++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java
@@ -79,8 +79,8 @@ public class CreateGenericALaCarteServiceInstanceTest extends WorkflowTest {
MockGetCustomer("MCBH-1610", "CreateServiceInstance/createServiceInstance_queryGlobalCustomerId_AAIResponse_Success.xml");
MockPutServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "");
MockGetServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "GenericFlows/getServiceInstance.xml");
- MockNodeQueryServiceInstanceByName("RAATest-1", "");
- MockNodeQueryServiceInstanceById("RaaTest-1-id", "");
+ MockNodeQueryServiceInstanceByName("RAATest-1", null);
+ MockNodeQueryServiceInstanceById("RaaTest-1-id", null);
//SDNC
mockSDNCAdapter(200);
//DB