2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.verificator;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
28 import java.lang.reflect.Field;
29 import java.util.Arrays;
30 import java.util.List;
32 import java.util.stream.Collectors;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
35 import org.openecomp.sdc.be.model.ComponentInstance;
36 import org.openecomp.sdc.be.model.GroupInstance;
37 import org.openecomp.sdc.be.model.Resource;
38 import org.openecomp.sdc.be.model.Service;
39 import org.openecomp.sdc.ci.tests.datatypes.TypeHeatMetaDefinition;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
42 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaGroupsTopologyTemplateDefinition;
43 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaServiceGroupsMetadataDefinition;
45 import com.aventstack.extentreports.Status;
47 public class VfModuleVerificator {
50 private final static List<String> PROPERTY_TYPES = DeploymentViewVerificator.getCurrentPropertiesWithoutIsBase();//{"vf_module_label", "min_vf_module_instances", "max_vf_module_instances", "initial_count"};
51 private static final String VF_MODULE_TYPE = "org.openecomp.groups.VfModule";
54 * compare number of groups from HEAT.meta file vs TOSCA yaml groups generated by ASDC
55 * @param listTypeHeatMetaDefinition - java object created from HEAT.meta file
56 * @param toscaDefinition - java object created from TOSCA yaml
58 public static void compareNumberOfVfModules(List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition, ToscaDefinition toscaDefinition) {
60 int heatMetaGroupCount = 0;
61 int toscaDefinitionGroupCount = 0;
62 for (TypeHeatMetaDefinition typeHeatMetaDefinition : listTypeHeatMetaDefinition) {
63 if(!typeHeatMetaDefinition.getTypeName().equals("artifacts")) {
64 heatMetaGroupCount = typeHeatMetaDefinition.getGroupHeatMetaDefinition().size();
67 toscaDefinitionGroupCount = toscaDefinition.getTopology_template().getGroups().size();
68 assertEquals("Expected num of groups in HEAT.meta file is " + heatMetaGroupCount + ", but was in TOSCA yaml file " + toscaDefinitionGroupCount, heatMetaGroupCount, toscaDefinitionGroupCount);
72 * check group structure and "metadata" parameters vs data on the service object
73 * @param toscaDefinition
75 public static void verifyGroupMetadata(ToscaDefinition toscaDefinition, Service service) {
77 Map<String, ToscaGroupsTopologyTemplateDefinition> groups = toscaDefinition.getTopology_template().getGroups();
78 for (Map.Entry<String, ToscaGroupsTopologyTemplateDefinition> groupTopologyTemplateDefinition : groups.entrySet()) {
79 String key = groupTopologyTemplateDefinition.getKey();
80 GroupInstance groupInstanceObject = getGroupInstanceByKey(key, service);
81 ToscaServiceGroupsMetadataDefinition metadata = groupTopologyTemplateDefinition.getValue().getMetadata();
82 assertNotNull("groupInstanceObject is null", groupInstanceObject);
83 assertTrue("expected vfModuleModelName " + groupInstanceObject.getGroupName() + ", actual " + metadata.getVfModuleModelName(), groupInstanceObject.getGroupName().equals(metadata.getVfModuleModelName()));
84 assertTrue("expected vfModuleModelInvariantUUID " + groupInstanceObject.getInvariantUUID() + ", actual " + metadata.getVfModuleModelInvariantUUID(), groupInstanceObject.getInvariantUUID().equals(metadata.getVfModuleModelInvariantUUID()));
85 assertTrue("expected vfModuleModelCustomizationUUID " + groupInstanceObject.getCustomizationUUID() + ", actual " + metadata.getVfModuleModelCustomizationUUID(), groupInstanceObject.getCustomizationUUID().equals(metadata.getVfModuleModelCustomizationUUID()));
86 assertTrue("expected vfModuleModelUUID " + groupInstanceObject.getGroupUUID() + ", actual " + metadata.getVfModuleModelUUID(), groupInstanceObject.getGroupUUID().equals(metadata.getVfModuleModelUUID()));
87 assertTrue("expected vfModuleModelVersion " + groupInstanceObject.getVersion() + ", actual " + metadata.getVfModuleModelVersion(), groupInstanceObject.getVersion().equals(metadata.getVfModuleModelVersion()));
97 public static GroupInstance getGroupInstanceByKey(String key, Service service) {
98 for(ComponentInstance componentInstance : service.getComponentInstances()){
99 for(GroupInstance groupInstance : componentInstance.getGroupInstances()){
100 if( key.equals(groupInstance.getName())){
101 return groupInstance;
108 public static void validateSpecificModulePropertiesFromRequest(Resource resource) {
109 List<List<PropertyDataDefinition>> allProperties = resource.getGroups().stream().
110 filter(e -> e.getType().equals(VF_MODULE_TYPE)).
111 map(e -> e.getProperties()).
112 collect(Collectors.toList());
113 for(String propertyType : PROPERTY_TYPES){
114 int numberOfTypes = getPropertyType(allProperties, propertyType).size();
115 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF property %s exist, Expected: %s, Actual: %s ", propertyType, allProperties.size(), numberOfTypes));
116 assertTrue(numberOfTypes == allProperties.size());
120 public static List<PropertyDataDefinition> getPropertyType(List<List<PropertyDataDefinition>> allProperties, String propertyType) {
121 return allProperties.stream().
122 flatMap(List::stream).
123 filter(e -> e.getName().equals(propertyType)).
124 collect(Collectors.toList());
127 public static void validateSpecificModulePropertiesFromFile(ToscaDefinition toscaDefinition){
128 List<ToscaGroupsTopologyTemplateDefinition> vfModules = toscaDefinition.getTopology_template().getGroups().values().stream().
129 filter(e -> e.getType().equals(VF_MODULE_TYPE)).
130 collect(Collectors.toList());
132 for(String propertyType : PROPERTY_TYPES){
133 int numberOfTypes = (int) vfModules.stream().
134 // Get all declared fields from class ToscaGroupPropertyDefinition, collect them to List and check that current property exist and declared class
135 filter(e -> Arrays.asList(e.getProperties().getClass().getDeclaredFields()).stream().
136 map(p -> p.getName()).
137 collect(Collectors.toList()).
138 contains(propertyType)
140 collect(Collectors.toList()).
142 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF property %s exist, Expected: %s, Actual: %s ", propertyType, vfModules.size(), numberOfTypes));
143 assertTrue(numberOfTypes == vfModules.size());
147 public static String getTemplateFilenname(String pathToCsar) {
148 File csarFile = new File(pathToCsar);
149 String templateFileName = csarFile.getName().replaceAll("-csar.csar", "-template.yml");
150 return templateFileName;