summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test/java/org/onap
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-01 12:48:00 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-01 12:48:14 -0500
commit09940a4aacf2fb32eddc85dd49f5a17dedff9de0 (patch)
treeca2a09e6cf184da0131b2fa3cc53decf94c69f13 /adapters/mso-adapter-utils/src/test/java/org/onap
parent244d353aeda3662d57c6629eb95ee4791b7c07f1 (diff)
vnf spin up gr api vnf s base module fails
map object representations of json back to json strings marshal all objects to json strings before sending all input params converted to Map<String, Object> Updated userParams map from HashMap<String, String> to Map<String, Object> as HashMap<String, String> userParams was causing VNF spin up to fail. Input json in Userparams was not accepted as a valid json format. Updated other files that were affected by this change. Change-Id: I0c00fc00c4c11b54ace4df7be8d5bfc80d41d130 Issue-ID: SO-1582 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java/org/onap')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java56
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java67
2 files changed, 104 insertions, 19 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java
index 7c5111bd18..f63aab7ce1 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java
@@ -23,7 +23,7 @@ package org.onap.so.cloudify.utils;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -33,7 +33,9 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -52,17 +54,23 @@ import org.onap.so.adapters.vdu.VduModelInfo;
import org.onap.so.adapters.vdu.VduStateType;
import org.onap.so.adapters.vdu.VduStatus;
import org.onap.so.cloud.CloudConfig;
-import org.onap.so.cloudify.beans.DeploymentInfoBuilder;
-import org.onap.so.db.catalog.beans.CloudIdentity;
-import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.cloudify.beans.DeploymentInfo;
+import org.onap.so.cloudify.beans.DeploymentInfoBuilder;
import org.onap.so.cloudify.beans.DeploymentStatus;
import org.onap.so.cloudify.v3.client.Cloudify;
import org.onap.so.cloudify.v3.model.AzureConfig;
+import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.beans.CloudifyManager;
import org.onap.so.db.catalog.beans.HeatTemplateParam;
import org.onap.so.openstack.exceptions.MsoAdapterException;
import org.onap.so.openstack.exceptions.MsoException;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
public class MsoCloudifyUtilsTest {
@@ -282,21 +290,31 @@ public class MsoCloudifyUtilsTest {
}
@Test
- public void convertInputValue_successful() {
- MsoCloudifyUtils testedObject = new MsoCloudifyUtils();
-
- HeatTemplateParam heatTemplateParam = new HeatTemplateParam();
- heatTemplateParam.setParamType("number");
- Object result = testedObject.convertInputValue("5", heatTemplateParam);
- assertTrue(result instanceof Integer);
-
- heatTemplateParam.setParamType("json");
- Object result2 = testedObject.convertInputValue("{\"key\": \"value\"}", heatTemplateParam);
- assertTrue(result2 instanceof JsonNode);
+ public void convertInputValueTest() throws JsonParseException, JsonMappingException, IOException {
+ MsoCloudifyUtils utils = new MsoCloudifyUtils();
+ ObjectMapper mapper = new ObjectMapper();
+ HeatTemplateParam paramNum = new HeatTemplateParam();
+ paramNum.setParamType("number");
+ paramNum.setParamName("my-number");
+
+ HeatTemplateParam paramString = new HeatTemplateParam();
+ paramString.setParamType("string");
+ paramString.setParamName("my-string");
+
+ HeatTemplateParam paramJson = new HeatTemplateParam();
+ paramJson.setParamType("json");
+ paramJson.setParamName("my-json");
+
+ Map<String, Object> jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference<Map<String, Object>>(){});
+
+ assertEquals(3, utils.convertInputValue("3", paramNum));
+ assertEquals("hello", utils.convertInputValue("hello", paramString));
+ JSONAssert.assertEquals(getJson("free-form.json"), utils.convertInputValue(jsonMap, paramJson).toString(), false);
+
+ }
- heatTemplateParam.setParamType("boolean");
- Object result3 = testedObject.convertInputValue("true", heatTemplateParam);
- assertTrue(result3 instanceof Boolean);
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/MsoHeatUtils/" + filename)));
}
private void mockCloudConfig(MsoCloudifyUtils testedObjectSpy) {
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java
new file mode 100644
index 0000000000..40bbe90218
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java
@@ -0,0 +1,67 @@
+package org.onap.so.openstack.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+import org.onap.so.db.catalog.beans.HeatTemplate;
+import org.onap.so.db.catalog.beans.HeatTemplateParam;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class MsoHeatUtilsUnitTest {
+
+
+ private ObjectMapper mapper = new ObjectMapper();
+ @Test
+ public void convertInputMapTest() throws JsonParseException, JsonMappingException, IOException {
+ MsoHeatUtils utils = new MsoHeatUtils();
+
+ Map<String, Object> input = new HashMap<>();
+ HeatTemplate template = new HeatTemplate();
+ template.setArtifactUuid("my-uuid");
+ Set<HeatTemplateParam> parameters = template.getParameters();
+ HeatTemplateParam paramNum = new HeatTemplateParam();
+ paramNum.setParamType("number");
+ paramNum.setParamName("my-number");
+ input.put("my-number", "3");
+
+ HeatTemplateParam paramString = new HeatTemplateParam();
+ paramString.setParamType("string");
+ paramString.setParamName("my-string");
+ input.put("my-string", "hello");
+
+ HeatTemplateParam paramJson = new HeatTemplateParam();
+ paramJson.setParamType("json");
+ paramJson.setParamName("my-json");
+
+ Map<String, Object> jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference<Map<String, Object>>(){});
+ input.put("my-json", jsonMap);
+
+ parameters.add(paramNum);
+ parameters.add(paramString);
+ parameters.add(paramJson);
+
+ Map<String, Object> output = utils.convertInputMap(input, template);
+
+ assertEquals(3, output.get("my-number"));
+ assertEquals("hello", output.get("my-string"));
+ JSONAssert.assertEquals(getJson("free-form.json"), (String)output.get("my-json"), false);
+ }
+
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/MsoHeatUtils/" + filename)));
+ }
+
+}