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.onap.sdc.frontend.ci.tests.execute.sanity;
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.onap.sdc.frontend.ci.tests.dataProvider.OnbordingDataProviders;
26 import org.onap.sdc.backend.ci.tests.datatypes.enums.ArtifactTypeEnum;
27 import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
28 import org.onap.sdc.backend.ci.tests.tosca.model.ToscaMetadataFieldsPresentationEnum;
29 import org.onap.sdc.frontend.ci.tests.utilities.DownloadManager;
30 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
31 import org.onap.sdc.backend.ci.tests.utils.CsarParserUtils;
32 import org.onap.sdc.backend.ci.tests.utils.ToscaParserUtils;
33 import org.onap.sdc.backend.ci.tests.utils.general.AtomicOperationUtils;
34 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
35 import org.onap.sdc.backend.ci.tests.utils.general.OnboardingUtillViaApis;
36 import org.onap.sdc.backend.ci.tests.utils.rest.ArtifactRestUtils;
37 import org.onap.sdc.backend.ci.tests.utils.rest.PropertyRestUtils;
38 import org.onap.sdc.backend.ci.tests.utils.rest.ResponseParser;
39 import org.onap.sdc.frontend.ci.tests.verificator.ToscaValidation;
40 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
41 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
42 import org.onap.sdc.toscaparser.api.Group;
43 import org.onap.sdc.toscaparser.api.NodeTemplate;
44 import org.onap.sdc.toscaparser.api.elements.Metadata;
45 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
46 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
47 import org.openecomp.sdc.be.model.ArtifactDefinition;
48 import org.openecomp.sdc.be.model.Component;
49 import org.openecomp.sdc.be.model.ComponentInstance;
50 import org.openecomp.sdc.be.model.ComponentInstanceInput;
51 import org.openecomp.sdc.be.model.GroupDefinition;
52 import org.openecomp.sdc.be.model.GroupInstance;
53 import org.openecomp.sdc.be.model.PropertyDefinition;
54 import org.openecomp.sdc.be.model.Resource;
55 import org.openecomp.sdc.be.model.Service;
56 import org.openecomp.sdc.be.model.User;
57 import org.onap.sdc.backend.ci.tests.datatypes.GroupHeatMetaDefinition;
58 import org.onap.sdc.backend.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
59 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
60 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
61 import org.onap.sdc.backend.ci.tests.datatypes.TypeHeatMetaDefinition;
62 import org.onap.sdc.backend.ci.tests.datatypes.VendorSoftwareProductObject;
63 import org.onap.sdc.backend.ci.tests.datatypes.enums.LifeCycleStatesEnum;
64 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
65 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
66 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaDefinition;
67 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaGroupPropertyDefinition;
68 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaGroupsTopologyTemplateDefinition;
69 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaInputsTopologyTemplateDefinition;
70 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaServiceGroupsMetadataDefinition;
71 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaTopologyTemplateDefinition;
72 import org.onap.sdc.backend.ci.tests.tosca.datatypes.VfModuleDefinition;
73 import org.testng.annotations.DataProvider;
74 import org.testng.annotations.Test;
77 import java.util.ArrayList;
78 import java.util.Collection;
79 import java.util.HashMap;
80 import java.util.List;
82 import java.util.Random;
84 import static org.testng.Assert.assertFalse;
87 public class ToscaValidationTest extends SetupCDTest {
89 private static final String GENERIC_VF = "Generic_VF";
90 private static final String GENERIC_PNF = "Generic_PNF";
91 private static final String GENERIC_CR = "Generic_CR";
93 protected SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
94 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
96 @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
97 public void toscaFileValidator(String filePath, String vnfFile) throws Exception {
98 //--------------------------GENERAL--------------------------------
99 /*// for debugging only
101 File amdocsCsarFileName = (new File("C:\\Users\\al714h\\Downloads\\d218be69637647b0b693647d84a8c03f.csar"));
102 toscaMainAmdocsDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
103 toscaMainVfDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File("C:\\Users\\al714h\\Downloads\\resource-Civfonboarded2016073VmxBv301072E2eE60f5c15-csar.csar"));
105 // vnfFile = "vRouter for DHV Test_Version_4.zip";
107 List<Boolean> status = new ArrayList<>();
108 ISdcCsarHelper fdntCsarHelper;
109 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
110 //--------------------------AMDOCS--------------------------------
111 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, user);//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
112 resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
113 ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
114 //------adding generic inputs to expected object
115 toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
117 ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(toscaMainAmdocsDefinition);
118 // create list of modules from HEAT.meta file
119 File latestFileFromDir = FileHandling.getLastModifiedFileNameFromDir();
120 List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(latestFileFromDir);
121 //TODO VfModuleVerificator.verifyGroupMetadata();
122 //TODO--------------------------AMDOCS DOWNLOAD VIA APIS--------------------------------
123 //--------------------------VF--------------------------------
124 // create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
125 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
126 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
127 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
128 //--------------------------SERVICE--------------------------------
129 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();//getServiceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
130 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
131 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
132 ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
133 //--------------------------getProperties set values and declare--------------------
134 Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
135 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
136 setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
137 PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
139 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
140 Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject = createExpectedVfModuleDefinitionObject(resource, service, listTypeHeatMetaDefinition);
142 File serviceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
143 OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + serviceCsarFileName));
144 ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + serviceCsarFileName));
145 //--------------------------initialization of Tosca Parser--------------------------------
146 fdntCsarHelper = initSdcCsarHelper(serviceCsarFileName, filesFolder);
147 ////---------------------------TESTS--------------------------------------------------
148 validateVfModuleJsonFile(expectedVfModulesDefinitionObject, service, componentInstanceDefinition.getUniqueId(), vnfFile, status);
149 validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
150 validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
151 validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
152 validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
153 validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
154 validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
155 validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
156 validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
157 validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
159 Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject = createExpectedToscaServiceGroupsDefinitionObject(resource, service, listTypeHeatMetaDefinition);
160 validateServiceModuleMetadata(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
161 validateServiceModuleProperty(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition, vnfFile, status);
162 validateServiceModuleMetadataUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
163 validateServiceModulePropertyUsingParser(fdntCsarHelper, expectedToscaServiceGroupsDefinitionObject, vnfFile, status);
165 if (status.contains(false)) {
166 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
172 @DataProvider(name = "toscaValidationTest", parallel = true)
173 public static Object[][] dataProviderForSpecificResourceType() {
174 return new Object[][]{
175 {"networkModel", ResourceTypeEnum.PNF, GENERIC_PNF},
176 {"collectorResourceModel", ResourceTypeEnum.CR, GENERIC_CR},
180 @Test(dataProvider = "toscaValidationTest")
181 public void validateSpecificResourceType(String type, ResourceTypeEnum resourceType, String genericPropName) throws Exception {
182 //--------------------------GENERAL--------------------------------
183 String vnfFile = type;
185 List<Boolean> status = new ArrayList<>();
186 ISdcCsarHelper fdntCsarHelper;
187 ToscaDefinition expectedToscaMainDefinition = new ToscaDefinition();
188 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
189 // filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
191 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(resourceType, user);
192 expectedToscaMainDefinition = addGenericPropertiesToToscaDefinitionObject(expectedToscaMainDefinition, genericPropName);
193 ToscaDefinition toscaExpectedMainServiceDefinition = new ToscaDefinition(expectedToscaMainDefinition);
194 //--------------------------VF--------------------------------
195 Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
196 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
198 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
200 //--------------------------SERVICE--------------------------------
201 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
202 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
204 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
205 ComponentInstance componentInstanceDefinition = addComponentInstanceToComponentContainer.left().value();
207 //--------------------------getProperties set values and declare--------------------
209 Component componentObject = AtomicOperationUtils.getComponentObject(service, UserRoleEnum.DESIGNER);
210 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = componentObject.getComponentInstancesInputs();
211 setValuesToPropertiesList(componentInstancesInputs, toscaExpectedMainServiceDefinition);
212 PropertyRestUtils.declareProporties(componentObject, componentInstancesInputs, user);
214 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
215 File ServiceCsarFileName = new File(File.separator + "ServiceCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
216 OnboardingUtillViaApis.downloadToscaCsarToDirectory(service, new File(filesFolder.getPath() + ServiceCsarFileName));
217 ToscaDefinition toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + ServiceCsarFileName));
219 //--------------------------initialization of Tosca Parser--------------------------------
221 fdntCsarHelper = initSdcCsarHelper(ServiceCsarFileName, filesFolder);
224 //---------------------------TESTS--------------------------------------------------
225 validateVfMetadata(expectedToscaMainDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
226 validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
227 validateServiceMetadata(toscaMainServiceDefinition, serviceReqDetails, service, vnfFile, status);
228 validateServiceNodeTemplateMetadata(toscaMainServiceDefinition, componentInstanceDefinition, resourceReqDetails, resource, vnfFile, status);
229 validateServiceMetadataUsingParser(fdntCsarHelper, serviceReqDetails, service, vnfFile, status);
230 validateServiceNodeTemplateMetadataUsingParser(fdntCsarHelper, resourceReqDetails, resource, componentInstanceDefinition, vnfFile, status);
231 validateResourceInputs(expectedToscaMainDefinition, toscaMainVfDefinition, vnfFile, status);
232 validateServiceInputs(toscaExpectedMainServiceDefinition, toscaMainServiceDefinition, vnfFile, status);
233 validateServiceInputsUsingParser(fdntCsarHelper, toscaExpectedMainServiceDefinition, vnfFile, status);
235 if (status.contains(false)) {
236 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: tosca validation test failed with zip file " + vnfFile);
242 * The method set values to toscaDefinition object service level only, to resource level should put instead of setDefault --> setValue
243 * inputs.get(componentInstanceInput.getName()).setValue(randomString);
245 * @param componentInstancesInputs list of componentInstancesInputs
246 * @param toscaDefinition
248 private void setValuesToPropertiesList(Map<String, List<ComponentInstanceInput>> componentInstancesInputs, ToscaDefinition toscaDefinition) {
249 for (Map.Entry<String, List<ComponentInstanceInput>> entry : componentInstancesInputs.entrySet()) {
250 List<ComponentInstanceInput> value = entry.getValue();
251 String[] names = entry.getKey().split("\\.");
252 String expectedServiceInputPrefix = null;
253 Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
254 if (names.length > 0) {
255 expectedServiceInputPrefix = names[names.length - 1] + "_";
257 for (ComponentInstanceInput componentInstanceInput : value) {
260 String type = componentInstanceInput.getType();
261 List<String> myList = new ArrayList<>();
262 myList.add("cbf8049e-69e8-48c3-a06f-255634391403");
265 String randomString = getRandomString();
266 componentInstanceInput.setValue(randomString);
267 inputs.get(componentInstanceInput.getName()).setDefault(randomString);
271 int randomInteger = getRandomInteger();
272 componentInstanceInput.setValue(Integer.toString(randomInteger));
273 inputs.get(componentInstanceInput.getName()).setDefault(randomInteger);
276 componentInstanceInput.setValue("5.5");
277 inputs.get(componentInstanceInput.getName()).setDefault("5.5");
281 componentInstanceInput.setValue("true");
282 inputs.get(componentInstanceInput.getName()).setDefault("true");
285 String myListofStrings = myList.toString();
286 componentInstanceInput.setValue(myListofStrings);
287 inputs.get(componentInstanceInput.getName()).setDefault(myListofStrings);
290 String myJson = "{\"firstParam\":\"my First Param Value\",\"secondParam\":\"my Second Param Value\",\"numberParam\":666}";
291 componentInstanceInput.setValue(myJson);
292 inputs.get(componentInstanceInput.getName()).setDefault(myJson);
294 case "comma_delimited_list":
295 String commaDelimitedList = "[\"one\", \"two\"]";
296 componentInstanceInput.setValue(commaDelimitedList);
297 inputs.get(componentInstanceInput.getName()).setDefault(commaDelimitedList);
303 String expectedServiceInputName = expectedServiceInputPrefix + componentInstanceInput.getName();
304 ToscaInputsTopologyTemplateDefinition oldInput = inputs.get(componentInstanceInput.getName());
305 inputs.put(expectedServiceInputName, oldInput);
306 inputs.remove(componentInstanceInput.getName());
313 protected String getRandomString() {
314 final int LengthOfRandomString = 18;
315 String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
316 StringBuilder salt = new StringBuilder();
317 Random rnd = new Random();
318 while (salt.length() < LengthOfRandomString) {
319 int index = (int) (rnd.nextFloat() * SALTCHARS.length());
320 salt.append(SALTCHARS.charAt(index));
322 String strValue = salt.toString();
327 protected int getRandomInteger() {
329 final int high = 100;
330 Random r = new Random();
331 return r.nextInt(high - low) + low;
335 //--------------------------Metadata verification--------------------------------
336 //--------------------------Resource--------------------------------
338 public List<Boolean> validateVfMetadata(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
339 reportStartTestPrint("validateVfMetadata", vnfFile);
340 //add resource metadata to expected object
341 toscaMainAmdocsDefinition = addAndGenerateResourceMetadataToExpectedObject(toscaMainAmdocsDefinition, resourceReqDetails, resource);
342 Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator = ToscaValidation.resourceToscaMetadataValidator(toscaMainAmdocsDefinition, toscaMainVfDefinition);
343 if (resourceToscaMetadataValidator.isRight()) {
349 public List<Boolean> validateResourceNodeTemplateMetadata(ToscaDefinition toscaMainVfDefinition, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
350 reportStartTestPrint("validateResourceNodeTemplateMetadata", vnfFile);
351 Map<String, Map<String, String>> generateReosurceNodeTemplateMetadataToExpectedObject = generateResourceNodeTemplateMetadataToExpectedObject(resource);
352 Boolean resourceToscaMetadataValidator = ToscaValidation.resourceToscaNodeTemplateMetadataValidator(generateReosurceNodeTemplateMetadataToExpectedObject, toscaMainVfDefinition);
353 if (!resourceToscaMetadataValidator) {
359 //--------------------------Service--------------------------------
360 public List<Boolean> validateServiceMetadata(ToscaDefinition toscaMainServiceDefinition, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
361 reportStartTestPrint("validateServiceMetadata", vnfFile);
362 Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
363 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.serviceToscaMetadataValidator(generateServiceMetadataToExpectedObject, toscaMainServiceDefinition);
364 if (serviceToscaMetadataValidator.isRight()) {
371 public List<Boolean> validateServiceNodeTemplateMetadata(ToscaDefinition toscaMainServiceDefinition, ComponentInstance componentInstanceDefinition, ResourceReqDetails resourceReqDetails, Resource resource, String vnfFile, List<Boolean> status) throws Exception {
372 reportStartTestPrint("validateServiceNodeTemplateMetadata", vnfFile);
373 Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
374 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.componentToscaNodeTemplateMetadataValidator(generateServiceNodeTemplateMetadataToExpectedObject, toscaMainServiceDefinition, componentInstanceDefinition.getName(), ComponentTypeEnum.SERVICE, componentInstanceDefinition.getName());
375 if (serviceToscaMetadataValidator.isRight()) {
381 private List<Boolean> validateVfModuleJsonFile(Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject, Service service, String resInstUniqueId, String vnfFile, List<Boolean> status) throws Exception {
382 reportStartTestPrint("validateVfModuleJsonFile", vnfFile);
383 String artifactUniqueId = null;
384 for (ComponentInstance inst : service.getComponentInstances()) {
385 if (inst.getUniqueId().equals(resInstUniqueId)) {
386 artifactUniqueId = inst.getDeploymentArtifacts().get("vfModulesMetadata").getUniqueId();
390 if (artifactUniqueId == null) {
391 SetupCDTest.getExtendTest().log(Status.ERROR, "validateVfModuleJsonFile verification failed, artifact vfModulesMetadata not found");
395 RestResponse restResponse = ArtifactRestUtils.downloadResourceInstanceArtifact(service.getUniqueId(), resInstUniqueId, user, artifactUniqueId);
396 String artifactPayload = ArtifactRestUtils.getDecodedArtifactPayloadFromResponse(restResponse);
397 Map<String, VfModuleDefinition> actualVfModulesDefinitionObject = ResponseParser.convertVfModuleJsonResponseToJavaObject(artifactPayload);
398 Either<Boolean, Map<String, Object>> vfModuleJsonFileValidator = ToscaValidation.vfModuleJsonFileValidator(expectedVfModulesDefinitionObject, actualVfModulesDefinitionObject);
399 if (vfModuleJsonFileValidator.isRight()) {
405 //--------------------------Service verification against Pavel Parser--------------------------------
406 public List<Boolean> validateServiceMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ServiceReqDetails serviceReqDetails, Service service, String vnfFile, List<Boolean> status) throws Exception {
407 if (fdntCsarHelper == null) {
408 reportSkipTestPrint("validateServiceMetadataUsingParser", status);
410 reportStartTestPrint("validateServiceMetadataUsingParser", vnfFile);
411 Map<String, String> generateServiceMetadataToExpectedObject = generateServiceMetadataToExpectedObject(serviceReqDetails, service);
412 Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
413 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceMetadataToExpectedObject, serviceMetadata);
414 if (serviceToscaMetadataValidatorAgainstParser.isRight()) {
421 public List<Boolean> validateServiceNodeTemplateMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, ResourceReqDetails resourceReqDetails, Resource resource, ComponentInstance componentInstanceDefinition, String vnfFile, List<Boolean> status) throws Exception {
422 if (fdntCsarHelper == null) {
423 reportSkipTestPrint("validateServiceNodeTemplateMetadataUsingParser", status);
425 reportStartTestPrint("validateServiceNodeTemplateMetadataUsingParser", vnfFile);
426 Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject = generateServiceNodeTemplateMetadataToExpectedObject(resourceReqDetails, resource, componentInstanceDefinition);
427 List<NodeTemplate> serviceNodeTemplates = fdntCsarHelper.getServiceNodeTemplates();
428 Metadata serviceNodeTemplateMetadata = serviceNodeTemplates.get(0).getMetadata();
429 Either<Boolean, Map<String, Object>> serviceNodeTemplateToscaMetadataValidatorAgainstParser = ToscaValidation.serviceToscaMetadataValidatorAgainstParser(generateServiceNodeTemplateMetadataToExpectedObject, serviceNodeTemplateMetadata);
430 if (serviceNodeTemplateToscaMetadataValidatorAgainstParser.isRight()) {
437 //--------------------------Input verification--------------------------------
439 //--------------------------Resource--------------------------------
440 public List<Boolean> validateResourceInputs(ToscaDefinition toscaMainAmdocsDefinition, ToscaDefinition toscaMainVfDefinition, String vnfFile, List<Boolean> status) throws Exception {
441 reportStartTestPrint("validateResourceInputs", vnfFile);
442 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaMainAmdocsDefinition.getTopology_template().getInputs();
443 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainVfDefinition.getTopology_template().getInputs();
444 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
445 if (toscaInputsValidator.isRight()) {
451 //--------------------------Service--------------------------------
453 public List<Boolean> validateServiceInputs(ToscaDefinition toscaExpectedMainServiceDefinition, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
454 reportStartTestPrint("validateServiceInputs", vnfFile);
455 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
456 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = toscaMainServiceDefinition.getTopology_template().getInputs();
457 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidator(expectedInputsMap, actualInputsMap);
458 if (toscaInputsValidator.isRight()) {
464 public List<Boolean> validateServiceModuleMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
465 reportStartTestPrint("validateServiceModuleMetadata", vnfFile);
467 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
468 if (toscaServiceModuleMetadataValidator.isRight()) {
474 public List<Boolean> validateServiceModuleProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, ToscaDefinition toscaMainServiceDefinition, String vnfFile, List<Boolean> status) {
475 reportStartTestPrint("validateServiceModuleProperty", vnfFile);
477 Either<Boolean, Map<String, Object>> toscaServiceModulePropertyValidator = ToscaValidation.serviceToscaGroupPropertyValidator(expectedToscaServiceGroupsDefinitionObject, toscaMainServiceDefinition);
478 if (toscaServiceModulePropertyValidator.isRight()) {
484 //--------------------------Service verification against Pavel Parser--------------------------------
485 public List<Boolean> validateServiceInputsUsingParser(ISdcCsarHelper fdntCsarHelper, ToscaDefinition toscaExpectedMainServiceDefinition, String vnfFile, List<Boolean> status) throws Exception {
486 if (fdntCsarHelper == null) {
487 reportSkipTestPrint("validateServiceInputsUsingParser", status);
489 reportStartTestPrint("validateServiceInputsUsingParser", vnfFile);
490 Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap = toscaExpectedMainServiceDefinition.getTopology_template().getInputs();
491 Either<Boolean, Map<String, Object>> toscaInputsValidator = ToscaValidation.toscaInputsValidatorAgainstParser(expectedInputsMap, fdntCsarHelper);
492 if (toscaInputsValidator.isRight()) {
499 public List<Boolean> validateServiceModuleMetadataUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
500 reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
501 String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetadata().getValue("customizationUUID");
502 List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
503 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupMetadataValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
504 if (toscaServiceModuleMetadataValidator.isRight()) {
510 public List<Boolean> validateServiceModulePropertyUsingParser(ISdcCsarHelper fdntCsarHelper, Map<String, ToscaGroupsTopologyTemplateDefinition> expectedToscaServiceGroupsDefinitionObject, String vnfFile, List<Boolean> status) {
511 reportStartTestPrint("validateServiceModuleMetadataUsingParser", vnfFile);
512 String customizationUUID = fdntCsarHelper.getServiceNodeTemplates().get(0).getMetadata().getValue("customizationUUID");
513 List<Group> actualGroups = fdntCsarHelper.getVfModulesByVf(customizationUUID);
514 Either<Boolean, Map<String, Object>> toscaServiceModuleMetadataValidator = ToscaValidation.serviceToscaGroupPropertyValidatorUsingParser(expectedToscaServiceGroupsDefinitionObject, actualGroups);
515 if (toscaServiceModuleMetadataValidator.isRight()) {
521 private Map<String, ToscaGroupsTopologyTemplateDefinition> createExpectedToscaServiceGroupsDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
522 Map<String, ToscaGroupsTopologyTemplateDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
524 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
525 if (!moduleType.getTypeName().equals("artifacts")) {
526 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
527 ToscaGroupsTopologyTemplateDefinition toscaGroupsTopologyTemplateDefinition = new ToscaGroupsTopologyTemplateDefinition();
528 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
529 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
530 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
531 String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
532 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
533 toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
534 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
535 toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
536 toscaGroupsTopologyTemplateDefinitionMap.put(serviceModuleName, toscaGroupsTopologyTemplateDefinition);
538 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
543 return toscaGroupsTopologyTemplateDefinitionMap;
548 private Map<String, VfModuleDefinition> createExpectedVfModuleDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
549 Map<String, VfModuleDefinition> toscaGroupsTopologyTemplateDefinitionMap = new HashMap<>();
551 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
552 if (!moduleType.getTypeName().equals("artifacts")) {
553 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
554 VfModuleDefinition toscaGroupsTopologyTemplateDefinition = new VfModuleDefinition();
555 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
556 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
557 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
558 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, resourceModuleName, service);
559 toscaGroupsTopologyTemplateDefinition.setMetadata(toscaServiceGroupsMetadataDefinition);
560 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = setGroupProperty(module);
561 toscaGroupsTopologyTemplateDefinition.setProperties(toscaGroupPropertyDefinition);
562 toscaGroupsTopologyTemplateDefinition.setArtifacts(getArtifactsUuidListForRI(module, resource, service));
563 toscaGroupsTopologyTemplateDefinitionMap.put(toscaServiceGroupsMetadataDefinition.vfModuleModelName, toscaGroupsTopologyTemplateDefinition);
566 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
571 return toscaGroupsTopologyTemplateDefinitionMap;
575 private List<String> getArtifactsUuidListForRI(GroupHeatMetaDefinition module, Resource resource, Service service) {
576 //TODO check if each heat include its env file
577 List<String> artifactsUuidList = new ArrayList<>();
578 ComponentInstance resourceInstance = null;
579 for (ComponentInstance componentInstance : service.getComponentInstances()) {
580 if (componentInstance.getUniqueId().contains(resource.getUniqueId())) {
581 resourceInstance = componentInstance;
586 Collection<ArtifactDefinition> artifactsDefinitionValues = resourceInstance.getDeploymentArtifacts().values();
588 for (HeatMetaFirstLevelDefinition moduleArtifactDefinition : module.getArtifactList()) {
589 for (ArtifactDefinition riArtifactDefinition : artifactsDefinitionValues) {
590 String heatYamlName = moduleArtifactDefinition.getFileName();
591 String heatEnvName = heatYamlName.replaceAll("yaml|yml", "env");
592 String riArtifactName = riArtifactDefinition.getArtifactName();
593 if (riArtifactName.equals(heatYamlName) || riArtifactName.equals(heatEnvName)) {
594 artifactsUuidList.add(riArtifactDefinition.getArtifactUUID());
599 return artifactsUuidList;
602 private ToscaGroupPropertyDefinition setGroupProperty(GroupHeatMetaDefinition module) {
603 ToscaGroupPropertyDefinition toscaGroupPropertyDefinition = new ToscaGroupPropertyDefinition();
604 toscaGroupPropertyDefinition.setVf_module_label(module.getGroupName());
605 Boolean isBase = module.getPropertyHeatMetaDefinition().getValue();
607 toscaGroupPropertyDefinition.setInitial_count("1");
608 toscaGroupPropertyDefinition.setMin_vf_module_instances("1");
609 toscaGroupPropertyDefinition.setMax_vf_module_instances("1");
610 toscaGroupPropertyDefinition.setVf_module_type("Base");
612 toscaGroupPropertyDefinition.setInitial_count("0");
613 toscaGroupPropertyDefinition.setMin_vf_module_instances("0");
614 toscaGroupPropertyDefinition.setMax_vf_module_instances("");
615 toscaGroupPropertyDefinition.setVf_module_type("Expansion");
617 toscaGroupPropertyDefinition.setAvailability_zone_count("");
618 toscaGroupPropertyDefinition.setVfc_list("");
619 toscaGroupPropertyDefinition.setVf_module_description("");
620 toscaGroupPropertyDefinition.setVolume_group(isVolumeGroup(module));
622 return toscaGroupPropertyDefinition;
625 private String isVolumeGroup(GroupHeatMetaDefinition module) {
626 String isVolumeGroup = "false";
627 for (HeatMetaFirstLevelDefinition artifactList : module.getArtifactList()) {
628 if (artifactList.getType().equals(ArtifactTypeEnum.HEAT_VOL.getType())) {
629 isVolumeGroup = "true";
630 return isVolumeGroup;
633 return isVolumeGroup;
636 private Map<String, ToscaServiceGroupsMetadataDefinition> createExpectedToscaServiceGroupsPropertyDefinitionObject(Resource resource, Service service, List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition) {
638 Map<String, ToscaServiceGroupsMetadataDefinition> toscaServiceGroupsMetadataDefinitionMap = new HashMap<>();
639 for (TypeHeatMetaDefinition moduleType : listTypeHeatMetaDefinition) {
640 Map<String, String> groupProperty = new HashMap<>();
642 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
643 for (GroupHeatMetaDefinition module : moduleType.getGroupHeatMetaDefinition()) {
644 String resourceModuleName = buildResourceModuleName(resource, module.getGroupName());
645 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromResourceObject(resourceModuleName, resource);
646 if (!toscaServiceGroupsMetadataDefinition.equals("")) {
647 String serviceModuleName = buildServiceModuleName(service.getComponentInstances().get(0).getNormalizedName(), toscaServiceGroupsMetadataDefinition.getVfModuleModelName());
648 toscaServiceGroupsMetadataDefinition = setGroupMetadataFromServiceObject(toscaServiceGroupsMetadataDefinition, serviceModuleName, service);
649 toscaServiceGroupsMetadataDefinitionMap.put(serviceModuleName, toscaServiceGroupsMetadataDefinition);
651 getExtendTest().log(Status.FAIL, "module name [" + module.getGroupName() + "] didn't represent in resource");
655 return toscaServiceGroupsMetadataDefinitionMap;
659 private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromServiceObject(ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition, String serviceModuleName, Service service) {
660 for (GroupInstance groupInstance : service.getComponentInstances().get(0).getGroupInstances()) {
661 if (groupInstance.getName().contains(serviceModuleName)) {
662 toscaServiceGroupsMetadataDefinition.setVfModuleModelCustomizationUUID(groupInstance.getCustomizationUUID());
663 return toscaServiceGroupsMetadataDefinition;
666 return toscaServiceGroupsMetadataDefinition;
669 private ToscaServiceGroupsMetadataDefinition setGroupMetadataFromResourceObject(String resourceModuleName, Resource resource) {
670 ToscaServiceGroupsMetadataDefinition toscaServiceGroupsMetadataDefinition = new ToscaServiceGroupsMetadataDefinition();
671 for (GroupDefinition group : resource.getGroups()) {
672 if (group.getName().contains(resourceModuleName)) {
673 toscaServiceGroupsMetadataDefinition.setVfModuleModelName(group.getName());
674 toscaServiceGroupsMetadataDefinition.setVfModuleModelInvariantUUID(group.getInvariantUUID());
675 toscaServiceGroupsMetadataDefinition.setVfModuleModelUUID(group.getGroupUUID());
676 toscaServiceGroupsMetadataDefinition.setVfModuleModelVersion(group.getVersion());
677 return toscaServiceGroupsMetadataDefinition;
680 return toscaServiceGroupsMetadataDefinition;
683 public static String buildResourceModuleName(Resource resource, String groupName) {
684 return resource.getSystemName() + ".." + groupName + ".." + "module-";
687 public static String buildServiceModuleName(String resourceInstanceNormalizedName, String resourceGroupName) {
688 return resourceInstanceNormalizedName + ".." + resourceGroupName;
691 public static ToscaDefinition addGenericInputsToToscaObject(ToscaDefinition toscaDefinition, String genericName) throws Exception {
692 Resource genericResource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, genericName, "1.0");
693 ToscaTopologyTemplateDefinition topologyTemplate = toscaDefinition.getTopology_template();
694 Map<String, ToscaInputsTopologyTemplateDefinition> newInput = new HashMap<>();
695 for (PropertyDefinition property : genericResource.getProperties()) {
696 ToscaInputsTopologyTemplateDefinition input = new ToscaInputsTopologyTemplateDefinition();
697 // input.setConstraints(property.getConstraints());
698 input.setDefault(property.getDefaultValue());
699 input.setDescription(property.getDescription());
700 // input.setEntry_schema(property.getSchema());
701 input.setName(property.getName());
702 // input.setRequired(property.get);
703 input.setStatus(property.getStatus());
704 input.setType(property.getType());
705 input.setValue(property.getValue());
706 newInput.put(property.getName(), input);
709 topologyTemplate.addInputs(newInput);
710 toscaDefinition.setTopology_template(topologyTemplate);
711 return toscaDefinition;
714 public static ToscaDefinition setNameToToscaInput(ToscaDefinition toscaDefinition) {
715 Map<String, ToscaInputsTopologyTemplateDefinition> inputs = toscaDefinition.getTopology_template().getInputs();
716 for (String name : inputs.keySet()) {
717 inputs.get(name).setName(name);
719 toscaDefinition.getTopology_template().setInputs(inputs);
720 return toscaDefinition;
723 public static ToscaDefinition addAndGenerateResourceMetadataToExpectedObject(ToscaDefinition toscaDefinition, ResourceReqDetails resourceReqDetails, Component component) {
725 Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
726 toscaDefinition.setMetadata(metadata);
727 return toscaDefinition;
730 public static Map<String, String> convertResourceMetadataToMap(ResourceReqDetails resourceReqDetails, Component component) {
731 Map<String, String> metadata = new HashMap<>();
733 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resourceReqDetails.getCategories().get(0).getName());
734 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resourceReqDetails.getDescription());
735 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
736 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resourceReqDetails.getResourceType());
737 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
738 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
740 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resourceReqDetails.getVendorName());
741 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resourceReqDetails.getResourceVendorModelNumber());
742 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resourceReqDetails.getVendorRelease());
743 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resourceReqDetails.getCategories().get(0).getSubcategories().get(0).getName());
747 public static Map<String, String> convertResourceNodeTemplateMetadataToMap(ComponentInstance componentInstance) throws Exception {
749 Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
750 Map<String, String> metadata = new HashMap<>();
752 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, resource.getCategories().get(0).getName());
753 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, resource.getDescription());
754 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, resource.getInvariantUUID());
755 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, resource.getResourceType().toString());
756 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, resource.getUUID());
757 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, resource.getName());
759 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_NAME.value, resource.getVendorName());
760 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_MODEL_NUMBER.value, resource.getResourceVendorModelNumber());
761 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.RESOURCE_VENDOR_RELEASE.value, resource.getVendorRelease());
762 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SUBCATEGORY.value, resource.getCategories().get(0).getSubcategories().get(0).getName());
763 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstance.getCustomizationUUID());
764 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstance.getComponentVersion());
769 public static Map<String, String> generateServiceNodeTemplateMetadataToExpectedObject(ResourceReqDetails resourceReqDetails, Component component, ComponentInstance componentInstanceDefinition) {
771 Map<String, String> metadata = convertResourceMetadataToMap(resourceReqDetails, component);
772 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CUSTOMIZATION_UUID.value, componentInstanceDefinition.getCustomizationUUID());
773 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.VERSION.value, componentInstanceDefinition.getComponentVersion());
778 public static Map<String, Map<String, String>> generateResourceNodeTemplateMetadataToExpectedObject(Component component) throws Exception {
780 Map<String, Map<String, String>> resourcesNodeTemplateMetadataMap = new HashMap<>();
781 if (component.getComponentInstances() != null && !component.getComponentInstances().isEmpty()) {
782 for (ComponentInstance componentInstance : component.getComponentInstances()) {
783 Map<String, String> metadata = convertResourceNodeTemplateMetadataToMap(componentInstance);
784 resourcesNodeTemplateMetadataMap.put(componentInstance.getName(), metadata);
787 return resourcesNodeTemplateMetadataMap;
790 public static Map<String, String> generateServiceMetadataToExpectedObject(ServiceReqDetails serviceReqDetails, Component component) {
792 Map<String, String> metadata = new HashMap<>();
794 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.CATEGORY.value, serviceReqDetails.getCategories().get(0).getName());
795 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.DESCRIPTION.value, serviceReqDetails.getDescription());
796 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.INVARIANT_UUID.value, component.getInvariantUUID());
797 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.TYPE.value, "Service");
798 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.UUID.value, component.getUUID());
799 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAME.value, component.getName());
801 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_TYPE.value, serviceReqDetails.getServiceType());
802 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ROLE.value, serviceReqDetails.getServiceRole());
803 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.NAMING_POLICY.value, serviceReqDetails.getNamingPolicy());
804 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.ECOMP_GENERATED_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());
805 metadata.put(ToscaMetadataFieldsPresentationEnum.ToscaMetadataFieldsEnum.SERVICE_ECOMP_NAMING.value, serviceReqDetails.getEcompGeneratedNaming().toString());//equals to ECOMP_GENERATED_NAMING
810 public static void reportStartTestPrint(String testName, String vnfFile) {
811 // reportMessageInColor("info", "blue", "Running test \" + testName + \" with zip file - \" + vnfFile");
812 SetupCDTest.getExtendTest().log(Status.INFO, "<html><font color=\"blue\"> Running test " + testName + " with zip file - " + vnfFile + "</font></html>");
815 public static void reportSkipTestPrint(String testName, List<Boolean> status) {
816 // reportMessageInColor("error", "orange", "Skip test \" + testName + \" due to previous tosca parser error");
817 SetupCDTest.getExtendTest().log(Status.ERROR, "<html><font color=\"orange\"> Skip test " + testName + " due to previous tosca parser error" + "</font></html>");
821 public static void reportMessageInColor(String status, String color, String message) {
822 String printLine = getReportMessageInColor(color, message);
823 SetupCDTest.getExtendTest().log(Status.valueOf(status), printLine);
824 // SetupCDTest.getExtendTest().log(Status.valueOf(status), getReportMessageInColor(color, message));
828 * @param color = red, green, orange, blue ...
829 * @param message - message string
830 * @return string in desired color
832 public static String getReportMessageInColor(String color, String message) {
833 String returnValue = ("<html><font color=\\\"+color+\"\">" + message + "</font></html>").toString();
838 public void printTest(){
839 System.out.println("print");
840 reportMessageInColor("ERROR", "green", "green");
841 reportMessageInColor("INFO", "orange", "orange");
842 reportMessageInColor("INFO", "red", "red");
846 public void allottedResourceModelTest() throws Exception{
847 List<Boolean> status = new ArrayList<>();
849 List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
850 List<String> newRandomFileNamesFromFolder = OnbordingDataProviders.getRandomElements(1, fileNamesFromFolder);
851 String vnfFile = newRandomFileNamesFromFolder.get(0);
853 String filePath = FileHandling.getVnfRepositoryPath();
854 File filesFolder = new File(SetupCDTest.getWindowTest().getDownloadDirectory());
856 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(ResourceCategoryEnum.ALLOTTED_RESOURCE_SERVICE_ADMIN);
857 resourceReqDetails = createCustomizedVsp(resourceReqDetails, filePath, vnfFile);
859 ToscaDefinition toscaMainAmdocsDefinition = downloadAndGetToscaMainYamlObjectUI(resourceReqDetails, filesFolder);
860 toscaMainAmdocsDefinition = addGenericPropertiesToToscaDefinitionObject(toscaMainAmdocsDefinition, GENERIC_VF);
862 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
863 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
865 ToscaDefinition toscaMainVfDefinition = downloadAndGetToscaMainYamlObjectApi(resource, filesFolder);
867 status = validateVfMetadata(toscaMainAmdocsDefinition, toscaMainVfDefinition, resourceReqDetails, resource, vnfFile, status);
868 status = validateResourceNodeTemplateMetadata(toscaMainVfDefinition, resource, vnfFile, status);
869 status = validateResourceInputs(toscaMainAmdocsDefinition, toscaMainVfDefinition, vnfFile, status);
871 if(status.contains(false)){
872 SetupCDTest.getExtendTest().log(Status.FAIL, "Summary: allottedResourceModelTest tosca validation test failed with zip file " + vnfFile);
873 Assert.assertFalse(true);
878 // help method to toscaValidation tests
879 private ISdcCsarHelper initSdcCsarHelper(File serviceCsarFileName, File filesFolder) {
881 ISdcCsarHelper fdntCsarHelper;
883 SetupCDTest.getExtendTest().log(Status.INFO, "Tosca parser is going to convert service csar file to ISdcCsarHelper object...");
884 fdntCsarHelper = factory.getSdcCsarHelper(filesFolder.getPath() + serviceCsarFileName);
885 } catch (Exception e) {
886 SetupCDTest.getExtendTest().log(Status.ERROR, "Tosca parser FAILED to convert service csar file to ISdcCsarHelper object...");
887 SetupCDTest.getExtendTest().log(Status.FAIL, e);
888 fdntCsarHelper = null;
890 return fdntCsarHelper;
895 * @param resourceReqDetails to create Vsp
896 * @return updated resourceReqDetails after Vsp was created
898 private ResourceReqDetails createCustomizedVsp(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
899 VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, filePath, vnfFile, user);
900 resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
901 return resourceReqDetails;
905 * @param resourceReqDetails to download csar file via UI
906 * @return Tosca definition object from main yaml file
908 private ToscaDefinition downloadAndGetToscaMainYamlObjectUI(ResourceReqDetails resourceReqDetails, File filesFolder) throws Exception {
909 DownloadManager.downloadCsarByNameFromVSPRepository(resourceReqDetails.getName(), false);
910 File amdocsCsarFileName = FileHandling.getLastModifiedFileNameFromDir(filesFolder.getAbsolutePath());
911 return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(amdocsCsarFileName);
915 * @param toscaMainAmdocsDefinition object to add generic properties
916 * @param genericName resource name
917 * @return updated toscaMainAmdocsDefinition object
919 private ToscaDefinition addGenericPropertiesToToscaDefinitionObject(ToscaDefinition toscaMainAmdocsDefinition, String genericName) throws Exception {
920 toscaMainAmdocsDefinition = setNameToToscaInput(toscaMainAmdocsDefinition);
921 toscaMainAmdocsDefinition = addGenericInputsToToscaObject(toscaMainAmdocsDefinition, genericName);
922 return toscaMainAmdocsDefinition;
926 * @param resource to download csar file via API
927 * @return Tosca definition object from main yaml file
929 private ToscaDefinition downloadAndGetToscaMainYamlObjectApi(Resource resource, File filesFolder) throws Exception {
930 File vfCsarFileName = new File(File.separator + "VfCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
931 OnboardingUtillViaApis.downloadToscaCsarToDirectory(resource, new File(filesFolder.getPath() + vfCsarFileName));
932 return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + vfCsarFileName));