diff options
author | aosull01 <adrian.osullivan@huawei.com> | 2019-11-13 15:17:49 +0000 |
---|---|---|
committer | Matthieu Geerebaert <matthieu.geerebaert@orange.com> | 2019-11-13 15:39:50 +0000 |
commit | 063ebf596dc67b870220d2664edc576f43e7f6e5 (patch) | |
tree | 98bcfd45267e2733ca2ddde2a637a52d0358aed2 /src | |
parent | 5d4e5d3e5ee349e3f74c96dbdb287b09a77e9ee0 (diff) |
Fix issue with null Pointer for Inputs of type list/map
Issue-ID: EXTAPI-354
Signed-off-by: aosull01 <adrian.osullivan@huawei.com>
Change-Id: I5650233598618982c023fa5b786b049981efbaca
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java | 9 | ||||
-rw-r--r-- | src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java | 48 | ||||
-rw-r--r-- | src/test/resources/toscafile/service-MscmEvplService-csar.csar | bin | 0 -> 77013 bytes |
3 files changed, 55 insertions, 2 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java index 649ae22..97bcd9c 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java @@ -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) { diff --git a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java b/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java index 0043a8a..9742d88 100644 --- a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java +++ b/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java @@ -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 Binary files differnew file mode 100644 index 0000000..b124160 --- /dev/null +++ b/src/test/resources/toscafile/service-MscmEvplService-csar.csar |