Merge "Handle annotated-input which has 2 properties"
authorOfir Sonsino <ofir.sonsino@intl.att.com>
Mon, 3 Dec 2018 07:10:14 +0000 (07:10 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 3 Dec 2018 07:10:14 +0000 (07:10 +0000)
vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java
vid-app-common/src/main/resources/1712_ADIOD.zip [new file with mode: 0644]
vid-app-common/src/main/resources/sdcservices.json
vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
vid-app-common/src/test/resources/empty.json [new file with mode: 0644]
vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java

index 17fb29b..57d80ce 100644 (file)
@@ -1,7 +1,6 @@
 package org.onap.vid.asdc.parser;
 
-import org.onap.vid.asdc.beans.Service;
-import org.onap.vid.model.*;
+import org.apache.commons.lang3.StringUtils;
 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
 import org.onap.sdc.tosca.parser.impl.FilterType;
@@ -11,6 +10,8 @@ import org.onap.sdc.toscaparser.api.Group;
 import org.onap.sdc.toscaparser.api.*;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
 import org.onap.sdc.toscaparser.api.parameters.Input;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.model.*;
 
 import java.nio.file.Path;
 import java.util.*;
@@ -417,7 +418,22 @@ public class ToscaParserImpl2 {
     private boolean isInputMatchesToGroup(List<Property> annotationProperties, org.onap.vid.model.Group group){
         for(Property property: annotationProperties){
             if(property.getName().equals(VF_MODULE_LABEL)){
-                return getPropertyValueAsString(property).equals(group.getProperties().getVfModuleLabel());
+                final Object values = property.getValue();
+                final String vfModuleLabel = group.getProperties().getVfModuleLabel();
+                if (values instanceof List) {
+                    if (listContainsAsString((List) values, vfModuleLabel)) return true;
+                } else {
+                    return getPropertyValueAsString(property).equals(vfModuleLabel);
+                }
+            }
+        }
+        return false;
+    }
+
+    private boolean listContainsAsString(List list, String value) {
+        for (Object v : list) {
+            if (StringUtils.equals(v.toString(), value)) {
+                return true;
             }
         }
         return false;
@@ -428,7 +444,7 @@ public class ToscaParserImpl2 {
     }
 
     private String removeSquareBrackets(String stringWithSquareBrackets){
-        return stringWithSquareBrackets.substring(1, stringWithSquareBrackets.length()-1);
+        return stringWithSquareBrackets.replaceAll("(^\\[|\\]$)", "");
     }
 
     private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){
@@ -507,7 +523,10 @@ public class ToscaParserImpl2 {
         for (Property property : properties) {
             //special handling to necessary sub-property "ecomp_generated_naming"
             if(property.getName().equals("nf_naming")){
-                propertiesMap.put(removeSquareBrackets(((LinkedHashMap)(property.getValue())).keySet().toString()) ,((LinkedHashMap)(property.getValue())).get("ecomp_generated_naming").toString());
+                final Object ecompGeneratedNaming = ((Map) (property.getValue())).get("ecomp_generated_naming");
+                if (ecompGeneratedNaming != null) {
+                    propertiesMap.put("ecomp_generated_naming", ecompGeneratedNaming.toString());
+                }
             }
             propertiesMap.put(property.getName(), property.getValue().toString());
         }
diff --git a/vid-app-common/src/main/resources/1712_ADIOD.zip b/vid-app-common/src/main/resources/1712_ADIOD.zip
new file mode 100644 (file)
index 0000000..281ee8a
Binary files /dev/null and b/vid-app-common/src/main/resources/1712_ADIOD.zip differ
index 1d9d160..e300597 100644 (file)
       "artifacts": null,
       "resources": null
     },
+    {
+      "uuid": "90fe6842-aa76-4b68-8329-5c86ff564407",
+      "invariantUUID": "0311f998-9268-4fd6-bbba-afff15087b72",
+      "name": "4-27_vMME_Service",
+      "version": "1.0",
+      "toscaModelURL": "./1712_ADIOD.zip",
+      "category": "Mobility",
+      "lifecycleState": "CERTIFIED",
+      "lastUpdaterUserId": "rg276b",
+      "lastUpdaterFullName": null,
+      "distributionStatus": "DISTRIBUTED",
+      "artifacts": null,
+      "resources": null
+    },
     {
       "uuid": "73e1322a-8a9a-49dc-9558-b0c5c5770e4a",
       "invariantUUID": "f430728a-4530-42be-a577-1206b9484cef",
index 1282a6f..e1c5e92 100644 (file)
@@ -15,8 +15,8 @@ import org.onap.sdc.toscaparser.api.NodeTemplate;
 import org.onap.vid.asdc.AsdcCatalogException;
 import org.onap.vid.asdc.AsdcClient;
 import org.onap.vid.asdc.local.LocalAsdcClient;
-import org.onap.vid.model.*;
 import org.onap.vid.controllers.ToscaParserMockHelper;
+import org.onap.vid.model.*;
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -196,6 +196,28 @@ public class ToscaParserImpl2Test {
         JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations);
     }
 
+    @Test
+    public void modelWithAnnotatedInputWithTwoProperties_vfModuleGetsTheInput() throws Exception {
+        final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
+        final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
+
+        assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { 201712488_adiodvpe10_availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel));
+    }
+
+    @Test
+    public void modelWithNfNamingWithToValues_ecompGeneratedNamingIsExtracted() throws Exception {
+        final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
+        final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
+
+        assertJsonStringEqualsIgnoreNulls("" +
+                "{ vnfs: " +
+                "  { \"201712-488_ADIOD-vPE-1 0\": " +
+                "    { properties: { " +
+                "      ecomp_generated_naming: \"true\", " +
+                "      nf_naming: \"{naming_policy=SDNC_Policy.Config_MS_1806SRIOV_VPE_ADIoDJson, ecomp_generated_naming=true}\" " +
+                "} } } }", om.writeValueAsString(serviceModel));
+    }
+
     private void setPprobeServiceProxy(Map<String, PortMirroringConfig> expectedConfigurations){
         //Port Mirroring Configuration By Policy 0 doesn't contains pProbe.
         // But due to sdc design if pProbe not exists parser expects to get it from other source.
diff --git a/vid-app-common/src/test/resources/empty.json b/vid-app-common/src/test/resources/empty.json
new file mode 100644 (file)
index 0000000..9e26dfe
--- /dev/null
@@ -0,0 +1 @@
+{}
\ No newline at end of file
index f4d3796..1738970 100644 (file)
@@ -115,7 +115,7 @@ public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest {
                 new ArrayList<>(),
                 false, true, true, true,
                 "2017-488_ADIOD-vPE 0",
-                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1,  new ArrayList<>());
+                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1,  ImmutableList.of("Bandwidth", "Bandwidth units"));
 
         String serviceInstanceName = deployServiceInstance(serviceData, false);
         vidBasePage.screenshotDeployDialog(serviceInstanceName);