re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / ToscaValidationTest.java
1 package org.openecomp.sdc.ci.tests.execute.sanity;
2
3 import com.aventstack.extentreports.Status;
4 import fj.data.Either;
5 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
6 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
7 import org.onap.sdc.toscaparser.api.Group;
8 import org.onap.sdc.toscaparser.api.NodeTemplate;
9 import org.onap.sdc.toscaparser.api.elements.Metadata;
10 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
11 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
12 import org.openecomp.sdc.be.model.*;
13 import org.openecomp.sdc.be.model.Service;
14 import org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders;
15 import org.openecomp.sdc.ci.tests.datatypes.*;
16 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
17 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
18 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
19 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
20 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
21 import org.openecomp.sdc.ci.tests.tosca.datatypes.*;
22 import org.openecomp.sdc.ci.tests.tosca.model.ToscaMetadataFieldsPresentationEnum;
23 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
24 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
25 import org.openecomp.sdc.ci.tests.utils.CsarParserUtils;
26 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
27 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
28 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
29 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
30 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
31 import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
32 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
33 import org.openecomp.sdc.ci.tests.verificator.ToscaValidation;
34 import org.testng.annotations.DataProvider;
35 import org.testng.annotations.Test;
36
37 import java.io.File;
38 import java.util.*;
39
40 import static org.testng.Assert.assertFalse;
41
42
43 public class ToscaValidationTest extends SetupCDTest {
44
45     private static final String GENERIC_VF = "Generic_VF";
46     private static final String GENERIC_PNF = "Generic_PNF";
47     private static final String GENERIC_CR = "Generic_CR";
48
49     protected SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
50     User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
51
52     @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
53     public void toscaFileValidator(String filePath, String vnfFile) throws Exception {
54 //--------------------------GENERAL--------------------------------
55 /*//            for debugging only
56         setLog("Test");
57                 File amdocsCsarFileName = (new File("C:\\Users\\al714h\\Downloads\\d218be69637647b0b693647d84a8c03f.csar"));
58                 toscaMainAmdocsDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
59                 toscaMainVfDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File("C:\\Users\\al714h\\Downloads\\resource-Civfonboarded2016073VmxBv301072E2eE60f5c15-csar.csar"));
60         */
61   //      vnfFile = "vRouter for DHV Test_Version_4.zip";
62         setLog(vnfFile);
63         List<Boolean> status = new ArrayList<>();
64         ISdcCsarHelper fdntCsarHelper;
65         File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
66 //--------------------------AMDOCS--------------------------------
67         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, user);//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
68         resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
69         ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
70 //------adding generic inputs to expected object
71         toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
72 //      copy object
73         ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(toscaMainAmdocsDefinition);
74 //              create list of modules from HEAT.meta file
75         File latestFileFromDir = FileHandling.getLastModifiedFileNameFromDir();
76         List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(latestFileFromDir);
77 //TODO  VfModuleVerificator.verifyGroupMetadata();
78 //TODO--------------------------AMDOCS DOWNLOAD VIA APIS--------------------------------
79 //--------------------------VF--------------------------------
80 //              create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
81         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
82         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
83         ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
84 //--------------------------SERVICE--------------------------------
85         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();//getServiceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
86         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
87         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
88         ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
89 //--------------------------getProperties set values and declare--------------------
90         Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
91         Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
92         setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
93         PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
94
95         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
96         Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject = createExpectedVfModuleDefinitionObject(resource, service, listTypeHeatMetaDefinition);
97
98         File serviceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
99         OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + serviceCsarFileName));
100         ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + serviceCsarFileName));
101 //--------------------------initialization of Tosca Parser--------------------------------
102         fdntCsarHelper = initSdcCsarHelper(serviceCsarFileName, filesFolder);
103 ////---------------------------TESTS--------------------------------------------------
104         validateVfModuleJsonFile(expectedVfModulesDefinitionObject, service, componentInstanceDefinition.getUniqueId(), vnfFile, status);
105         validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
106         validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
107         validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
108         validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
109         validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
110         validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
111         validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
112         validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
113         validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
114
115         Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject = createExpectedToscaServiceGroupsDefinitionObject(resource, service, listTypeHeatMetaDefinition);
116         validateServiceModuleMetadata(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
117         validateServiceModuleProperty(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
118         validateServiceModuleMetadataUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
119         validateServiceModulePropertyUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
120
121         if (status.contains(false)) {
122             SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
123             assertFalse(true);
124         }
125     }
126
127
128     @DataProvider(name = "toscaValidationTest", parallel = true)
129     public static Object[][] dataProviderForSpecificResourceType() {
130         return new Object[][]{
131                 {"networkModel", ResourceTypeEnum.PNF, GENERIC_PNF},
132                 {"collectorResourceModel", ResourceTypeEnum.CR, GENERIC_CR},
133         };
134     }
135
136     @Test(dataProvider = "toscaValidationTest")
137     public void validateSpecificResourceType(String type, ResourceTypeEnum resourceType, String genericPropName) throws Exception {
138 //--------------------------GENERAL--------------------------------
139         String vnfFile = type;
140         setLog(vnfFile);
141         List<Boolean> status = new ArrayList<>();
142         ISdcCsarHelper fdntCsarHelper;
143         ToscaDefinition expectedToscaMainDefinition = new ToscaDefinition();
144         File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
145 //              filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
146
147         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(resourceType, user);
148         expectedToscaMainDefinition = addGenericPropertiesToToscaDefinitionObject(expectedToscaMainDefinition, genericPropName);
149         ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(expectedToscaMainDefinition);
150 //--------------------------VF--------------------------------
151         Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
152         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
153
154         ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
155
156 //--------------------------SERVICE--------------------------------
157         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
158         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
159
160         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
161         ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
162
163 //--------------------------getProperties set values and declare--------------------
164
165         Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
166         Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
167         setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
168         PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
169
170         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
171         File ServiceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
172         OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + ServiceCsarFileName));
173         ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + ServiceCsarFileName));
174
175 //--------------------------initialization of Tosca Parser--------------------------------
176
177         fdntCsarHelper = initSdcCsarHelper(ServiceCsarFileName, filesFolder);
178
179
180 //---------------------------TESTS--------------------------------------------------
181         validateVfMetadata(expectedToscaMainDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
182         validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
183         validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
184         validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
185         validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
186         validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
187         validateResourceInputs(expectedToscaMainDefinition, toscaMainVfDefinition, vnfFile, status);
188         validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
189         validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
190
191         if (status.contains(false)) {
192             SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
193             assertFalse(true);
194         }
195     }
196
197     /**
198      * The method set values to toscaDefinition object service level only, to resource level should put instead of setDefault --> setValue
199      * inputs.get(componentInstanceInput.getName()).setValue(randomString);
200      *
201      * @param componentInstancesInputs list of componentInstancesInputs
202      * @param toscaDefinition
203      */
204     private void setValuesToPropertiesList(Map<String, List<ComponentInstanceInput>> componentInstancesInputs, ToscaDefinition toscaDefinition) {
205         for (Map.Entry<String, List<ComponentInstanceInput>> entry : componentInstancesInputs.entrySet()) {
206             List<ComponentInstanceInput> value = entry.getValue();
207             String[] names = entry.getKey().split("\\.");
208             String expectedServiceInputPrefix = null;
209             Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
210             if (names.length > 0) {
211                 expectedServiceInputPrefix = names[names.length - 1] + "_";
212             }
213             for (ComponentInstanceInput componentInstanceInput : value) {
214
215
216                 String type = componentInstanceInput.getType();
217                 List<String> myList = new ArrayList<>();
218                 myList.add("cbf8049e-69e8-48c3-a06f-255634391403");
219                 switch (type) {
220                     case "string":
221                         String randomString = getRandomString();
222                         componentInstanceInput.setValue(randomString);
223                         inputs.get(componentInstanceInput.getName()).setDefault(randomString);
224
225                         break;
226                     case "integer":
227                         int randomInteger = getRandomInteger();
228                         componentInstanceInput.setValue(Integer.toString(randomInteger));
229                         inputs.get(componentInstanceInput.getName()).setDefault(randomInteger);
230                         break;
231                     case "float":
232                         componentInstanceInput.setValue("5.5");
233                         inputs.get(componentInstanceInput.getName()).setDefault("5.5");
234
235                         break;
236                     case "boolean":
237                         componentInstanceInput.setValue("true");
238                         inputs.get(componentInstanceInput.getName()).setDefault("true");
239                         break;
240                     case "list":
241                         String myListofStrings = myList.toString();
242                         componentInstanceInput.setValue(myListofStrings);
243                         inputs.get(componentInstanceInput.getName()).setDefault(myListofStrings);
244                         break;
245                     case "json":
246                         String myJson = "{\"firstParam\":\"my First Param Value\",\"secondParam\":\"my Second Param Value\",\"numberParam\":666}";
247                         componentInstanceInput.setValue(myJson);
248                         inputs.get(componentInstanceInput.getName()).setDefault(myJson);
249                         break;
250                     case "comma_delimited_list":
251                         String commaDelimitedList = "[\"one\", \"two\"]";
252                         componentInstanceInput.setValue(commaDelimitedList);
253                         inputs.get(componentInstanceInput.getName()).setDefault(commaDelimitedList);
254                         break;
255                     default:
256                         break;
257                 }
258
259                 String expectedServiceInputName = expectedServiceInputPrefix + componentInstanceInput.getName();
260                 ToscaInputsTopologyTemplateDefinition oldInput = inputs.get(componentInstanceInput.getName());
261                 inputs.put(expectedServiceInputName, oldInput);
262                 inputs.remove(componentInstanceInput.getName());
263
264             }
265
266         }
267     }
268
269     protected String getRandomString() {
270         String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
271         StringBuilder salt = new StringBuilder();
272         Random rnd = new Random();
273         while (salt.length() < 18) { // length of the random string.
274             int index = (int) (rnd.nextFloat() * SALTCHARS.length());
275             salt.append(SALTCHARS.charAt(index));
276         }
277         String strValue = salt.toString();
278         return strValue;
279
280     }
281
282     protected int getRandomInteger() {
283         Random r = new Random();
284         int low = 10;
285         int high = 100;
286         int integerValue = r.nextInt(high - low) + low;
287         return integerValue;
288     }
289
290
291     //--------------------------Metadata verification--------------------------------
292 //--------------------------Resource--------------------------------    
293
294     public List<Boolean> validateVfMetadata(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
295         reportStartTestPrint("validateVfMetadata", vnfFile);
296         //add resource metadata to expected object
297         toscaMainAmdocsDefinition = addAndGenerateResourceMetadataToExpectedObject(toscaMainAmdocsDefinition, resourceReqDetails, resource);
298         Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator = ToscaValidation.resourceToscaMetadataValidator(toscaMainAmdocsDefinition, toscaMainVfDefinition);
299         if (resourceToscaMetadataValidator.isRight())
300             status.add(false);
301         return status;
302     }
303
304     public List<Boolean> validateResourceNodeTemplateMetadata(ToscaDefinition toscaMainVfDefinition, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
305         reportStartTestPrint("validateResourceNodeTemplateMetadata", vnfFile);
306         Map<String, Map<String, String>> generateReosurceNodeTemplateMetadataToExpectedObject = generateResourceNodeTemplateMetadataToExpectedObject(resource);
307         Boolean resourceToscaMetadataValidator = ToscaValidation.resourceToscaNodeTemplateMetadataValidator(generateReosurceNodeTemplateMetadataToExpectedObject, toscaMainVfDefinition);
308         if (!resourceToscaMetadataValidator)
309             status.add(false);
310         return status;
311     }
312
313     //--------------------------Service--------------------------------
314     public List<Boolean> validateServiceMetadata(ToscaDefinition toscaMainServiceDefinition, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
315         reportStartTestPrint("validateServiceMetadata", vnfFile);
316         Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
317         Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.serviceToscaMetadataValidator(generateServiceMetadataToExpectedObject, toscaMainServiceDefinition);
318         if (serviceToscaMetadataValidator.isRight())
319             status.add(false);
320         return status;
321     }
322
323
324     public List<Boolean> validateServiceNodeTemplateMetadata(ToscaDefinition toscaMainServiceDefinition, ComponentInstance componentInstanceDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
325         reportStartTestPrint("validateServiceNodeTemplateMetadata", vnfFile);
326         Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
327         Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.componentToscaNodeTemplateMetadataValidator(generateServiceNodeTemplateMetadataToExpectedObject, toscaMainServiceDefinition, componentInstanceDefinition.getName(), ComponentTypeEnum.SERVICE, componentInstanceDefinition.getName());
328         if (serviceToscaMetadataValidator.isRight())
329             status.add(false);
330         return status;
331     }
332
333     private List<Boolean> validateVfModuleJsonFile(Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject, Service service, String resInstUniqueId, String vnfFile, List<Boolean> status) throws Exception {
334         reportStartTestPrint("validateVfModuleJsonFile", vnfFile);
335         String artifactUniqueId = null;
336         for (ComponentInstance inst : service.getComponentInstances()) {
337             if (inst.getUniqueId().equals(resInstUniqueId)) {
338                 artifactUniqueId = inst.getDeploymentArtifacts().get("vfModulesMetadata").getUniqueId();
339                 break;
340             }
341         }
342         if (artifactUniqueId == null) {
343             SetupCDTest.getExtendTest().log(Status.ERROR, "validateVfModuleJsonFile verification failed, artifact vfModulesMetadata not found");
344             status.add(false);
345             return status;
346         }
347         RestResponse restResponse = ArtifactRestUtils.downloadResourceInstanceArtifact(service.getUniqueId(), resInstUniqueId, user, artifactUniqueId);
348         String artifactPayload = ArtifactRestUtils.getDecodedArtifactPayloadFromResponse(restResponse);
349         Map<String, VfModuleDefinition> actualVfModulesDefinitionObject = ResponseParser.convertVfModuleJsonResponseToJavaObject(artifactPayload);
350         Either<Boolean, Map<String, Object>> vfModuleJsonFileValidator = ToscaValidation.vfModuleJsonFileValidator(expectedVfModulesDefinitionObject, actualVfModulesDefinitionObject);
351         if (vfModuleJsonFileValidator.isRight())
352             status.add(false);
353         return status;
354     }
355
356     //--------------------------Service verification against Pavel Parser--------------------------------
357     public List<Boolean> validateServiceMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
358         if (fdntCsarHelper == null) {
359             reportSkipTestPrint("validateServiceMetadataUsingParser", status);
360         } else {
361             reportStartTestPrint("validateServiceMetadataUsingParser", vnfFile);
362             Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
363             Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
364             Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceMetadataToExpectedObject, serviceMetadata);
365             if (serviceToscaMetadataValidatorAgainstParser.isRight())
366                 status.add(false);
367         }
368         return status;
369     }
370
371     public List<Boolean> validateServiceNodeTemplateMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ResourceReqDetails resourceReqDetails, Resource resource, ComponentInstance componentInstanceDefinition, String vnfFile, List<Boolean> status) throws Exception {
372         if (fdntCsarHelper == null) {
373             reportSkipTestPrint("validateServiceNodeTemplateMetadataUsingParser", status);
374         } else {
375             reportStartTestPrint("validateServiceNodeTemplateMetadataUsingParser", vnfFile);
376             Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
377             List<NodeTemplate> serviceNodeTemplates = fdntCsarHelper.getServiceNodeTemplates();
378             Metadata serviceNodeTemplateMetadata = serviceNodeTemplates.get(0).getMetaData();
379             Either<Boolean, Map<String, Object>> serviceNodeTemplateToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceNodeTemplateMetadataToExpectedObject, serviceNodeTemplateMetadata);
380             if (serviceNodeTemplateToscaMetadataValidatorAgainstParser.isRight())
381                 status.add(false);
382         }
383         return status;
384     }
385
386     //--------------------------Input verification--------------------------------
387
388     //--------------------------Resource--------------------------------
389     public List<Boolean> validateResourceInputs(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, String vnfFile, List<Boolean> status) throws Exception {
390         reportStartTestPrint("validateResourceInputs", vnfFile);
391         Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaMainAmdocsDefinition.getTopology_template().getInputs();
392         Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainVfDefinition.getTopology_template().getInputs();
393         Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
394         if (toscaInputsValidator.isRight())
395             status.add(false);
396         return status;
397     }
398
399     //--------------------------Service--------------------------------
400
401     public List<Boolean> validateServiceInputs(ToscaDefinition toscaExpectedMainServiceDefinition, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
402         reportStartTestPrint("validateServiceInputs", vnfFile);
403         Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
404         Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainServiceDefinition.getTopology_template().getInputs();
405         Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
406         if (toscaInputsValidator.isRight())
407             status.add(false);
408         return status;
409     }
410
411     public List<Boolean> validateServiceModuleMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
412         reportStartTestPrint("validateServiceModuleMetadata", vnfFile);
413
414         Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
415         if (toscaServiceModuleMetadataValidator.isRight())
416             status.add(false);
417         return status;
418     }
419
420     public List<Boolean> validateServiceModuleProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
421         reportStartTestPrint("validateServiceModuleProperty", vnfFile);
422
423         Either<Boolean, Map<String, Object>> toscaServiceModulePropertyValidator = ToscaValidation.serviceToscaGroupPropertyValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
424         if (toscaServiceModulePropertyValidator.isRight())
425             status.add(false);
426         return status;
427     }
428
429     //--------------------------Service verification against Pavel Parser--------------------------------
430     public List<Boolean> validateServiceInputsUsingParser(ISdcCsarHelper fdntCsarHelper, ToscaDefinition toscaExpectedMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
431         if (fdntCsarHelper == null) {
432             reportSkipTestPrint("validateServiceInputsUsingParser", status);
433         } else {
434             reportStartTestPrint("validateServiceInputsUsingParser", vnfFile);
435             Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
436             Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidatorAgainstParser(expectedInputsMap, fdntCsarHelper);
437             if (toscaInputsValidator.isRight())
438                 status.add(false);
439         }
440         return status;
441     }
442
443     public List<Boolean> validateServiceModuleMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
444         reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
445         String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetaData().getValue("customizationUUID");
446         List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
447         Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
448         if (toscaServiceModuleMetadataValidator.isRight())
449             status.add(false);
450         return status;
451     }
452
453     public List<Boolean> validateServiceModulePropertyUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
454         reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
455         String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetaData().getValue("customizationUUID");
456         List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
457         Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupPropertyValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
458         if (toscaServiceModuleMetadataValidator.isRight())
459             status.add(false);
460         return status;
461     }
462
463     private Map<String, ToscaGroupsTopologyTemplateDefinition> createExpectedToscaServiceGroupsDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
464         Map<String, ToscaGroupsTopologyTemplateDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
465
466         for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
467             if (!moduleType.getTypeName().equals("artifacts")) {
468                 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
469                     ToscaGroupsTopologyTemplateDefinition toscaGroupsTopologyTemplateDefinition = new ToscaGroupsTopologyTemplateDefinition();
470                     String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
471                     ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
472                     if (!toscaServiceGroupsMetadataDefinition.equals("")) {
473                         String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
474                         toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
475                         toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
476                         ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
477                         toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
478                         toscaGroupsTopologyTemplateDefinitionMap.put(serviceModuleName, toscaGroupsTopologyTemplateDefinition);
479                     } else {
480                         getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
481                     }
482                 }
483             }
484         }
485         return toscaGroupsTopologyTemplateDefinitionMap;
486
487     }
488
489
490     private Map<String, VfModuleDefinition> createExpectedVfModuleDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
491         Map<String, VfModuleDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
492
493         for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
494             if (!moduleType.getTypeName().equals("artifacts")) {
495                 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
496                     VfModuleDefinition toscaGroupsTopologyTemplateDefinition = new VfModuleDefinition();
497                     String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
498                     ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
499                     if (!toscaServiceGroupsMetadataDefinition.equals("")) {
500                         toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, resourceModuleName, service);
501                         toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
502                         ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
503                         toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
504                         toscaGroupsTopologyTemplateDefinition.setArtifacts(getArtifactsUuidListForRI(module, resource, service));
505                         toscaGroupsTopologyTemplateDefinitionMap.put(toscaServiceGroupsMetadataDefinition.vfModuleModelName, toscaGroupsTopologyTemplateDefinition);
506
507                     } else {
508                         getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
509                     }
510                 }
511             }
512         }
513         return toscaGroupsTopologyTemplateDefinitionMap;
514
515     }
516
517     private List<String> getArtifactsUuidListForRI(GroupHeatMetaDefinition module, Resource resource, Service service) {
518 //TODO check if each heat include its env file
519         List<String> artifactsUuidList = new ArrayList<>();
520         ComponentInstance resourceInstance = null;
521         for (ComponentInstance componentInstance : service.getComponentInstances()) {
522             if (componentInstance.getUniqueId().contains(resource.getUniqueId())) {
523                 resourceInstance = componentInstance;
524                 break;
525             }
526         }
527
528         Collection<ArtifactDefinition> artifactsDefinitionValues = resourceInstance.getDeploymentArtifacts().values();
529
530         for (HeatMetaFirstLevelDefinition moduleArtifactDefinition : module.getArtifactList()) {
531             for (ArtifactDefinition riArtifactDefinition : artifactsDefinitionValues) {
532                 String heatYamlName = moduleArtifactDefinition.getFileName();
533                 String heatEnvName = heatYamlName.replaceAll("yaml|yml", "env");
534                 String riArtifactName = riArtifactDefinition.getArtifactName();
535                 if (riArtifactName.equals(heatYamlName) || riArtifactName.equals(heatEnvName)) {
536                     artifactsUuidList.add(riArtifactDefinition.getArtifactUUID());
537                 }
538             }
539         }
540
541         return artifactsUuidList;
542     }
543
544     private ToscaGroupPropertyDefinition setGroupProperty(GroupHeatMetaDefinition module) {
545         ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = new ToscaGroupPropertyDefinition();
546         toscaGroupPropertyDefinition.setVf_module_label(module.getGroupName());
547         Boolean isBase = module.getPropertyHeatMetaDefinition().getValue();
548         if (isBase) {
549             toscaGroupPropertyDefinition.setInitial_count("1");
550             toscaGroupPropertyDefinition.setMin_vf_module_instances("1");
551             toscaGroupPropertyDefinition.setMax_vf_module_instances("1");
552             toscaGroupPropertyDefinition.setVf_module_type("Base");
553         } else {
554             toscaGroupPropertyDefinition.setInitial_count("0");
555             toscaGroupPropertyDefinition.setMin_vf_module_instances("0");
556             toscaGroupPropertyDefinition.setMax_vf_module_instances("");
557             toscaGroupPropertyDefinition.setVf_module_type("Expansion");
558         }
559         toscaGroupPropertyDefinition.setAvailability_zone_count("");
560         toscaGroupPropertyDefinition.setVfc_list("");
561         toscaGroupPropertyDefinition.setVf_module_description("");
562         toscaGroupPropertyDefinition.setVolume_group(isVolumeGroup(module));
563
564         return toscaGroupPropertyDefinition;
565     }
566
567     private String isVolumeGroup(GroupHeatMetaDefinition module) {
568         String isVolumeGroup = "false";
569         for (HeatMetaFirstLevelDefinition artifactList : module.getArtifactList()) {
570             if (artifactList.getType().equals(ArtifactTypeEnum.HEAT_VOL.getType())) {
571                 isVolumeGroup = "true";
572                 return isVolumeGroup;
573             }
574         }
575         return isVolumeGroup;
576     }
577
578     private Map<String, ToscaServiceGroupsMetadataDefinition> createExpectedToscaServiceGroupsPropertyDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
579
580         Map<String, ToscaServiceGroupsMetadataDefinition> toscaServiceGroupsMetadataDefinitionMap = new HashMap<>();
581         for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
582             Map<String, String> groupProperty = new HashMap<>();
583
584             ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
585             for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
586                 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
587                 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
588                 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
589                     String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
590                     toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
591                     toscaServiceGroupsMetadataDefinitionMap.put(serviceModuleName, toscaServiceGroupsMetadataDefinition);
592                 } else {
593                     getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
594                 }
595             }
596         }
597         return toscaServiceGroupsMetadataDefinitionMap;
598
599     }
600
601     private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromServiceObject(ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition, String serviceModuleName, Service service) {
602         for (GroupInstance groupInstance : service.getComponentInstances().get(0).getGroupInstances()) {
603             if (groupInstance.getName().contains(serviceModuleName)) {
604                 toscaServiceGroupsMetadataDefinition.setVfModuleModelCustomizationUUID(groupInstance.getCustomizationUUID());
605                 return toscaServiceGroupsMetadataDefinition;
606             }
607         }
608         return toscaServiceGroupsMetadataDefinition;
609     }
610
611     private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromResourceObject(String resourceModuleName, Resource resource) {
612         ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
613         for (GroupDefinition group : resource.getGroups()) {
614             if (group.getName().contains(resourceModuleName)) {
615                 toscaServiceGroupsMetadataDefinition.setVfModuleModelName(group.getName());
616                 toscaServiceGroupsMetadataDefinition.setVfModuleModelInvariantUUID(group.getInvariantUUID());
617                 toscaServiceGroupsMetadataDefinition.setVfModuleModelUUID(group.getGroupUUID());
618                 toscaServiceGroupsMetadataDefinition.setVfModuleModelVersion(group.getVersion());
619                 return toscaServiceGroupsMetadataDefinition;
620             }
621         }
622         return toscaServiceGroupsMetadataDefinition;
623     }
624
625     public static String buildResourceModuleName(Resource resource, String groupName) {
626         return resource.getSystemName() + ".." + groupName + ".." + "module-";
627     }
628
629     public static String buildServiceModuleName(String resourceInstanceNormalizedName, String resourceGroupName) {
630         return resourceInstanceNormalizedName + ".." + resourceGroupName;
631     }
632
633
634     @Override
635     protected UserRoleEnum getRole() {
636         return UserRoleEnum.DESIGNER;
637     }
638
639
640     public static ToscaDefinition addGenericInputsToToscaObject(ToscaDefinition toscaDefinition, String genericName) throws Exception {
641         Resource genericResource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, genericName, "1.0");
642         ToscaTopologyTemplateDefinition topologyTemplate = toscaDefinition.getTopology_template();
643         Map<String, ToscaInputsTopologyTemplateDefinition> newInput = new HashMap<>();
644         for (PropertyDefinition property : genericResource.getProperties()) {
645             ToscaInputsTopologyTemplateDefinition input = new ToscaInputsTopologyTemplateDefinition();
646 //                              input.setConstraints(property.getConstraints());
647             input.setDefault(property.getDefaultValue());
648             input.setDescription(property.getDescription());
649 //                              input.setEntry_schema(property.getSchema());
650             input.setName(property.getName());
651 //                              input.setRequired(property.get);
652             input.setStatus(property.getStatus());
653             input.setType(property.getType());
654             input.setValue(property.getValue());
655             newInput.put(property.getName(), input);
656         }
657
658         topologyTemplate.addInputs(newInput);
659         toscaDefinition.setTopology_template(topologyTemplate);
660         return toscaDefinition;
661     }
662
663     public static ToscaDefinition setNameToToscaInput(ToscaDefinition toscaDefinition) {
664         Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
665         for (String name : inputs.keySet()) {
666             inputs.get(name).setName(name);
667         }
668         toscaDefinition.getTopology_template().setInputs(inputs);
669         return toscaDefinition;
670     }
671
672     public static ToscaDefinition addAndGenerateResourceMetadataToExpectedObject(ToscaDefinition toscaDefinition, ResourceReqDetails resourceReqDetails, Component component) {
673
674         Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
675         toscaDefinition.setMetadata(metadata);
676         return toscaDefinition;
677     }
678
679     public static Map<String, String> convertResourceMetadataToMap(ResourceReqDetails resourceReqDetails, Component component) {
680         Map<String, String> metadata = new HashMap<>();
681
682         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resourceReqDetails.getCategories().get(0).getName());
683         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resourceReqDetails.getDescription());
684         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
685         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resourceReqDetails.getResourceType());
686         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
687         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
688
689         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resourceReqDetails.getVendorName());
690         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resourceReqDetails.getResourceVendorModelNumber());
691         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resourceReqDetails.getVendorRelease());
692         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resourceReqDetails.getCategories().get(0).getSubcategories().get(0).getName());
693         return metadata;
694     }
695
696     public static Map<String, String> convertResourceNodeTemplateMetadataToMap(ComponentInstance componentInstance) throws Exception {
697
698         Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
699         Map<String, String> metadata = new HashMap<>();
700
701         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resource.getCategories().get(0).getName());
702         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resource.getDescription());
703         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, resource.getInvariantUUID());
704         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resource.getResourceType().toString());
705         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, resource.getUUID());
706         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, resource.getName());
707
708         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resource.getVendorName());
709         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resource.getResourceVendorModelNumber());
710         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resource.getVendorRelease());
711         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resource.getCategories().get(0).getSubcategories().get(0).getName());
712         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstance.getCustomizationUUID());
713         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstance.getComponentVersion());
714
715         return metadata;
716     }
717
718     public static Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject(ResourceReqDetails resourceReqDetails, Component component, ComponentInstance componentInstanceDefinition) {
719
720         Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
721         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstanceDefinition.getCustomizationUUID());
722         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstanceDefinition.getComponentVersion());
723
724         return metadata;
725     }
726
727     public static Map<String, Map<String, String>> generateResourceNodeTemplateMetadataToExpectedObject(Component component) throws Exception {
728
729         Map<String, Map<String, String>> resourcesNodeTemplateMetadataMap = new HashMap<>();
730         if (component.getComponentInstances() != null && !component.getComponentInstances().isEmpty()) {
731             for (ComponentInstance componentInstance : component.getComponentInstances()) {
732                 Map<String, String> metadata = convertResourceNodeTemplateMetadataToMap(componentInstance);
733                 resourcesNodeTemplateMetadataMap.put(componentInstance.getName(), metadata);
734             }
735         }
736         return resourcesNodeTemplateMetadataMap;
737     }
738
739     public static Map<String, String> generateServiceMetadataToExpectedObject(ServiceReqDetails serviceReqDetails, Component component) {
740
741         Map<String, String> metadata = new HashMap<>();
742
743         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, serviceReqDetails.getCategories().get(0).getName());
744         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, serviceReqDetails.getDescription());
745         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
746         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, "Service");
747         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
748         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
749
750         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_TYPE.value, serviceReqDetails.getServiceType());
751         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ROLE.value, serviceReqDetails.getServiceRole());
752         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAMING_POLICY.value, serviceReqDetails.getNamingPolicy());
753         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.ECOMP_GENERATED_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());
754         metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ECOMP_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());//equals to ECOMP_GENERATED_NAMING
755
756         return metadata;
757     }
758
759     public static void reportStartTestPrint(String testName, String vnfFile) {
760 //              reportMessageInColor("info", "blue", "Running test \" + testName + \" with zip file - \" + vnfFile");
761         SetupCDTest.getExtendTest().log(Status.INFO, "<html><font color=\"blue\"> Running test " + testName + " with zip file - " + vnfFile + "</font></html>");
762     }
763
764     public static void reportSkipTestPrint(String testName, List<Boolean> status) {
765 //              reportMessageInColor("error", "orange", "Skip test \" + testName + \" due to previous tosca parser error");
766         SetupCDTest.getExtendTest().log(Status.ERROR, "<html><font color=\"orange\"> Skip test " + testName + " due to previous tosca parser error" + "</font></html>");
767         status.add(false);
768     }
769
770     public static void reportMessageInColor(String status, String color, String message) {
771         String printLine = getReportMessageInColor(color, message);
772         SetupCDTest.getExtendTest().log(Status.valueOf(status), printLine);
773 //              SetupCDTest.getExtendTest().log(Status.valueOf(status), getReportMessageInColor(color, message));
774     }
775
776     /**
777      * @param color   = red, green, orange, blue ...
778      * @param message - message string
779      * @return string in desired color
780      */
781     public static String getReportMessageInColor(String color, String message) {
782         String returnValue = ("<html><font color=\\\"+color+\"\">" + message + "</font></html>").toString();
783         return returnValue;
784     }
785
786 /*      @Test()
787     public void printTest(){
788                 System.out.println("print");
789                 reportMessageInColor("ERROR", "green", "green");
790                 reportMessageInColor("INFO", "orange", "orange");
791                 reportMessageInColor("INFO", "red", "red");
792         }*/
793
794 /*      @Test
795         public void allottedResourceModelTest() throws Exception{
796                 List<Boolean> status = new ArrayList<>();
797
798                 List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
799                 List<String> newRandomFileNamesFromFolder = OnbordingDataProviders.getRandomElements(1, fileNamesFromFolder);
800                 String vnfFile = newRandomFileNamesFromFolder.get(0);
801                 setLog(vnfFile);
802                 String filePath = FileHandling.getVnfRepositoryPath();
803                 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
804
805                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(ResourceCategoryEnum.ALLOTTED_RESOURCE_SERVICE_ADMIN);
806                 resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
807
808                 ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
809                 toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
810
811                 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
812                 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
813
814                 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
815
816                 status = validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
817                 status = validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
818                 status = validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
819
820                 if(status.contains(false)){
821                         SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: allottedResourceModelTest tosca validation test failed with zip file " + vnfFile);
822                         Assert.assertFalse(true);
823                 }
824         }*/
825
826
827     //  help method to toscaValidation tests
828     private ISdcCsarHelper initSdcCsarHelper(File serviceCsarFileName, File filesFolder) {
829
830         ISdcCsarHelper fdntCsarHelper;
831         try {
832             SetupCDTest.getExtendTest().log(Status.INFO, "Tosca parser is going to convert service csar file to ISdcCsarHelper object...");
833             fdntCsarHelper = factory.getSdcCsarHelper(filesFolder.getPath() + serviceCsarFileName);
834         } catch (Exception e) {
835             SetupCDTest.getExtendTest().log(Status.ERROR, "Tosca parser FAILED to convert service csar file to ISdcCsarHelper object...");
836             SetupCDTest.getExtendTest().log(Status.FAIL, e);
837             fdntCsarHelper = null;
838         }
839         return fdntCsarHelper;
840     }
841
842
843     /**
844      * @param resourceReqDetails to create Vsp
845      * @return updated resourceReqDetails after Vsp was created
846      */
847     private ResourceReqDetails createCustomizedVsp(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
848         VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, filePath, vnfFile, user);
849         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
850         return resourceReqDetails;
851     }
852
853     /**
854      * @param resourceReqDetails to download csar file via UI
855      * @return Tosca definition object from main yaml file
856      */
857     private ToscaDefinition downloadAndGetToscaMainYamlObjectUI(ResourceReqDetails resourceReqDetails, File filesFolder) throws Exception {
858         DownloadManager.downloadCsarByNameFromVSPRepository(resourceReqDetails.getName(), false);
859         File amdocsCsarFileName = FileHandling.getLastModifiedFileNameFromDir(filesFolder.getAbsolutePath());
860         return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
861     }
862
863     /**
864      * @param toscaMainAmdocsDefinition object to add generic properties
865      * @param genericName               resource name
866      * @return updated toscaMainAmdocsDefinition object
867      */
868     private ToscaDefinition addGenericPropertiesToToscaDefinitionObject(ToscaDefinition toscaMainAmdocsDefinition, String genericName) throws Exception {
869         toscaMainAmdocsDefinition = setNameToToscaInput(toscaMainAmdocsDefinition);
870         toscaMainAmdocsDefinition = addGenericInputsToToscaObject(toscaMainAmdocsDefinition, genericName);
871         return toscaMainAmdocsDefinition;
872     }
873
874     /**
875      * @param resource to download csar file via API
876      * @return Tosca definition object from main yaml file
877      */
878     private ToscaDefinition downloadAndGetToscaMainYamlObjectApi(Resource resource, File filesFolder) throws Exception {
879         File vfCsarFileName = new File(File.separator + "VfCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
880         OnboardingUtillViaApis.downloadToscaCsarToDirectory(resource, new File(filesFolder.getPath() + vfCsarFileName));
881         return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + vfCsarFileName));
882     }
883
884
885 }
886
887