From 8ac648a7e1148caca6d8a3bab799893393246d8a Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Tue, 22 Jan 2019 14:27:55 +0530 Subject: Fix Integer cast exception in getResourceInput Fix Integer cast exception in getResourceInput. Change-Id: I2022ec07fe12bfe1764f734f1776f6bd32143b84 Issue-ID: SO-1408 Signed-off-by: subhash kumar singh --- .../installer/heat/ToscaResourceInstaller.java | 2 +- .../installer/heat/ToscaResourceInputTest.java | 49 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index b3fda73045..aa1e1a8bd9 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -425,7 +425,7 @@ public class ToscaResourceInstaller { if(input.getName().equals(inputName)) { // keep both input name and default value // if service input does not supplies value the use default value - String defaultValue = input.getDefault() != null ? (String) input.getDefault() : ""; + String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : ""; output = inputName + "|" + defaultValue;// return default value } } diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java index e738235a0a..bc9275bb51 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java @@ -133,4 +133,53 @@ public class ToscaResourceInputTest { String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1"); assertEquals("{\\\"prop1\\\":\\\"res_key|default_value\\\"}", resourceInput); } + + @Test + public void resouceInputGetInputDefaultIntegerTest() throws ArtifactInstallerException { + ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller(); + ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(); + + toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper); + + HashMap hashMap = new HashMap(); + hashMap.put("customizationUUID", "id1"); + Metadata metadata = new Metadata(hashMap); + + LinkedHashMap propertyMap = new LinkedHashMap(); + propertyMap.put("prop1", property); + + when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate)); + when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input)); + when(nodeTemplate.getMetaData()).thenReturn(metadata); + when(nodeTemplate.getProperties()).thenReturn(propertyMap); + when(property.getValue()).thenReturn(getInput); + when(getInput.getInputName()).thenReturn("res_key"); + when(input.getName()).thenReturn("res_key"); + when(input.getDefault()).thenReturn(new Integer(10)); + + String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1"); + assertEquals("{\\\"prop1\\\":\\\"res_key|10\\\"}", resourceInput); + } + + @Test + public void resouceInputGetInputNoPropertyTest() throws ArtifactInstallerException { + ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller(); + ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(); + + toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper); + + HashMap hashMap = new HashMap(); + hashMap.put("customizationUUID", "id1"); + Metadata metadata = new Metadata(hashMap); + + LinkedHashMap propertyMap = new LinkedHashMap(); + + when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate)); + when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input)); + when(nodeTemplate.getMetaData()).thenReturn(metadata); + when(nodeTemplate.getProperties()).thenReturn(propertyMap); + + String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1"); + assertEquals("{}", resourceInput); + } } -- cgit 1.2.3-korg