Fix issue with null Pointer for Inputs of type list/map 67/98367/3
authoraosull01 <adrian.osullivan@huawei.com>
Wed, 13 Nov 2019 15:17:49 +0000 (15:17 +0000)
committerMatthieu Geerebaert <matthieu.geerebaert@orange.com>
Wed, 13 Nov 2019 15:39:50 +0000 (15:39 +0000)
Issue-ID: EXTAPI-354
Signed-off-by: aosull01 <adrian.osullivan@huawei.com>
Change-Id: I5650233598618982c023fa5b786b049981efbaca

src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java
src/test/resources/toscafile/service-MscmEvplService-csar.csar [new file with mode: 0644]

index 649ae22..97bcd9c 100644 (file)
@@ -124,8 +124,13 @@ public class ToscaInfosProcessor {
 
     if (inputs != null && inputs.size() > 0) {
       for (Input input : inputs) {
-        Property property = PropertyBuilder.build(input.getType(), null, null);
-        property.setDescription(input.getDescription());
+       Property property = null;
+       if (input.getType().equals("list") ||  input.getType().equals("map"))
+               property = PropertyBuilder.build("array", null, null);
+       else
+               property = PropertyBuilder.build(input.getType(), null, null);
+
+       property.setDescription(input.getDescription());
         property.setRequired(input.isRequired());
 
         if (input.getDefault() != null) {
index 0043a8a..9742d88 100644 (file)
@@ -202,4 +202,52 @@ public class ToscaInfosProcessorTest {
     }
     assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
   }
+  
+  
+  @Test
+  public void testBuildAndSaveResponseWithSdcToscaParserWithInputListType() {
+
+    ClassLoader classLoader = getClass().getClassLoader();
+    Path path = new File(
+        classLoader.getResource("toscafile/service-MscmEvplService-csar.csar").getFile())
+            .toPath().toAbsolutePath();
+
+    LinkedHashMap response = new LinkedHashMap();
+    response.put("version", "1.0");
+    response.put("name", "MSCM-EVPL-Service");
+    response.put("description", "MSCM EVPL Service");
+    response.put("id", "66a66cc3-178c-45fd-82c2-494336cb3665");
+
+    List<LinkedHashMap> resources = new ArrayList<>();
+    LinkedHashMap resource1 = new LinkedHashMap();
+    resource1.put("id", "f5f487df-8c02-4485-81d4-695c50e24b22");
+    resources.add(resource1);
+    LinkedHashMap resource2 = new LinkedHashMap();
+    resource2.put("id", "65c34b35-e8ab-426a-b048-d707467f68b2");
+    resources.add(resource2);
+
+    response.put("resourceSpecification", resources);
+
+    LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
+    serviceSpecCharacteristicValue.put("valueType", "object");
+    serviceSpecCharacteristicValue.put("@schemaLocation",
+        "/serviceSpecification/66a66cc3-178c-45fd-82c2-494336cb3665/specificationInputSchema");
+    serviceSpecCharacteristicValue.put("@type", "MSCM-EVPL-Service_ServiceCharacteristic");
+
+    LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
+    serviceSpecCharacteristic.put("name", "MSCM-EVPL-Service_ServiceCharacteristics");
+    serviceSpecCharacteristic.put("description",
+        "This object describes all the inputs needed from the client to interact with the MSCM-EVPL-Service Service Topology");
+    // using object to match examples in specifications
+    serviceSpecCharacteristic.put("valueType", "object");
+    serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
+    serviceSpecCharacteristic.put("@schemaLocation", "null");
+    serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue);
+    try {
+      toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
+    } catch (SdcToscaParserException ex) {
+      throw new TechnicalException("unable to build response " + ex.getMessage());
+    }
+    assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
+  }
 }
diff --git a/src/test/resources/toscafile/service-MscmEvplService-csar.csar b/src/test/resources/toscafile/service-MscmEvplService-csar.csar
new file mode 100644 (file)
index 0000000..b124160
Binary files /dev/null and b/src/test/resources/toscafile/service-MscmEvplService-csar.csar differ