From db7e56a11d52e3f89039add0b209eedb9552ac5a Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 2 Nov 2021 10:01:16 +0000 Subject: [PATCH] IT Test Import tosca types for a model Issue-ID: SDC-3735 Signed-off-by: davsad Change-Id: I45d438af0439ad553869e26feb4175795e417d4c Signed-off-by: Vasyl Razinkov --- .../org/onap/sdc/backend/ci/tests/utils/Utils.java | 571 ++++++++------------- .../ci/tests/datatypes/ToscaTypeUploadEnum.java | 49 ++ .../execute/sanity/ModelToscaTypeImportTest.java | 213 ++++++++ .../tosca/capability-types/capabilityTypes.yml | 2 + .../Files/imports/tosca/data-types/dataTypes.yml | 14 + .../imports/tosca/group-types/groupTypes.json | 6 + .../Files/imports/tosca/group-types/groupTypes.yml | 9 + .../Files/imports/tosca/group-types/groupTypes.zip | Bin 0 -> 424 bytes .../interfaceLifecycleTypes.yml | 18 + .../interfaceLifecycleTypes.zip | Bin 0 -> 419 bytes .../imports/tosca/node-types/Network/network.json | 22 + .../imports/tosca/node-types/Network/network.yml | 45 ++ .../imports/tosca/policy-types/policyTypes.json | 6 + .../imports/tosca/policy-types/policyTypes.yml | 3 + .../tosca/relationship-types/relationshipTypes.yml | 9 + .../ci/testSuites/frontend/onapUiSanity.xml | 1 + 16 files changed, 613 insertions(+), 355 deletions(-) create mode 100644 integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ToscaTypeUploadEnum.java create mode 100644 integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ModelToscaTypeImportTest.java create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/capability-types/capabilityTypes.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/data-types/dataTypes.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.json create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.zip create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/node-types/Network/network.json create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/node-types/Network/network.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/policy-types/policyTypes.json create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/policy-types/policyTypes.yml create mode 100644 integration-tests/src/test/resources/Files/imports/tosca/relationship-types/relationshipTypes.yml diff --git a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/Utils.java b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/Utils.java index 100d7f009a..b09c310227 100644 --- a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/Utils.java +++ b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/Utils.java @@ -7,9 +7,9 @@ * 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. @@ -20,22 +20,13 @@ package org.onap.sdc.backend.ci.tests.utils; -import com.google.gson.Gson; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; + import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails; -import org.onap.sdc.backend.ci.tests.datatypes.enums.ArtifactTypeEnum; -import org.onap.sdc.backend.ci.tests.tosca.model.ToscaMetadataFieldsPresentationEnum; -import org.openecomp.sdc.be.model.Component; -import org.onap.sdc.backend.ci.tests.config.Config; -import org.openecomp.sdc.common.api.ToscaNodeTypeInfo; -import org.openecomp.sdc.common.api.YamlConstants; -import org.yaml.snakeyaml.Yaml; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -48,327 +39,196 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; - -import static org.testng.AssertJUnit.*; +import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.backend.ci.tests.config.Config; +import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails; +import org.onap.sdc.backend.ci.tests.datatypes.enums.ArtifactTypeEnum; +import org.onap.sdc.backend.ci.tests.tosca.model.ToscaMetadataFieldsPresentationEnum; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.common.api.ToscaNodeTypeInfo; +import org.openecomp.sdc.common.api.YamlConstants; +import org.yaml.snakeyaml.Yaml; public final class Utils { - Gson gson = new Gson(); - - static Logger logger = LogManager.getLogger(Utils.class); - - String contentTypeHeaderData = "application/json"; - String acceptHeaderDate = "application/json"; - - public Utils() { - /* - * super(); - * - * StartTest.enableLogger(); logger = - * Logger.getLogger(Utils.class.getName()); - */ - - } - - // public String serviceTopologyPattern = "/topology/topology/%s"; - // public String serviceTopologyTemplatePattern = - // "/topologytemplate/topologytemplate/%s"; - // - // public String serviceTopologySearchPattern = - // "topology/topology/_search?q=%s"; - // public String serviceTopologyTemplateSearchPattern = - // "topologytemplate/topologytemplate/_search?q=%s"; - // - // public ArtifactTypeEnum getFileTypeByExtension(String fileName) { - // - // String fileExtension = null; - // if (fileName.matches("(.*)\\.(.*)")) { - // System.out.println(fileName.substring(fileName.lastIndexOf(".") + 1)); - // fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1); - // } - // - // switch (fileExtension) { - // case "sh": - // return ArtifactTypeEnum.SHELL_SCRIPT; - // case "png": - // return ArtifactTypeEnum.ICON; - // case "ppp": - // return ArtifactTypeEnum.PUPPET; - // case "yang": - // return ArtifactTypeEnum.YANG; - // default: - // return ArtifactTypeEnum.UNKNOWN; - // } - // - // } - // - // public ArrayList getScriptList (List - // artifactsList){ - // - // ArrayList scriptNameArray = new ArrayList<>(); - // if (artifactsList != null){ - // for (UploadArtifactInfo fileInArtifactsList : artifactsList){ - // String artifactFileName = fileInArtifactsList.getArtifactName(); - // ArtifactTypeEnum artifactFileType = - // fileInArtifactsList.getArtifactType(); - // if (! artifactFileType.equals(ArtifactTypeEnum.ICON)){ - // scriptNameArray.add(artifactFileName); - // } - // continue; - // } - // return scriptNameArray; - // } - // return null; - // } - // - // - // public String getYamlFileLocation(File testResourcesPath) { - // File[] files = testResourcesPath.listFiles(); - // if (files.length == 0){ - // return null; - // }else{ - // for (int i = 0; i < files.length; i++){ - // if (files[i].isFile()){ - // return files[i].getAbsoluteFile().toString(); - // } - // } - // } - // return null; - // } - // - // public String readFileContentToString (String fileName) throws - // IOException { - // - // Path path = Paths.get(fileName); - // String stringFromFile = new String(Files.readAllBytes(path)); - // return stringFromFile; - // - // - // } - // - @SuppressWarnings("unchecked") - public ToscaNodeTypeInfo parseToscaNodeYaml(String fileContent) { - - ToscaNodeTypeInfo result = new ToscaNodeTypeInfo(); - Object templateVersion = null; - Object templateName = null; - - if (fileContent != null) { - Yaml yaml = new Yaml(); - - Map yamlObject = (Map) yaml.load(fileContent); - - templateVersion = yamlObject.get(YamlConstants.TEMPLATE_VERSION); - if (templateVersion != null) { - result.setTemplateVersion(templateVersion.toString()); - } - templateName = yamlObject.get(YamlConstants.TEMPLATE_NAME); - if (templateName != null) { - result.setTemplateName(templateName.toString()); - } - Object nodeTypes = yamlObject.get(YamlConstants.NODE_TYPES); - - if (nodeTypes != null) { - Map nodeTypesMap = (Map) nodeTypes; - for (Entry entry : nodeTypesMap.entrySet()) { - - String nodeName = entry.getKey(); - if (nodeName != null) { - result.setNodeName(nodeName); - } - - break; - - } - } - - } - - return result; - } - - // - // - // public ArtifactsMetadata getArtifactsMetadata(String response){ - // ArtifactsMetadata artifactsMetadata = new ArtifactsMetadata(); - // - // artifactsMetadata.setId(getJsonObjectValueByKey(response, "id")); - // artifactsMetadata.setName(getJsonObjectValueByKey(response, "name")); - // artifactsMetadata.setType(getJsonObjectValueByKey(response, "type")); - // - // artifactsMetadata.setCreator(getJsonObjectValueByKey(response, - // "creator")); - // artifactsMetadata.setCreationTime(getJsonObjectValueByKey(response, - // "creationTime")); - // artifactsMetadata.setLastUpdateTime(getJsonObjectValueByKey(response, - // "lastUpdateTime")); - // artifactsMetadata.setChecksum(getJsonObjectValueByKey(response, - // "checksum")); - // artifactsMetadata.setDescription(getJsonObjectValueByKey(response, - // "description")); - // artifactsMetadata.setLastUpdater(getJsonObjectValueByKey(response, - // "lastUpdater")); - // - // return artifactsMetadata; - // } - // - public static String getJsonObjectValueByKey(String metadata, String key) { - JsonElement jelement = new JsonParser().parse(metadata); - - JsonObject jobject = jelement.getAsJsonObject(); - Object obj = jobject.get(key); - if (obj == null) { - return null; - } else { - String value; - value = (String) jobject.get(key).getAsString(); - return value; - } - } - - public static Config getConfig() throws FileNotFoundException { - Config config = Config.instance(); - return config; - } - - public static Config getConfigHandleException() { - Config config = null; - try{ - config = Config.instance(); - }catch (Exception e){ - System.out.println("Configuration file not found. " + e); - } - return config; - } - - public static void compareArrayLists(List actualArraylList, List expectedArrayList, - String message) { - - ArrayList actual = new ArrayList(actualArraylList); - ArrayList expected = new ArrayList(expectedArrayList); - // assertEquals(message + " count got by rest API not match to " + - // message + " expected count", expected.size(),actual.size()); - expected.removeAll(actual); - assertEquals(message + " content got by rest API not match to " + message + " actual content", 0, - expected.size()); - } - - public static Object parseYamlConfig(String pattern) throws FileNotFoundException { - - Yaml yaml = new Yaml(); - Config config = getConfig(); - String configurationFile = config.getConfigurationFile(); - File file = new File(configurationFile); - // File file = new - // File("../catalog-be/src/main/resources/config/configuration.yaml"); - InputStream inputStream = new FileInputStream(file); - Map map = (Map) yaml.load(inputStream); - Object patternMap = (Object) map.get(pattern); - - return patternMap; - } - - public static String getDepArtLabelFromConfig(ArtifactTypeEnum artifactTypeEnum) throws FileNotFoundException { - - @SuppressWarnings("unchecked") - Map mapOfDepResArtTypesObjects = (Map) parseYamlConfig( - "deploymentResourceArtifacts"); - for (Map.Entry iter : mapOfDepResArtTypesObjects.entrySet()) { - if (iter.getValue().toString().contains(artifactTypeEnum.getType())) { - return iter.getKey().toLowerCase(); - } - } - - return "defaultLabelName"; - } - - - public static String multipleChar(String ch, int repeat) { - return StringUtils.repeat(ch, repeat); - } - - public static List getListOfDepResArtLabels(Boolean isLowerCase) throws FileNotFoundException { - - List listOfResDepArtTypesFromConfig = new ArrayList(); - @SuppressWarnings("unchecked") - Map resourceDeploymentArtifacts = (Map) parseYamlConfig( - "deploymentResourceArtifacts"); - if (resourceDeploymentArtifacts != null) { - - if (isLowerCase) { - for (Map.Entry iter : resourceDeploymentArtifacts.entrySet()) { - listOfResDepArtTypesFromConfig.add(iter.getKey().toLowerCase()); - } - } else { - - for (Map.Entry iter : resourceDeploymentArtifacts.entrySet()) { - listOfResDepArtTypesFromConfig.add(iter.getKey()); - } - } - } - return listOfResDepArtTypesFromConfig; - } - - public static List getListOfToscaArtLabels(Boolean isLowerCase) throws FileNotFoundException { - - List listOfToscaArtTypesFromConfig = new ArrayList(); - @SuppressWarnings("unchecked") - Map toscaArtifacts = (Map) parseYamlConfig("toscaArtifacts"); - if (toscaArtifacts != null) { - - if (isLowerCase) { - for (Map.Entry iter : toscaArtifacts.entrySet()) { - listOfToscaArtTypesFromConfig.add(iter.getKey().toLowerCase()); - } - } else { - for (Map.Entry iter : toscaArtifacts.entrySet()) { - listOfToscaArtTypesFromConfig.add(iter.getKey()); - } - } - } - return listOfToscaArtTypesFromConfig; - } - - public static List getListOfResPlaceHoldersDepArtTypes() throws FileNotFoundException { - List listResDepArtTypesFromConfig = new ArrayList(); - List listOfResDepArtLabelsFromConfig = getListOfDepResArtLabels(false); - assertNotNull("deployment artifact types list is null", listOfResDepArtLabelsFromConfig); - Object parseYamlConfig = Utils.parseYamlConfig("deploymentResourceArtifacts"); - Map mapOfDepResArtTypesObjects = (Map) Utils - .parseYamlConfig("deploymentResourceArtifacts"); - - // assertNotNull("deployment artifact types list is null", - // mapOfDepResArtTypesObjects); - if (listOfResDepArtLabelsFromConfig != null) { - for (String resDepArtType : listOfResDepArtLabelsFromConfig) { - Object object = mapOfDepResArtTypesObjects.get(resDepArtType); - if (object instanceof Map) { - Map map = (Map) object; - listResDepArtTypesFromConfig.add((String) map.get("type")); - } else { - assertTrue("return object does not instance of map", false); - } - } - } - return listResDepArtTypesFromConfig; - } - - public static Long getEpochTimeFromUTC(String time) throws ParseException { - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz"); - java.util.Date date = df.parse(time); - long epoch = date.getTime(); - return epoch; - } - - public static Long getActionDuration(Runnable func) throws Exception{ - long startTime = System.nanoTime(); - func.run(); - long estimateTime = System.nanoTime(); - Long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime); - return duration; - } - - public static Long getAndValidateActionDuration (Runnable action, int regularTestRunTime){ + @SuppressWarnings("unchecked") + public ToscaNodeTypeInfo parseToscaNodeYaml(String fileContent) { + + ToscaNodeTypeInfo result = new ToscaNodeTypeInfo(); + + if (fileContent != null) { + Yaml yaml = new Yaml(); + Map yamlObject = (Map) yaml.load(fileContent); + + final Object templateVersion = yamlObject.get(YamlConstants.TEMPLATE_VERSION); + if (templateVersion != null) { + result.setTemplateVersion(templateVersion.toString()); + } + + final Object templateName = yamlObject.get(YamlConstants.TEMPLATE_NAME); + if (templateName != null) { + result.setTemplateName(templateName.toString()); + } + + Object nodeTypes = yamlObject.get(YamlConstants.NODE_TYPES); + if (nodeTypes != null) { + Map nodeTypesMap = (Map) nodeTypes; + for (Entry entry : nodeTypesMap.entrySet()) { + + String nodeName = entry.getKey(); + if (nodeName != null) { + result.setNodeName(nodeName); + } + break; + } + } + } + + return result; + } + + public static String getJsonObjectValueByKey(String metadata, String key) { + JsonElement jelement = new JsonParser().parse(metadata); + + JsonObject jobject = jelement.getAsJsonObject(); + Object obj = jobject.get(key); + if (obj == null) { + return null; + } else { + return (String) jobject.get(key).getAsString(); + } + } + + public static Config getConfig() throws FileNotFoundException { + return Config.instance(); + } + + public static Config getConfigHandleException() { + Config config = null; + try { + config = Config.instance(); + } catch (Exception e) { + System.out.println("Configuration file not found. " + e); + } + return config; + } + + public static void compareArrayLists(List actualArraylList, List expectedArrayList, String message) { + + ArrayList actual = new ArrayList(actualArraylList); + ArrayList expected = new ArrayList(expectedArrayList); + expected.removeAll(actual); + assertEquals(message + " content got by rest API not match to " + message + " actual content", 0, expected.size()); + } + + public static Object parseYamlConfig(String pattern) throws FileNotFoundException { + + Yaml yaml = new Yaml(); + Config config = getConfig(); + String configurationFile = config.getConfigurationFile(); + File file = new File(configurationFile); + InputStream inputStream = new FileInputStream(file); + Map map = (Map) yaml.load(inputStream); + return (Object) map.get(pattern); + } + + public static String getDepArtLabelFromConfig(ArtifactTypeEnum artifactTypeEnum) throws FileNotFoundException { + + @SuppressWarnings("unchecked") + Map mapOfDepResArtTypesObjects = (Map) parseYamlConfig( + "deploymentResourceArtifacts"); + for (Map.Entry iter : mapOfDepResArtTypesObjects.entrySet()) { + if (iter.getValue().toString().contains(artifactTypeEnum.getType())) { + return iter.getKey().toLowerCase(); + } + } + + return "defaultLabelName"; + } + + + public static String multipleChar(String ch, int repeat) { + return StringUtils.repeat(ch, repeat); + } + + public static List getListOfDepResArtLabels(Boolean isLowerCase) throws FileNotFoundException { + + List listOfResDepArtTypesFromConfig = new ArrayList(); + @SuppressWarnings("unchecked") + Map resourceDeploymentArtifacts = (Map) parseYamlConfig( + "deploymentResourceArtifacts"); + if (resourceDeploymentArtifacts != null) { + + if (isLowerCase) { + for (Map.Entry iter : resourceDeploymentArtifacts.entrySet()) { + listOfResDepArtTypesFromConfig.add(iter.getKey().toLowerCase()); + } + } else { + + for (Map.Entry iter : resourceDeploymentArtifacts.entrySet()) { + listOfResDepArtTypesFromConfig.add(iter.getKey()); + } + } + } + return listOfResDepArtTypesFromConfig; + } + + public static List getListOfToscaArtLabels(Boolean isLowerCase) throws FileNotFoundException { + + List listOfToscaArtTypesFromConfig = new ArrayList(); + @SuppressWarnings("unchecked") + Map toscaArtifacts = (Map) parseYamlConfig("toscaArtifacts"); + if (toscaArtifacts != null) { + + if (isLowerCase) { + for (Map.Entry iter : toscaArtifacts.entrySet()) { + listOfToscaArtTypesFromConfig.add(iter.getKey().toLowerCase()); + } + } else { + for (Map.Entry iter : toscaArtifacts.entrySet()) { + listOfToscaArtTypesFromConfig.add(iter.getKey()); + } + } + } + return listOfToscaArtTypesFromConfig; + } + + public static List getListOfResPlaceHoldersDepArtTypes() throws FileNotFoundException { + List listResDepArtTypesFromConfig = new ArrayList(); + List listOfResDepArtLabelsFromConfig = getListOfDepResArtLabels(false); + assertNotNull("deployment artifact types list is null", listOfResDepArtLabelsFromConfig); + Object parseYamlConfig = Utils.parseYamlConfig("deploymentResourceArtifacts"); + Map mapOfDepResArtTypesObjects = (Map) Utils + .parseYamlConfig("deploymentResourceArtifacts"); + + if (listOfResDepArtLabelsFromConfig != null) { + for (String resDepArtType : listOfResDepArtLabelsFromConfig) { + Object object = mapOfDepResArtTypesObjects.get(resDepArtType); + if (object instanceof Map) { + Map map = (Map) object; + listResDepArtTypesFromConfig.add((String) map.get("type")); + } else { + assertTrue("return object does not instance of map", false); + } + } + } + return listResDepArtTypesFromConfig; + } + + public static Long getEpochTimeFromUTC(String time) throws ParseException { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz"); + java.util.Date date = df.parse(time); + return date.getTime(); + } + + public static Long getActionDuration(Runnable func) throws Exception { + long startTime = System.nanoTime(); + func.run(); + long estimateTime = System.nanoTime(); + return TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime); + } + + public static Long getAndValidateActionDuration(Runnable action, int regularTestRunTime) { Long actualTestRunTime = null; try { actualTestRunTime = Utils.getActionDuration(() -> { @@ -383,30 +243,31 @@ public final class Utils { } double factor = 1.5; - assertTrue("Expected test run time should be less than " + regularTestRunTime*factor + ", " + - "actual time is " + actualTestRunTime , regularTestRunTime*factor>actualTestRunTime); -// SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is " + actualTestRunTime + " seconds"); + assertTrue("Expected test run time should be less than " + regularTestRunTime * factor + ", " + + "actual time is " + actualTestRunTime, regularTestRunTime * factor > actualTestRunTime); return actualTestRunTime; } - public static Map generateServiceMetadataToExpectedObject(ServiceReqDetails serviceReqDetails, Component component) { - - Map metadata = new HashMap<>(); - - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, serviceReqDetails.getCategories().get(0).getName()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, serviceReqDetails.getDescription()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, "Service"); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INSTANTIATION_TYPE.value, serviceReqDetails.getInstantiationType()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_TYPE.value, serviceReqDetails.getServiceType()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ROLE.value, serviceReqDetails.getServiceRole()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAMING_POLICY.value, serviceReqDetails.getNamingPolicy()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.ECOMP_GENERATED_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString()); - metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ECOMP_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());//equals to ECOMP_GENERATED_NAMING - - return metadata; - } + public static Map generateServiceMetadataToExpectedObject(ServiceReqDetails serviceReqDetails, Component component) { + + Map metadata = new HashMap<>(); + + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, serviceReqDetails.getCategories().get(0).getName()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, serviceReqDetails.getDescription()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, "Service"); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INSTANTIATION_TYPE.value, serviceReqDetails.getInstantiationType()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_TYPE.value, serviceReqDetails.getServiceType()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ROLE.value, serviceReqDetails.getServiceRole()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAMING_POLICY.value, serviceReqDetails.getNamingPolicy()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.ECOMP_GENERATED_NAMING.value, + serviceReqDetails.getEcompGeneratedNaming().toString()); + metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ECOMP_NAMING.value, + serviceReqDetails.getEcompGeneratedNaming().toString());//equals to ECOMP_GENERATED_NAMING + + return metadata; + } } diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ToscaTypeUploadEnum.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ToscaTypeUploadEnum.java new file mode 100644 index 0000000000..9f09cc0856 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ToscaTypeUploadEnum.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.datatypes; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ToscaTypeUploadEnum { + + DATA("datatypes", "dataTypes", "data-types", "dataTypesZip"), + CAPABILITY("capability", "capabilityTypes", "capability-types", "capabilityTypeZip"), + RELATIONSHIP("relationship", "relationshipTypes", "relationship-types", "relationshipTypeZip"), + INTERFACE("interfaceLifecycle", "interfaceLifecycleTypes", "interface-lifecycle-types", "interfaceLifecycleTypeZip"), + GROUP("grouptypes", "groupTypes", "group-types", "groupTypesZip", true), + POLICY("policytypes", "policyTypes", "policy-types", "policyTypesZip", true); + + ToscaTypeUploadEnum(final String urlSuffix, final String modelParam, final String directory, final String zipParam) { + this.urlSuffix = urlSuffix; + this.modelParam = modelParam; + this.directory = directory; + this.zipParam = zipParam; + this.metadata = false; + } + + private String urlSuffix; + private String modelParam; + private String directory; + private String zipParam; + private boolean metadata; +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ModelToscaTypeImportTest.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ModelToscaTypeImportTest.java new file mode 100644 index 0000000000..ed54f7f897 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ModelToscaTypeImportTest.java @@ -0,0 +1,213 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.execute.sanity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Map; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.HttpClients; +import org.onap.sdc.backend.ci.tests.config.Config; +import org.onap.sdc.backend.ci.tests.datatypes.enums.ComponentType; +import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum; +import org.onap.sdc.backend.ci.tests.datatypes.http.HttpHeaderEnum; +import org.onap.sdc.backend.ci.tests.utils.Utils; +import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory; +import org.onap.sdc.frontend.ci.tests.datatypes.ComponentData; +import org.onap.sdc.frontend.ci.tests.datatypes.ModelName; +import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData; +import org.onap.sdc.frontend.ci.tests.datatypes.ToscaTypeUploadEnum; +import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory; +import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest; +import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow; +import org.onap.sdc.frontend.ci.tests.flow.CreateVfFlow; +import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow; +import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException; +import org.onap.sdc.frontend.ci.tests.pages.home.HomePage; +import org.onap.sdc.frontend.ci.tests.utilities.FileHandling; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class ModelToscaTypeImportTest extends SetupCDTest { + + private final static String NODE_TYPE_TO_ADD = "Network"; + private final static String MODEL_VNFD_TYPES = "vnfd_types"; + private final static String MODEL_NSD_TYPES = "nsd_types"; + private final static String TYPE_URL = "http://%s:%s/sdc2/rest/v1/catalog/uploadType/%s"; + private final static String NODE_TYPE_URL = "http://%s:%s/sdc2/rest/v1/catalog/upload/multipart"; + private final static String IMPORT_PATH = System.getProperty("user.dir").concat("/src/test/resources/Files/imports/tosca"); + private final static String NODE_TYPE_DIRECTORY = IMPORT_PATH.concat(File.separator).concat("node-types"); + private static final String TOSCA_CAPABILITIES_NETWORK_LINK = "tosca.capabilities.network.Linkable"; + + private WebDriver webDriver; + + @BeforeMethod + public void init() { + webDriver = DriverFactory.getDriver(); + } + + @Test + public void importTypesForModel() throws Exception { + for (final var type : ToscaTypeUploadEnum.values()) { + assertTrue(postType(type.getUrlSuffix(), type.getModelParam(), type.getDirectory(), type.getZipParam(), type.isMetadata())); + } + } + + @Test(dependsOnMethods = "importTypesForModel") + public void addNodeType() throws Exception { + assertTrue(postNodeType(NODE_TYPE_TO_ADD)); + } + + @Test(dependsOnMethods = "addNodeType") + public void verifyToscaTypesIncludedInCsar() throws Exception { + final var home = new HomePage(webDriver); + + final var vf = new ResourceCreateData(); + vf.setRandomName(ElementFactory.getResourcePrefix() + "-VF"); + vf.setCategory(ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory()); + vf.setTagList(Arrays.asList(vf.getName())); + vf.setDescription("Test"); + vf.setVendorName("EST"); + vf.setVendorRelease("2.5.1"); + vf.setVendorModelNumber("0001"); + vf.setModel(ModelName.ETSI_SOL001_v2_5_1.getName()); + + final var createVfFlow = new CreateVfFlow(webDriver, vf); + createVfFlow.run(home); + final var resourceCreatePage = createVfFlow.getLandedPage() + .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ResourceCreatePage")); + resourceCreatePage.isLoaded(); + + final var parentComponent = new ComponentData(); + parentComponent.setName(vf.getName()); + parentComponent.setVersion("0.1"); + parentComponent.setComponentType(ComponentType.RESOURCE); + final var addComponent = new ComponentData(); + addComponent.setName("Network"); + addComponent.setVersion("1.0"); + addComponent.setComponentType(ComponentType.RESOURCE); + + final var compositionPage = resourceCreatePage.goToComposition(); + compositionPage.isLoaded(); + final var addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, addComponent); + addNodeToCompositionFlow.run(compositionPage); + compositionPage.isLoaded(); + compositionPage.goToServiceGeneral(); + + final var downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver); + downloadCsarArtifactFlow.setWaitBeforeGetTheFile(5L); + downloadCsarArtifactFlow.run(resourceCreatePage); + final var toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage() + .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage")); + assertTrue(toscaArtifactsPage.getDownloadedArtifactList().size() > 0, "No artifact download was found"); + toscaArtifactsPage.getDownloadedArtifactList().get(0); + + final var downloadFolderPath = getConfig().getDownloadAutomationFolder(); + final Map csarFiles = FileHandling.getFilesFromZip(downloadFolderPath, toscaArtifactsPage.getDownloadedArtifactList().get(0)); + assertEquals(7, csarFiles.size()); + assertTrue(csarFiles.keySet().stream().filter(filename -> filename.contains(NODE_TYPE_TO_ADD.concat("-template.yml"))).findAny().isPresent()); + assertTrue(csarFiles.keySet().stream().filter(filename -> filename.contains(MODEL_VNFD_TYPES.concat(".yaml"))).findAny().isPresent()); + assertTrue(csarFiles.keySet().stream().filter(filename -> filename.contains(MODEL_NSD_TYPES.concat(".yaml"))).findAny().isPresent()); + assertTrue(csarFiles.keySet().stream().filter(filename -> filename.contains("-template-interface".concat(".yml"))).findAny().isPresent()); + assertTrue(csarFiles.values().stream().filter(bytes -> new String(bytes).contains(TOSCA_CAPABILITIES_NETWORK_LINK)).findAny().isPresent()); + } + + private boolean postNodeType(final String directory) throws Exception { + final var yamlDirectory = new File(NODE_TYPE_DIRECTORY.concat(File.separator).concat(directory)); + final var builder = MultipartEntityBuilder.create(); + builder.addTextBody("resourceMetadata", getJsonString(yamlDirectory)); + final var zipFile = getImportZipFile(yamlDirectory); + builder.addBinaryBody("resourceZip", zipFile, ContentType.APPLICATION_OCTET_STREAM, zipFile.getName()); + try { + final Config config = Utils.getConfig(); + postEntity(String.format(NODE_TYPE_URL, config.getCatalogBeHost(), config.getCatalogBePort()), "jh0003", builder.build()); + } finally { + zipFile.delete(); + } + return true; + } + + private boolean postType(final String urlSuffix, final String modelParam, final String directory, final String zipParam, + final boolean metadata) throws Exception { + final var yamlDirectory = new File(IMPORT_PATH.concat(File.separator).concat(directory)); + final var builder = MultipartEntityBuilder.create(); + if (metadata) { + builder.addTextBody("toscaTypeMetadata", getJsonString(yamlDirectory)); + } + builder.addTextBody("model", ModelName.ETSI_SOL001_v2_5_1.getName()); + final var zipFile = getImportZipFile(yamlDirectory); + builder.addBinaryBody(zipParam, zipFile, ContentType.APPLICATION_OCTET_STREAM, zipFile.getName()); + + try { + final Config config = Utils.getConfig(); + postEntity(String.format(TYPE_URL, config.getCatalogBeHost(), config.getCatalogBePort(), urlSuffix), "cs0008", builder.build()); + } finally { + zipFile.delete(); + } + return true; + } + + private void postEntity(final String url, final String user, final HttpEntity entity) throws Exception { + final var httpPost = new HttpPost(String.format(url)); + httpPost.setHeader(HttpHeaderEnum.USER_ID.getValue(), user); + httpPost.setEntity(entity); + + try (final var client = HttpClients.createDefault()) { + final var response = client.execute(httpPost); + assertEquals(201, response.getStatusLine().getStatusCode()); + } + } + + private File getImportZipFile(final File yamlDirectory) throws Exception { + final var fileToZip = yamlDirectory.listFiles((dir, filename) -> filename.toLowerCase().endsWith(".yml"))[0]; + final var zipName = + yamlDirectory.getAbsolutePath().concat(File.separator).concat(fileToZip.getName()).concat(UUID.randomUUID().toString()).concat(".zip"); + try (final var zipOut = new ZipOutputStream(new FileOutputStream(zipName)); + final var fis = new FileInputStream(fileToZip)) { + final var zipEntry = new ZipEntry(fileToZip.getName()); + zipOut.putNextEntry(zipEntry); + final var bytes = new byte[1024]; + int length; + while ((length = fis.read(bytes)) >= 0) { + zipOut.write(bytes, 0, length); + } + } + return new File(zipName); + } + + private String getJsonString(final File yamlDirectory) throws Exception { + return new String( + Files.readAllBytes(Paths.get(yamlDirectory.listFiles((dir, filename) -> filename.toLowerCase().endsWith(".json"))[0].getAbsolutePath()))); + } +} diff --git a/integration-tests/src/test/resources/Files/imports/tosca/capability-types/capabilityTypes.yml b/integration-tests/src/test/resources/Files/imports/tosca/capability-types/capabilityTypes.yml new file mode 100644 index 0000000000..e4f19ef21f --- /dev/null +++ b/integration-tests/src/test/resources/Files/imports/tosca/capability-types/capabilityTypes.yml @@ -0,0 +1,2 @@ +tosca.capabilities.network.Linkable: + derived_from: tosca.capabilities.Root \ No newline at end of file diff --git a/integration-tests/src/test/resources/Files/imports/tosca/data-types/dataTypes.yml b/integration-tests/src/test/resources/Files/imports/tosca/data-types/dataTypes.yml new file mode 100644 index 0000000000..657c2d874c --- /dev/null +++ b/integration-tests/src/test/resources/Files/imports/tosca/data-types/dataTypes.yml @@ -0,0 +1,14 @@ +tosca.datatypes.nfv.AdditionalServiceData: + derived_from: tosca.datatypes.Root + description: describes the additional service data of the VirtualCp used to expose properties of the VirtualCp to NFV-MANO. + properties: + portData: + type: list + description: Service port numbers exposed by the VirtualCp. + required: false + entry_schema: + type: tosca.datatypes.nfv.ServicePortData + serviceData: + type: string + description: Service matching information exposed by the VirtualCp. + required: false \ No newline at end of file diff --git a/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.json b/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.json new file mode 100644 index 0000000000..af5c5858a3 --- /dev/null +++ b/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.json @@ -0,0 +1,6 @@ +{ + "tosca.groups.nfv.NsPlacementGroup": { + "displayName": "NFV NS PlacementGroup", + "icon": "group-nfv-placementgroup" + } +} \ No newline at end of file diff --git a/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.yml b/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.yml new file mode 100644 index 0000000000..fe1f21befa --- /dev/null +++ b/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.yml @@ -0,0 +1,9 @@ +tosca.groups.nfv.NsPlacementGroup: + derived_from: tosca.groups.Root + description: NsPlacementGroup is used for describing the affinity or anti-affinity relationship applicable between VNF instances created using different VNFDs, the Virtual Link instances created using different VLDs or the nested NS instances created using different NSDs when used in a NSD. + properties: + description: + type: string + description: Human readable description of the group + required: true + members: [tosca.nodes.nfv.VNF, tosca.nodes.nfv.NsVirtualLink, tosca.nodes.nfv.NS] \ No newline at end of file diff --git a/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.zip b/integration-tests/src/test/resources/Files/imports/tosca/group-types/groupTypes.zip new file mode 100644 index 0000000000000000000000000000000000000000..80909d2a142dc8d2e448008b8a9c2bda2426b0fa GIT binary patch literal 424 zcmWIWW@Zs#;Nak3_+xAy%zy;=fb8_5{L+Gu%7WBly~^C2-ieNWhaGrazt1_uu3_nL zO?1NwC6}dn0#1{UT#izicktVmS8r!ZDqRWF+4c9^|84ViUp$z#w?$-YVttNP?c6&J z#+z)#x7IR91it8aynMRB_JrxvwhOE&d!ZoG%e1{fnsLbl5%&*{)6UJS;4gD1xFH=1TWx!}4h>G!0x<1>4uwR^gySmMjq_D8O1y5Gri{Evy}jH8mzNqk>x<)iV9Fe VIl!Bh4J6M9gf>7r3}_|;0{}Mcpi%$; literal 0 HcmV?d00001 diff --git a/integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml b/integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml new file mode 100644 index 0000000000..9353c6a7bd --- /dev/null +++ b/integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml @@ -0,0 +1,18 @@ +tosca.interfaces.relationship.Configure: + derived_from: tosca.interfaces.Root + pre_configure_source: + description: Operation to pre-configure the source endpoint. + pre_configure_target: + description: Operation to pre-configure the target endpoint. + post_configure_source: + description: Operation to post-configure the source endpoint. + post_configure_target: + description: Operation to post-configure the target endpoint. + add_target: + description: Operation to notify the source node of a target node being added via a relationship. + add_source: + description: Operation to notify the target node of a source node which is now available via a relationship. + target_changed: + description: Operation to notify source some property or attribute of the target changed + remove_target: + description: Operation to remove a target node. \ No newline at end of file diff --git a/integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip b/integration-tests/src/test/resources/Files/imports/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip new file mode 100644 index 0000000000000000000000000000000000000000..e0cef1709a339a32100baf38e0afbd85a3fd45f8 GIT binary patch literal 419 zcmWIWW@Zs#;Nak3_+xAy%zy->f$Yq@lGLKK#NtOp%3q+eoQip2C#AJ!H@1*5|9hXlvn(tY2-qtH=l1!LP?-pnG zl|fP$B9gdlLgj_5-=#18#d~1#C#QWcLyk$kDgWSomMv9=GjVaNxN5Xl+c)Pp3&9b^WBPh2ik5;-phBdIDCUjb*yDO*PQh)oL;7Xk-zq$ zR#CsJu-snT?IX)2M!N&I-MnRfPxY1)J62QmliNN0=GQq^=S8ERM?Mm}!TMlIxcLFr z$^&H!>R*)yJ!U#KuV&$)i_=n;{E=1hzai_wcy`L|n`SE~KX*J|urzSmCHLFy>&>HT znFGApIcyR(rvC + -- 2.16.6