aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java8
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java20
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java117
3 files changed, 141 insertions, 4 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index 012c560689..47ff6c1b5f 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -1330,13 +1330,13 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
logger.debug("Parameter: {} is of type {}", key, type);
if ("string".equalsIgnoreCase(type)) {
// Easiest!
- String str = inputs.get(key).toString();
+ String str = inputs.get(key) != null ? inputs.get(key).toString() : null;
if (alias)
newInputs.put(realName, str);
else
newInputs.put(key, str);
} else if ("number".equalsIgnoreCase(type)) {
- String integerString = inputs.get(key).toString();
+ String integerString = inputs.get(key) != null ? inputs.get(key).toString() : null;
Integer anInteger = null;
try {
anInteger = Integer.parseInt(integerString);
@@ -1375,7 +1375,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
else
newInputs.put(key, json);
} else if ("comma_delimited_list".equalsIgnoreCase(type)) {
- String commaSeparated = inputs.get(key).toString();
+ String commaSeparated = inputs.get(key) != null ? inputs.get(key).toString() : null;
try {
List<String> anArrayList = this.convertCdlToArrayList(commaSeparated);
if (alias)
@@ -1390,7 +1390,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
newInputs.put(key, commaSeparated);
}
} else if ("boolean".equalsIgnoreCase(type)) {
- String booleanString = inputs.get(key).toString();
+ String booleanString = inputs.get(key) != null ? inputs.get(key).toString() : null;
Boolean aBool = Boolean.valueOf(booleanString);
if (alias)
newInputs.put(realName, aBool);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
index 70617fda4a..8469ad506c 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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=========================================================
+ */
+
/*
* ============LICENSE_START==========================================
* ONAP - SO
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
index 66d6f59e79..9edc805cf3 100644
--- 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
@@ -1,12 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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.onap.so.openstack.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -71,6 +95,99 @@ public class MsoHeatUtilsUnitTest {
JSONAssert.assertEquals(getJson("free-form.json"), mapper.writeValueAsString(output.get("my-json-escaped")), false);
}
+ @Test
+ public final void convertInputMapValuesTest() {
+ MsoHeatUtils utils = new MsoHeatUtils();
+ Map<String, Object> inputs = new HashMap<>();
+ Set<HeatTemplateParam> params = new HashSet<>();
+ HeatTemplate ht = new HeatTemplate();
+ HeatTemplateParam htp = new HeatTemplateParam();
+ htp.setParamName("vnf_name");
+ htp.setParamType("string");
+ params.add(htp);
+ inputs.put("vnf_name", "a_vnf_name");
+ htp = new HeatTemplateParam();
+ htp.setParamName("image_size");
+ htp.setParamType("number");
+ params.add(htp);
+ inputs.put("image_size", "1024");
+ htp = new HeatTemplateParam();
+ htp.setParamName("external");
+ htp.setParamType("boolean");
+ params.add(htp);
+ inputs.put("external", "false");
+ htp = new HeatTemplateParam();
+ htp.setParamName("oam_ips");
+ htp.setParamType("comma_delimited_list");
+ params.add(htp);
+ inputs.put("oam_ips", "a,b");
+ htp = new HeatTemplateParam();
+ htp.setParamName("oam_prefixes");
+ htp.setParamType("json");
+ params.add(htp);
+ String jsonEscInput = "[{\"prefix\": \"aValue\"}, {\"prefix\": \"aValue2\"}]";
+ inputs.put("oam_prefixes", jsonEscInput);
+ ht.setParameters(params);
+
+ Map<String, Object> output = utils.convertInputMap(inputs, ht);
+
+ assertEquals("a_vnf_name", output.get("vnf_name"));
+ assertEquals(1024, output.get("image_size"));
+ assertEquals(false, output.get("external"));
+ List<String> cdl = new ArrayList<>();
+ cdl.add(0, "a");
+ cdl.add(1, "b");
+ assertEquals(cdl, output.get("oam_ips"));
+ ObjectMapper JSON_MAPPER = new ObjectMapper();
+ JsonNode jn = null;
+ try {
+ jn = JSON_MAPPER.readTree(jsonEscInput);
+ } catch (Exception e) {
+ }
+ assertEquals(jn, output.get("oam_prefixes"));
+ }
+
+ @Test
+ public final void convertInputMapNullsTest() {
+ MsoHeatUtils utils = new MsoHeatUtils();
+ Map<String, Object> inputs = new HashMap<>();
+ Set<HeatTemplateParam> params = new HashSet<>();
+ HeatTemplate ht = new HeatTemplate();
+ HeatTemplateParam htp = new HeatTemplateParam();
+ htp.setParamName("vnf_name");
+ htp.setParamType("string");
+ params.add(htp);
+ inputs.put("vnf_name", null);
+ htp = new HeatTemplateParam();
+ htp.setParamName("image_size");
+ htp.setParamType("number");
+ params.add(htp);
+ inputs.put("image_size", null);
+ htp = new HeatTemplateParam();
+ htp.setParamName("external");
+ htp.setParamType("boolean");
+ params.add(htp);
+ inputs.put("external", null);
+ htp = new HeatTemplateParam();
+ htp.setParamName("oam_ips");
+ htp.setParamType("comma_delimited_list");
+ params.add(htp);
+ inputs.put("oam_ips", null);
+ htp = new HeatTemplateParam();
+ htp.setParamName("oam_prefixes");
+ htp.setParamType("json");
+ params.add(htp);
+ inputs.put("oam_prefixes", null);
+ ht.setParameters(params);
+
+ Map<String, Object> output = utils.convertInputMap(inputs, ht);
+
+ assertNull(output.get("vnf_name"));
+ assertNull(output.get("image_size"));
+ assertEquals(false, output.get("external"));
+ assertNull(output.get("oam_ips"));
+ assertNull(output.get("oam_prefixes"));
+ }
private String getJson(String filename) throws IOException {
return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/MsoHeatUtils/" + filename)));