2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.execute.sanity;
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
26 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
27 import org.onap.sdc.toscaparser.api.Group;
28 import org.onap.sdc.toscaparser.api.NodeTemplate;
29 import org.onap.sdc.toscaparser.api.elements.Metadata;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
32 import org.openecomp.sdc.be.model.*;
33 import org.openecomp.sdc.be.model.Service;
34 import org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders;
35 import org.openecomp.sdc.ci.tests.datatypes.*;
36 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.tosca.datatypes.*;
42 import org.openecomp.sdc.ci.tests.tosca.model.ToscaMetadataFieldsPresentationEnum;
43 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
44 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
45 import org.openecomp.sdc.ci.tests.utils.CsarParserUtils;
46 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
47 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
48 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
49 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
50 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
51 import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
52 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
53 import org.openecomp.sdc.ci.tests.verificator.ToscaValidation;
54 import org.testng.annotations.DataProvider;
55 import org.testng.annotations.Test;
60 import static org.testng.Assert.assertFalse;
63 public class ToscaValidationTest extends SetupCDTest {
65 private static final String GENERIC_VF = "Generic_VF";
66 private static final String GENERIC_PNF = "Generic_PNF";
67 private static final String GENERIC_CR = "Generic_CR";
69 protected SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
70 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
72 @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
73 public void toscaFileValidator(String filePath, String vnfFile) throws Exception {
74 //--------------------------GENERAL--------------------------------
75 /*// for debugging only
77 File amdocsCsarFileName = (new File("C:\\Users\\al714h\\Downloads\\d218be69637647b0b693647d84a8c03f.csar"));
78 toscaMainAmdocsDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
79 toscaMainVfDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File("C:\\Users\\al714h\\Downloads\\resource-Civfonboarded2016073VmxBv301072E2eE60f5c15-csar.csar"));
81 // vnfFile = "vRouter for DHV Test_Version_4.zip";
83 List<Boolean> status = new ArrayList<>();
84 ISdcCsarHelper fdntCsarHelper;
85 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
86 //--------------------------AMDOCS--------------------------------
87 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, user);//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
88 resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
89 ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
90 //------adding generic inputs to expected object
91 toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
93 ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(toscaMainAmdocsDefinition);
94 // create list of modules from HEAT.meta file
95 File latestFileFromDir = FileHandling.getLastModifiedFileNameFromDir();
96 List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(latestFileFromDir);
97 //TODO VfModuleVerificator.verifyGroupMetadata();
98 //TODO--------------------------AMDOCS DOWNLOAD VIA APIS--------------------------------
99 //--------------------------VF--------------------------------
100 // create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
101 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
102 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
103 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
104 //--------------------------SERVICE--------------------------------
105 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();//getServiceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
106 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
107 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
108 ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
109 //--------------------------getProperties set values and declare--------------------
110 Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
111 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
112 setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
113 PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
115 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
116 Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject = createExpectedVfModuleDefinitionObject(resource, service, listTypeHeatMetaDefinition);
118 File serviceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
119 OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + serviceCsarFileName));
120 ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + serviceCsarFileName));
121 //--------------------------initialization of Tosca Parser--------------------------------
122 fdntCsarHelper = initSdcCsarHelper(serviceCsarFileName, filesFolder);
123 ////---------------------------TESTS--------------------------------------------------
124 validateVfModuleJsonFile(expectedVfModulesDefinitionObject, service, componentInstanceDefinition.getUniqueId(), vnfFile, status);
125 validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
126 validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
127 validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
128 validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
129 validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
130 validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
131 validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
132 validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
133 validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
135 Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject = createExpectedToscaServiceGroupsDefinitionObject(resource, service, listTypeHeatMetaDefinition);
136 validateServiceModuleMetadata(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
137 validateServiceModuleProperty(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
138 validateServiceModuleMetadataUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
139 validateServiceModulePropertyUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
141 if (status.contains(false)) {
142 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
148 @DataProvider(name = "toscaValidationTest", parallel = true)
149 public static Object[][] dataProviderForSpecificResourceType() {
150 return new Object[][]{
151 {"networkModel", ResourceTypeEnum.PNF, GENERIC_PNF},
152 {"collectorResourceModel", ResourceTypeEnum.CR, GENERIC_CR},
156 @Test(dataProvider = "toscaValidationTest")
157 public void validateSpecificResourceType(String type, ResourceTypeEnum resourceType, String genericPropName) throws Exception {
158 //--------------------------GENERAL--------------------------------
159 String vnfFile = type;
161 List<Boolean> status = new ArrayList<>();
162 ISdcCsarHelper fdntCsarHelper;
163 ToscaDefinition expectedToscaMainDefinition = new ToscaDefinition();
164 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
165 // filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
167 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(resourceType, user);
168 expectedToscaMainDefinition = addGenericPropertiesToToscaDefinitionObject(expectedToscaMainDefinition, genericPropName);
169 ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(expectedToscaMainDefinition);
170 //--------------------------VF--------------------------------
171 Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
172 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
174 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
176 //--------------------------SERVICE--------------------------------
177 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
178 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
180 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
181 ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
183 //--------------------------getProperties set values and declare--------------------
185 Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
186 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
187 setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
188 PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
190 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
191 File ServiceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
192 OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + ServiceCsarFileName));
193 ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + ServiceCsarFileName));
195 //--------------------------initialization of Tosca Parser--------------------------------
197 fdntCsarHelper = initSdcCsarHelper(ServiceCsarFileName, filesFolder);
200 //---------------------------TESTS--------------------------------------------------
201 validateVfMetadata(expectedToscaMainDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
202 validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
203 validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
204 validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
205 validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
206 validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
207 validateResourceInputs(expectedToscaMainDefinition, toscaMainVfDefinition, vnfFile, status);
208 validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
209 validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
211 if (status.contains(false)) {
212 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
218 * The method set values to toscaDefinition object service level only, to resource level should put instead of setDefault --> setValue
219 * inputs.get(componentInstanceInput.getName()).setValue(randomString);
221 * @param componentInstancesInputs list of componentInstancesInputs
222 * @param toscaDefinition
224 private void setValuesToPropertiesList(Map<String, List<ComponentInstanceInput>> componentInstancesInputs, ToscaDefinition toscaDefinition) {
225 for (Map.Entry<String, List<ComponentInstanceInput>> entry : componentInstancesInputs.entrySet()) {
226 List<ComponentInstanceInput> value = entry.getValue();
227 String[] names = entry.getKey().split("\\.");
228 String expectedServiceInputPrefix = null;
229 Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
230 if (names.length > 0) {
231 expectedServiceInputPrefix = names[names.length - 1] + "_";
233 for (ComponentInstanceInput componentInstanceInput : value) {
236 String type = componentInstanceInput.getType();
237 List<String> myList = new ArrayList<>();
238 myList.add("cbf8049e-69e8-48c3-a06f-255634391403");
241 String randomString = getRandomString();
242 componentInstanceInput.setValue(randomString);
243 inputs.get(componentInstanceInput.getName()).setDefault(randomString);
247 int randomInteger = getRandomInteger();
248 componentInstanceInput.setValue(Integer.toString(randomInteger));
249 inputs.get(componentInstanceInput.getName()).setDefault(randomInteger);
252 componentInstanceInput.setValue("5.5");
253 inputs.get(componentInstanceInput.getName()).setDefault("5.5");
257 componentInstanceInput.setValue("true");
258 inputs.get(componentInstanceInput.getName()).setDefault("true");
261 String myListofStrings = myList.toString();
262 componentInstanceInput.setValue(myListofStrings);
263 inputs.get(componentInstanceInput.getName()).setDefault(myListofStrings);
266 String myJson = "{\"firstParam\":\"my First Param Value\",\"secondParam\":\"my Second Param Value\",\"numberParam\":666}";
267 componentInstanceInput.setValue(myJson);
268 inputs.get(componentInstanceInput.getName()).setDefault(myJson);
270 case "comma_delimited_list":
271 String commaDelimitedList = "[\"one\", \"two\"]";
272 componentInstanceInput.setValue(commaDelimitedList);
273 inputs.get(componentInstanceInput.getName()).setDefault(commaDelimitedList);
279 String expectedServiceInputName = expectedServiceInputPrefix + componentInstanceInput.getName();
280 ToscaInputsTopologyTemplateDefinition oldInput = inputs.get(componentInstanceInput.getName());
281 inputs.put(expectedServiceInputName, oldInput);
282 inputs.remove(componentInstanceInput.getName());
289 protected String getRandomString() {
290 String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
291 StringBuilder salt = new StringBuilder();
292 Random rnd = new Random();
293 while (salt.length() < 18) { // length of the random string.
294 int index = (int) (rnd.nextFloat() * SALTCHARS.length());
295 salt.append(SALTCHARS.charAt(index));
297 String strValue = salt.toString();
302 protected int getRandomInteger() {
303 Random r = new Random();
306 int integerValue = r.nextInt(high - low) + low;
311 //--------------------------Metadata verification--------------------------------
312 //--------------------------Resource--------------------------------
314 public List<Boolean> validateVfMetadata(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
315 reportStartTestPrint("validateVfMetadata", vnfFile);
316 //add resource metadata to expected object
317 toscaMainAmdocsDefinition = addAndGenerateResourceMetadataToExpectedObject(toscaMainAmdocsDefinition, resourceReqDetails, resource);
318 Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator = ToscaValidation.resourceToscaMetadataValidator(toscaMainAmdocsDefinition, toscaMainVfDefinition);
319 if (resourceToscaMetadataValidator.isRight())
324 public List<Boolean> validateResourceNodeTemplateMetadata(ToscaDefinition toscaMainVfDefinition, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
325 reportStartTestPrint("validateResourceNodeTemplateMetadata", vnfFile);
326 Map<String, Map<String, String>> generateReosurceNodeTemplateMetadataToExpectedObject = generateResourceNodeTemplateMetadataToExpectedObject(resource);
327 Boolean resourceToscaMetadataValidator = ToscaValidation.resourceToscaNodeTemplateMetadataValidator(generateReosurceNodeTemplateMetadataToExpectedObject, toscaMainVfDefinition);
328 if (!resourceToscaMetadataValidator)
333 //--------------------------Service--------------------------------
334 public List<Boolean> validateServiceMetadata(ToscaDefinition toscaMainServiceDefinition, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
335 reportStartTestPrint("validateServiceMetadata", vnfFile);
336 Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
337 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.serviceToscaMetadataValidator(generateServiceMetadataToExpectedObject, toscaMainServiceDefinition);
338 if (serviceToscaMetadataValidator.isRight())
344 public List<Boolean> validateServiceNodeTemplateMetadata(ToscaDefinition toscaMainServiceDefinition, ComponentInstance componentInstanceDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
345 reportStartTestPrint("validateServiceNodeTemplateMetadata", vnfFile);
346 Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
347 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.componentToscaNodeTemplateMetadataValidator(generateServiceNodeTemplateMetadataToExpectedObject, toscaMainServiceDefinition, componentInstanceDefinition.getName(), ComponentTypeEnum.SERVICE, componentInstanceDefinition.getName());
348 if (serviceToscaMetadataValidator.isRight())
353 private List<Boolean> validateVfModuleJsonFile(Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject, Service service, String resInstUniqueId, String vnfFile, List<Boolean> status) throws Exception {
354 reportStartTestPrint("validateVfModuleJsonFile", vnfFile);
355 String artifactUniqueId = null;
356 for (ComponentInstance inst : service.getComponentInstances()) {
357 if (inst.getUniqueId().equals(resInstUniqueId)) {
358 artifactUniqueId = inst.getDeploymentArtifacts().get("vfModulesMetadata").getUniqueId();
362 if (artifactUniqueId == null) {
363 SetupCDTest.getExtendTest().log(Status.ERROR, "validateVfModuleJsonFile verification failed, artifact vfModulesMetadata not found");
367 RestResponse restResponse = ArtifactRestUtils.downloadResourceInstanceArtifact(service.getUniqueId(), resInstUniqueId, user, artifactUniqueId);
368 String artifactPayload = ArtifactRestUtils.getDecodedArtifactPayloadFromResponse(restResponse);
369 Map<String, VfModuleDefinition> actualVfModulesDefinitionObject = ResponseParser.convertVfModuleJsonResponseToJavaObject(artifactPayload);
370 Either<Boolean, Map<String, Object>> vfModuleJsonFileValidator = ToscaValidation.vfModuleJsonFileValidator(expectedVfModulesDefinitionObject, actualVfModulesDefinitionObject);
371 if (vfModuleJsonFileValidator.isRight())
376 //--------------------------Service verification against Pavel Parser--------------------------------
377 public List<Boolean> validateServiceMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
378 if (fdntCsarHelper == null) {
379 reportSkipTestPrint("validateServiceMetadataUsingParser", status);
381 reportStartTestPrint("validateServiceMetadataUsingParser", vnfFile);
382 Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
383 Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
384 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceMetadataToExpectedObject, serviceMetadata);
385 if (serviceToscaMetadataValidatorAgainstParser.isRight())
391 public List<Boolean> validateServiceNodeTemplateMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ResourceReqDetails resourceReqDetails, Resource resource, ComponentInstance componentInstanceDefinition, String vnfFile, List<Boolean> status) throws Exception {
392 if (fdntCsarHelper == null) {
393 reportSkipTestPrint("validateServiceNodeTemplateMetadataUsingParser", status);
395 reportStartTestPrint("validateServiceNodeTemplateMetadataUsingParser", vnfFile);
396 Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
397 List<NodeTemplate> serviceNodeTemplates = fdntCsarHelper.getServiceNodeTemplates();
398 Metadata serviceNodeTemplateMetadata = serviceNodeTemplates.get(0).getMetaData();
399 Either<Boolean, Map<String, Object>> serviceNodeTemplateToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceNodeTemplateMetadataToExpectedObject, serviceNodeTemplateMetadata);
400 if (serviceNodeTemplateToscaMetadataValidatorAgainstParser.isRight())
406 //--------------------------Input verification--------------------------------
408 //--------------------------Resource--------------------------------
409 public List<Boolean> validateResourceInputs(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, String vnfFile, List<Boolean> status) throws Exception {
410 reportStartTestPrint("validateResourceInputs", vnfFile);
411 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaMainAmdocsDefinition.getTopology_template().getInputs();
412 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainVfDefinition.getTopology_template().getInputs();
413 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
414 if (toscaInputsValidator.isRight())
419 //--------------------------Service--------------------------------
421 public List<Boolean> validateServiceInputs(ToscaDefinition toscaExpectedMainServiceDefinition, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
422 reportStartTestPrint("validateServiceInputs", vnfFile);
423 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
424 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainServiceDefinition.getTopology_template().getInputs();
425 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
426 if (toscaInputsValidator.isRight())
431 public List<Boolean> validateServiceModuleMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
432 reportStartTestPrint("validateServiceModuleMetadata", vnfFile);
434 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
435 if (toscaServiceModuleMetadataValidator.isRight())
440 public List<Boolean> validateServiceModuleProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
441 reportStartTestPrint("validateServiceModuleProperty", vnfFile);
443 Either<Boolean, Map<String, Object>> toscaServiceModulePropertyValidator = ToscaValidation.serviceToscaGroupPropertyValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
444 if (toscaServiceModulePropertyValidator.isRight())
449 //--------------------------Service verification against Pavel Parser--------------------------------
450 public List<Boolean> validateServiceInputsUsingParser(ISdcCsarHelper fdntCsarHelper, ToscaDefinition toscaExpectedMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
451 if (fdntCsarHelper == null) {
452 reportSkipTestPrint("validateServiceInputsUsingParser", status);
454 reportStartTestPrint("validateServiceInputsUsingParser", vnfFile);
455 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
456 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidatorAgainstParser(expectedInputsMap, fdntCsarHelper);
457 if (toscaInputsValidator.isRight())
463 public List<Boolean> validateServiceModuleMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
464 reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
465 String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetaData().getValue("customizationUUID");
466 List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
467 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
468 if (toscaServiceModuleMetadataValidator.isRight())
473 public List<Boolean> validateServiceModulePropertyUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
474 reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
475 String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetaData().getValue("customizationUUID");
476 List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
477 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupPropertyValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
478 if (toscaServiceModuleMetadataValidator.isRight())
483 private Map<String, ToscaGroupsTopologyTemplateDefinition> createExpectedToscaServiceGroupsDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
484 Map<String, ToscaGroupsTopologyTemplateDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
486 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
487 if (!moduleType.getTypeName().equals("artifacts")) {
488 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
489 ToscaGroupsTopologyTemplateDefinition toscaGroupsTopologyTemplateDefinition = new ToscaGroupsTopologyTemplateDefinition();
490 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
491 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
492 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
493 String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
494 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
495 toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
496 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
497 toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
498 toscaGroupsTopologyTemplateDefinitionMap.put(serviceModuleName, toscaGroupsTopologyTemplateDefinition);
500 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
505 return toscaGroupsTopologyTemplateDefinitionMap;
510 private Map<String, VfModuleDefinition> createExpectedVfModuleDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
511 Map<String, VfModuleDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
513 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
514 if (!moduleType.getTypeName().equals("artifacts")) {
515 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
516 VfModuleDefinition toscaGroupsTopologyTemplateDefinition = new VfModuleDefinition();
517 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
518 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
519 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
520 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, resourceModuleName, service);
521 toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
522 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
523 toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
524 toscaGroupsTopologyTemplateDefinition.setArtifacts(getArtifactsUuidListForRI(module, resource, service));
525 toscaGroupsTopologyTemplateDefinitionMap.put(toscaServiceGroupsMetadataDefinition.vfModuleModelName, toscaGroupsTopologyTemplateDefinition);
528 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
533 return toscaGroupsTopologyTemplateDefinitionMap;
537 private List<String> getArtifactsUuidListForRI(GroupHeatMetaDefinition module, Resource resource, Service service) {
538 //TODO check if each heat include its env file
539 List<String> artifactsUuidList = new ArrayList<>();
540 ComponentInstance resourceInstance = null;
541 for (ComponentInstance componentInstance : service.getComponentInstances()) {
542 if (componentInstance.getUniqueId().contains(resource.getUniqueId())) {
543 resourceInstance = componentInstance;
548 Collection<ArtifactDefinition> artifactsDefinitionValues = resourceInstance.getDeploymentArtifacts().values();
550 for (HeatMetaFirstLevelDefinition moduleArtifactDefinition : module.getArtifactList()) {
551 for (ArtifactDefinition riArtifactDefinition : artifactsDefinitionValues) {
552 String heatYamlName = moduleArtifactDefinition.getFileName();
553 String heatEnvName = heatYamlName.replaceAll("yaml|yml", "env");
554 String riArtifactName = riArtifactDefinition.getArtifactName();
555 if (riArtifactName.equals(heatYamlName) || riArtifactName.equals(heatEnvName)) {
556 artifactsUuidList.add(riArtifactDefinition.getArtifactUUID());
561 return artifactsUuidList;
564 private ToscaGroupPropertyDefinition setGroupProperty(GroupHeatMetaDefinition module) {
565 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = new ToscaGroupPropertyDefinition();
566 toscaGroupPropertyDefinition.setVf_module_label(module.getGroupName());
567 Boolean isBase = module.getPropertyHeatMetaDefinition().getValue();
569 toscaGroupPropertyDefinition.setInitial_count("1");
570 toscaGroupPropertyDefinition.setMin_vf_module_instances("1");
571 toscaGroupPropertyDefinition.setMax_vf_module_instances("1");
572 toscaGroupPropertyDefinition.setVf_module_type("Base");
574 toscaGroupPropertyDefinition.setInitial_count("0");
575 toscaGroupPropertyDefinition.setMin_vf_module_instances("0");
576 toscaGroupPropertyDefinition.setMax_vf_module_instances("");
577 toscaGroupPropertyDefinition.setVf_module_type("Expansion");
579 toscaGroupPropertyDefinition.setAvailability_zone_count("");
580 toscaGroupPropertyDefinition.setVfc_list("");
581 toscaGroupPropertyDefinition.setVf_module_description("");
582 toscaGroupPropertyDefinition.setVolume_group(isVolumeGroup(module));
584 return toscaGroupPropertyDefinition;
587 private String isVolumeGroup(GroupHeatMetaDefinition module) {
588 String isVolumeGroup = "false";
589 for (HeatMetaFirstLevelDefinition artifactList : module.getArtifactList()) {
590 if (artifactList.getType().equals(ArtifactTypeEnum.HEAT_VOL.getType())) {
591 isVolumeGroup = "true";
592 return isVolumeGroup;
595 return isVolumeGroup;
598 private Map<String, ToscaServiceGroupsMetadataDefinition> createExpectedToscaServiceGroupsPropertyDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
600 Map<String, ToscaServiceGroupsMetadataDefinition> toscaServiceGroupsMetadataDefinitionMap = new HashMap<>();
601 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
602 Map<String, String> groupProperty = new HashMap<>();
604 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
605 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
606 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
607 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
608 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
609 String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
610 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
611 toscaServiceGroupsMetadataDefinitionMap.put(serviceModuleName, toscaServiceGroupsMetadataDefinition);
613 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
617 return toscaServiceGroupsMetadataDefinitionMap;
621 private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromServiceObject(ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition, String serviceModuleName, Service service) {
622 for (GroupInstance groupInstance : service.getComponentInstances().get(0).getGroupInstances()) {
623 if (groupInstance.getName().contains(serviceModuleName)) {
624 toscaServiceGroupsMetadataDefinition.setVfModuleModelCustomizationUUID(groupInstance.getCustomizationUUID());
625 return toscaServiceGroupsMetadataDefinition;
628 return toscaServiceGroupsMetadataDefinition;
631 private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromResourceObject(String resourceModuleName, Resource resource) {
632 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
633 for (GroupDefinition group : resource.getGroups()) {
634 if (group.getName().contains(resourceModuleName)) {
635 toscaServiceGroupsMetadataDefinition.setVfModuleModelName(group.getName());
636 toscaServiceGroupsMetadataDefinition.setVfModuleModelInvariantUUID(group.getInvariantUUID());
637 toscaServiceGroupsMetadataDefinition.setVfModuleModelUUID(group.getGroupUUID());
638 toscaServiceGroupsMetadataDefinition.setVfModuleModelVersion(group.getVersion());
639 return toscaServiceGroupsMetadataDefinition;
642 return toscaServiceGroupsMetadataDefinition;
645 public static String buildResourceModuleName(Resource resource, String groupName) {
646 return resource.getSystemName() + ".." + groupName + ".." + "module-";
649 public static String buildServiceModuleName(String resourceInstanceNormalizedName, String resourceGroupName) {
650 return resourceInstanceNormalizedName + ".." + resourceGroupName;
655 protected UserRoleEnum getRole() {
656 return UserRoleEnum.DESIGNER;
660 public static ToscaDefinition addGenericInputsToToscaObject(ToscaDefinition toscaDefinition, String genericName) throws Exception {
661 Resource genericResource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, genericName, "1.0");
662 ToscaTopologyTemplateDefinition topologyTemplate = toscaDefinition.getTopology_template();
663 Map<String, ToscaInputsTopologyTemplateDefinition> newInput = new HashMap<>();
664 for (PropertyDefinition property : genericResource.getProperties()) {
665 ToscaInputsTopologyTemplateDefinition input = new ToscaInputsTopologyTemplateDefinition();
666 // input.setConstraints(property.getConstraints());
667 input.setDefault(property.getDefaultValue());
668 input.setDescription(property.getDescription());
669 // input.setEntry_schema(property.getSchema());
670 input.setName(property.getName());
671 // input.setRequired(property.get);
672 input.setStatus(property.getStatus());
673 input.setType(property.getType());
674 input.setValue(property.getValue());
675 newInput.put(property.getName(), input);
678 topologyTemplate.addInputs(newInput);
679 toscaDefinition.setTopology_template(topologyTemplate);
680 return toscaDefinition;
683 public static ToscaDefinition setNameToToscaInput(ToscaDefinition toscaDefinition) {
684 Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
685 for (String name : inputs.keySet()) {
686 inputs.get(name).setName(name);
688 toscaDefinition.getTopology_template().setInputs(inputs);
689 return toscaDefinition;
692 public static ToscaDefinition addAndGenerateResourceMetadataToExpectedObject(ToscaDefinition toscaDefinition, ResourceReqDetails resourceReqDetails, Component component) {
694 Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
695 toscaDefinition.setMetadata(metadata);
696 return toscaDefinition;
699 public static Map<String, String> convertResourceMetadataToMap(ResourceReqDetails resourceReqDetails, Component component) {
700 Map<String, String> metadata = new HashMap<>();
702 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resourceReqDetails.getCategories().get(0).getName());
703 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resourceReqDetails.getDescription());
704 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
705 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resourceReqDetails.getResourceType());
706 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
707 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
709 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resourceReqDetails.getVendorName());
710 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resourceReqDetails.getResourceVendorModelNumber());
711 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resourceReqDetails.getVendorRelease());
712 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resourceReqDetails.getCategories().get(0).getSubcategories().get(0).getName());
716 public static Map<String, String> convertResourceNodeTemplateMetadataToMap(ComponentInstance componentInstance) throws Exception {
718 Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
719 Map<String, String> metadata = new HashMap<>();
721 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resource.getCategories().get(0).getName());
722 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resource.getDescription());
723 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, resource.getInvariantUUID());
724 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resource.getResourceType().toString());
725 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, resource.getUUID());
726 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, resource.getName());
728 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resource.getVendorName());
729 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resource.getResourceVendorModelNumber());
730 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resource.getVendorRelease());
731 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resource.getCategories().get(0).getSubcategories().get(0).getName());
732 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstance.getCustomizationUUID());
733 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstance.getComponentVersion());
738 public static Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject(ResourceReqDetails resourceReqDetails, Component component, ComponentInstance componentInstanceDefinition) {
740 Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
741 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstanceDefinition.getCustomizationUUID());
742 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstanceDefinition.getComponentVersion());
747 public static Map<String, Map<String, String>> generateResourceNodeTemplateMetadataToExpectedObject(Component component) throws Exception {
749 Map<String, Map<String, String>> resourcesNodeTemplateMetadataMap = new HashMap<>();
750 if (component.getComponentInstances() != null && !component.getComponentInstances().isEmpty()) {
751 for (ComponentInstance componentInstance : component.getComponentInstances()) {
752 Map<String, String> metadata = convertResourceNodeTemplateMetadataToMap(componentInstance);
753 resourcesNodeTemplateMetadataMap.put(componentInstance.getName(), metadata);
756 return resourcesNodeTemplateMetadataMap;
759 public static Map<String, String> generateServiceMetadataToExpectedObject(ServiceReqDetails serviceReqDetails, Component component) {
761 Map<String, String> metadata = new HashMap<>();
763 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, serviceReqDetails.getCategories().get(0).getName());
764 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, serviceReqDetails.getDescription());
765 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
766 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, "Service");
767 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
768 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
770 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_TYPE.value, serviceReqDetails.getServiceType());
771 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ROLE.value, serviceReqDetails.getServiceRole());
772 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAMING_POLICY.value, serviceReqDetails.getNamingPolicy());
773 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.ECOMP_GENERATED_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());
774 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ECOMP_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());//equals to ECOMP_GENERATED_NAMING
779 public static void reportStartTestPrint(String testName, String vnfFile) {
780 // reportMessageInColor("info", "blue", "Running test \" + testName + \" with zip file - \" + vnfFile");
781 SetupCDTest.getExtendTest().log(Status.INFO, "<html><font color=\"blue\"> Running test " + testName + " with zip file - " + vnfFile + "</font></html>");
784 public static void reportSkipTestPrint(String testName, List<Boolean> status) {
785 // reportMessageInColor("error", "orange", "Skip test \" + testName + \" due to previous tosca parser error");
786 SetupCDTest.getExtendTest().log(Status.ERROR, "<html><font color=\"orange\"> Skip test " + testName + " due to previous tosca parser error" + "</font></html>");
790 public static void reportMessageInColor(String status, String color, String message) {
791 String printLine = getReportMessageInColor(color, message);
792 SetupCDTest.getExtendTest().log(Status.valueOf(status), printLine);
793 // SetupCDTest.getExtendTest().log(Status.valueOf(status), getReportMessageInColor(color, message));
797 * @param color = red, green, orange, blue ...
798 * @param message - message string
799 * @return string in desired color
801 public static String getReportMessageInColor(String color, String message) {
802 String returnValue = ("<html><font color=\\\"+color+\"\">" + message + "</font></html>").toString();
807 public void printTest(){
808 System.out.println("print");
809 reportMessageInColor("ERROR", "green", "green");
810 reportMessageInColor("INFO", "orange", "orange");
811 reportMessageInColor("INFO", "red", "red");
815 public void allottedResourceModelTest() throws Exception{
816 List<Boolean> status = new ArrayList<>();
818 List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
819 List<String> newRandomFileNamesFromFolder = OnbordingDataProviders.getRandomElements(1, fileNamesFromFolder);
820 String vnfFile = newRandomFileNamesFromFolder.get(0);
822 String filePath = FileHandling.getVnfRepositoryPath();
823 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
825 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(ResourceCategoryEnum.ALLOTTED_RESOURCE_SERVICE_ADMIN);
826 resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
828 ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
829 toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
831 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
832 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
834 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
836 status = validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
837 status = validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
838 status = validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
840 if(status.contains(false)){
841 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: allottedResourceModelTest tosca validation test failed with zip file " + vnfFile);
842 Assert.assertFalse(true);
847 // help method to toscaValidation tests
848 private ISdcCsarHelper initSdcCsarHelper(File serviceCsarFileName, File filesFolder) {
850 ISdcCsarHelper fdntCsarHelper;
852 SetupCDTest.getExtendTest().log(Status.INFO, "Tosca parser is going to convert service csar file to ISdcCsarHelper object...");
853 fdntCsarHelper = factory.getSdcCsarHelper(filesFolder.getPath() + serviceCsarFileName);
854 } catch (Exception e) {
855 SetupCDTest.getExtendTest().log(Status.ERROR, "Tosca parser FAILED to convert service csar file to ISdcCsarHelper object...");
856 SetupCDTest.getExtendTest().log(Status.FAIL, e);
857 fdntCsarHelper = null;
859 return fdntCsarHelper;
864 * @param resourceReqDetails to create Vsp
865 * @return updated resourceReqDetails after Vsp was created
867 private ResourceReqDetails createCustomizedVsp(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
868 VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, filePath, vnfFile, user);
869 resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
870 return resourceReqDetails;
874 * @param resourceReqDetails to download csar file via UI
875 * @return Tosca definition object from main yaml file
877 private ToscaDefinition downloadAndGetToscaMainYamlObjectUI(ResourceReqDetails resourceReqDetails, File filesFolder) throws Exception {
878 DownloadManager.downloadCsarByNameFromVSPRepository(resourceReqDetails.getName(), false);
879 File amdocsCsarFileName = FileHandling.getLastModifiedFileNameFromDir(filesFolder.getAbsolutePath());
880 return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
884 * @param toscaMainAmdocsDefinition object to add generic properties
885 * @param genericName resource name
886 * @return updated toscaMainAmdocsDefinition object
888 private ToscaDefinition addGenericPropertiesToToscaDefinitionObject(ToscaDefinition toscaMainAmdocsDefinition, String genericName) throws Exception {
889 toscaMainAmdocsDefinition = setNameToToscaInput(toscaMainAmdocsDefinition);
890 toscaMainAmdocsDefinition = addGenericInputsToToscaObject(toscaMainAmdocsDefinition, genericName);
891 return toscaMainAmdocsDefinition;
895 * @param resource to download csar file via API
896 * @return Tosca definition object from main yaml file
898 private ToscaDefinition downloadAndGetToscaMainYamlObjectApi(Resource resource, File filesFolder) throws Exception {
899 File vfCsarFileName = new File(File.separator + "VfCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
900 OnboardingUtillViaApis.downloadToscaCsarToDirectory(resource, new File(filesFolder.getPath() + vfCsarFileName));
901 return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + vfCsarFileName));