diff options
Diffstat (limited to 'ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/VfModuleVerificator.java')
-rw-r--r-- | ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/VfModuleVerificator.java | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/VfModuleVerificator.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/VfModuleVerificator.java new file mode 100644 index 0000000000..7f01b86eaf --- /dev/null +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/VfModuleVerificator.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.verificator; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; + +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.GroupInstance; +import org.openecomp.sdc.be.model.GroupProperty; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.ci.tests.datatypes.TypeHeatMetaDefinition; +import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest; +import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition; +import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaGroupsMetadataDefinition; +import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaGroupsTopologyTemplateDefinition; +import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils; + +import com.aventstack.extentreports.Status; + +public class VfModuleVerificator { + + private static final String [] PROPERTY_TYPES = {"vf_module_label", "min_vf_module_instances", "max_vf_module_instances", "initial_count"}; + private static final String VF_MODULE_TYPE = "org.openecomp.groups.VfModule"; + + /** + * compare number of groups from HEAT.meta file vs TOSCA yaml groups generated by ASDC + * @param listTypeHeatMetaDefinition - java object created from HEAT.meta file + * @param toscaDefinition - java object created from TOSCA yaml + */ + public static void compareNumberOfVfModules(List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition, ToscaDefinition toscaDefinition) { + + int heatMetaGroupCount = 0; + int toscaDefinitionGroupCount = 0; + for (TypeHeatMetaDefinition typeHeatMetaDefinition : listTypeHeatMetaDefinition) { + heatMetaGroupCount = typeHeatMetaDefinition.getGroupHeatMetaDefinition().size(); + } + toscaDefinitionGroupCount = toscaDefinition.getTopology_template().getGroups().size(); + assertEquals("Expected num of groups in HEAT.meta file is " + heatMetaGroupCount + ", but was in TOSCA yaml file " + toscaDefinitionGroupCount, heatMetaGroupCount, toscaDefinitionGroupCount); + } + + /** + * check group structure and "metadata" parameters vs data on the service object + * @param toscaDefinition + */ + public static void verifyGroupMetadata(ToscaDefinition toscaDefinition, Service service) { + + Map<String, ToscaGroupsTopologyTemplateDefinition> groups = toscaDefinition.getTopology_template().getGroups(); + for (Map.Entry<String, ToscaGroupsTopologyTemplateDefinition> groupTopologyTemplateDefinition : groups.entrySet()) { + String key = groupTopologyTemplateDefinition.getKey(); + GroupInstance groupInstanceObject = getGroupInstanceByKey(key, service); + ToscaGroupsMetadataDefinition metadata = groupTopologyTemplateDefinition.getValue().getMetadata(); + assertNotNull("groupInstanceObject is null", groupInstanceObject); + assertTrue("expected vfModuleModelName " + groupInstanceObject.getGroupName() + ", actual " + metadata.getVfModuleModelName(), groupInstanceObject.getGroupName().equals(metadata.getVfModuleModelName())); + assertTrue("expected vfModuleModelInvariantUUID " + groupInstanceObject.getInvariantUUID() + ", actual " + metadata.getVfModuleModelInvariantUUID(), groupInstanceObject.getInvariantUUID().equals(metadata.getVfModuleModelInvariantUUID())); + assertTrue("expected vfModuleModelCustomizationUUID " + groupInstanceObject.getCustomizationUUID() + ", actual " + metadata.getVfModuleModelCustomizationUUID(), groupInstanceObject.getCustomizationUUID().equals(metadata.getVfModuleModelCustomizationUUID())); + assertTrue("expected vfModuleModelUUID " + groupInstanceObject.getGroupUUID() + ", actual " + metadata.getVfModuleModelUUID(), groupInstanceObject.getGroupUUID().equals(metadata.getVfModuleModelUUID())); + assertTrue("expected vfModuleModelVersion " + groupInstanceObject.getVersion() + ", actual " + metadata.getVfModuleModelVersion(), groupInstanceObject.getVersion().equals(metadata.getVfModuleModelVersion())); + } + } + + + /** + * @param key + * @param service + * @return + */ + public static GroupInstance getGroupInstanceByKey(String key, Service service) { + for(ComponentInstance componentInstance : service.getComponentInstances()){ + for(GroupInstance groupInstance : componentInstance.getGroupInstances()){ + if( key.equals(groupInstance.getName())){ + return groupInstance; + } + } + } + return null; + } + + public static void validateSpecificModulePropertiesFromRequest(Resource resource) { + List<List<PropertyDataDefinition>> allProperties = resource.getGroups().stream(). + filter(e -> e.getType().equals(VF_MODULE_TYPE)). + map(e -> e.getProperties()). + collect(Collectors.toList()); + for(String propertyType :PROPERTY_TYPES){ + int numberOfTypes = getPropertyType(allProperties, propertyType).size(); + SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF property %s exist, Expected: %s, Actual: %s ", propertyType, allProperties.size(), numberOfTypes)); + assertTrue(numberOfTypes == allProperties.size()); + } + } + + public static List<PropertyDataDefinition> getPropertyType(List<List<PropertyDataDefinition>> allProperties, String propertyType) { + return allProperties.stream(). + flatMap(List::stream). + filter(e -> e.getName().equals(propertyType)). + collect(Collectors.toList()); + } + + public static void validateSpecificModulePropertiesFromFile(ToscaDefinition toscaDefinition){ + List<ToscaGroupsTopologyTemplateDefinition> vfModules = toscaDefinition.getTopology_template().getGroups().values().stream(). + filter(e -> e.getType().equals(VF_MODULE_TYPE)). + collect(Collectors.toList()); + + for(String propertyType :PROPERTY_TYPES){ + int numberOfTypes = (int) vfModules.stream(). + filter(e -> e.getProperties().containsKey(propertyType)). + count(); + SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF property %s exist, Expected: %s, Actual: %s ", propertyType, vfModules.size(), numberOfTypes)); + assertTrue(numberOfTypes == vfModules.size()); + } + } + + public static ToscaDefinition getToscaTemplate(String pathToCsar) throws Exception { + String outputFolder = DeploymentViewVerificator.unzipCsarFile(pathToCsar); + String templateFileName = VfModuleVerificator.getTemplateFilenname(pathToCsar); + + File pathToMainServiceTemplate = new File(outputFolder + File.separator + "Definitions" + File.separator + templateFileName); + ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(pathToMainServiceTemplate); + + DeploymentViewVerificator.cleanFolders(new File(outputFolder).getParent()); + + return toscaDefinition; + } + + public static String getTemplateFilenname(String pathToCsar) { + File csarFile = new File(pathToCsar); + String templateFileName = csarFile.getName().replaceAll("-csar.csar", "-template.yml"); + return templateFileName; + } + +} |