aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java')
-rw-r--r--asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java544
1 files changed, 448 insertions, 96 deletions
diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
index e4360329ad..192f6759c3 100644
--- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
+++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
@@ -31,130 +31,306 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
import java.util.Optional;
import org.apache.commons.codec.binary.Base64;
import org.junit.Rule;
import org.junit.rules.TestName;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.InputsRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.BaseValidationUtils;
import org.openecomp.sdc.common.api.Constants;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.Yaml;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
public class ExportToscaTest extends ComponentBaseTest {
@Rule
public static TestName name = new TestName();
+ String rootPath = System.getProperty("user.dir");
+ private static final String CSARS_PATH = "/src/test/resources/CI/csars/";
+ public static String userDefinedNodeYaml = "CustomVL.yml";
public ExportToscaTest() {
super(name, ExportToscaTest.class.getName());
}
- @Test(enabled = true)
- public void exportVfModuleTest() throws Exception {
+ @DataProvider(name = "vfModuleCsar")
+ public static Object[][] csarNames() {
+ return new Object[][] { { "VSPPackage", true }, { "csar_1", true }, { "noArtifact", false }, {"noVfModule", false} };
+// return new Object[][] { { "VSPPackage", true }, { "csar_1", true }, { "noArtifact", false } };
+ }
+
+ @Test(dataProvider = "vfModuleCsar")
+ public void exportVfModuleTest(String csarname, boolean includeGroups) throws Exception {
+ System.out.println("run for csar " + csarname);
User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
- Resource createdResource = createVfFromCSAR(sdncModifierDetails, "VSPPackage");
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, csarname);
- Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ validateGroupsInResource(sdncModifierDetails, createdResource, includeGroups);
+ }
+
+ @Test(dataProvider = "vfModuleCsar")
+ public void exportVfModuleInstanceTest(String csarname, boolean includeGroups) throws Exception {
+ System.out.println("run for csar " + csarname);
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ // create resource
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, csarname);
+
+ // change state to check in
+ RestResponse checkinState = LifecycleRestUtils.changeComponentState(createdResource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ BaseRestUtils.checkSuccess(checkinState);
+ ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
+
+ // 2 create service
+ RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
+ ResourceRestUtils.checkCreateResponse(createServiceResponse);
+ Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
+
+ // 3 create vf instance in service
+ ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(createdResource);
+ RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
+ ResourceRestUtils.checkCreateResponse(createComponentInstance);
+
+ RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
+ BaseRestUtils.checkSuccess(getService);
+ service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
+
+ List<GroupDefinition> groupsInResource = createdResource.getGroups();
+ int vfModuleCount = 0;
+ List<GroupDefinition> vfModulesInRes = groupsInResource.stream().filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)).collect(Collectors.toList());
+
+ ComponentInstance componentInstance = service.getComponentInstances().get(0);
+ String normalizedName = componentInstance.getNormalizedName();
+
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, service);
assertNotNull(load);
Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
assertNotNull(topology_template);
Map<String, Object> groups = (Map<String, Object>) topology_template.get("groups");
- assertNotNull(groups);
- List<GroupDefinition> groupsOrigin = createdResource.getGroups();
+ if (includeGroups) {
+ assertNotNull(vfModulesInRes);
+ assertNotNull(groups);
- assertEquals("Validate groups size", groupsOrigin.size(), groups.size());
- for (GroupDefinition group : groupsOrigin) {
- Map<String, Object> groupTosca = (Map<String, Object>) groups.get(group.getName());
- assertNotNull(groupTosca);
+ assertEquals("Validate count of vf module instanses", vfModulesInRes.size(), groups.size());
- Map<String, Object> metadata = (Map<String, Object>) groupTosca.get("metadata");
- assertNotNull(metadata);
+ vfModulesInRes.forEach(modInRes -> {
+ validateVfModuleVsInstance(normalizedName, groups, modInRes);
+ });
+ }else{
+ assertNull(groups);
+ }
+ }
- String invariantUUID;
- String name;
- String UUID;
- String version;
- Map<String, Object> properties = (Map<String, Object>) groupTosca.get("properties");
-
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- invariantUUID = (String) metadata.get("vfModuleModelInvariantUUID");
- name = (String) metadata.get("vfModuleModelName");
- UUID = (String) metadata.get("vfModuleModelUUID");
- version = (String) metadata.get("vfModuleModelVersion");
- assertNotNull(properties);
-
- String vf_module_type = (String) properties.get("vf_module_type");
- List<GroupProperty> props = group.getProperties();
- for (GroupProperty prop : props) {
- if (prop.getName().equals(Constants.IS_BASE)) {
- String value = prop.getValue() == null ? prop.getDefaultValue() : prop.getValue();
- boolean bvalue = Boolean.parseBoolean(value);
- if (bvalue) {
- assertEquals("Validate vf_module_type", "Base", vf_module_type);
- } else {
- assertEquals("Validate vf_module_type", "Expansion", vf_module_type);
- }
- break;
- }
+ private void validateVfModuleVsInstance(String normalizedName, Map<String, Object> groups, GroupDefinition modInRes) {
+ String instName = normalizedName + ".." + modInRes.getName();
+ Map<String, Object> group = (Map<String, Object>) groups.get(instName);
+ assertNotNull(group);
+
+ String type = (String) group.get("type");
+ assertNotNull(type);
+ assertEquals("Validate group instance type", modInRes.getType(), type);
+
+ Map<String, Object> metadata = (Map<String, Object>) group.get("metadata");
+ assertNotNull(metadata);
+
+ String invariantUUID = (String) metadata.get("vfModuleModelInvariantUUID");
+ String name = (String) metadata.get("vfModuleModelName");
+ String UUID = (String) metadata.get("vfModuleModelUUID");
+ String version = (String) metadata.get("vfModuleModelVersion");
+
+ String customizationUUID = (String) metadata.get("vfModuleModelCustomizationUUID");
+ assertNotNull("Validate group instance customizationUUID", customizationUUID);
+
+ assertEquals("Validate group instance InvariantUUID", modInRes.getInvariantUUID(), invariantUUID);
+ assertEquals("Validate group instance name", modInRes.getName(), name);
+ assertEquals("Validate group instance UUID", modInRes.getGroupUUID(), UUID);
+ assertEquals("Validate group instance version", modInRes.getVersion(), version);
+
+ Map<String, Object> propertiesInInst = (Map<String, Object>) group.get("properties");
+ assertNotNull(propertiesInInst);
+
+ List<GroupProperty> propertiesInGroup = modInRes.convertToGroupProperties();
+ // property isBase not exist in tosca
+ assertEquals("Validate group instance properties size", propertiesInGroup.size() - 1, propertiesInInst.size());
+ propertiesInGroup.forEach(propInGroup -> {
+ String propName = propInGroup.getName();
+ if (!propName.equals("isBase")) {
+ Object propValue = propertiesInInst.get(propName);
+ String valueInGroup = propInGroup.getValue();
+ if (valueInGroup != null && !valueInGroup.isEmpty()) {
+ assertNotNull(propValue);
+ assertEquals("Validate group instance property value for " + propName, valueInGroup, propValue.toString());
+ } else {
+ assertNull(propValue);
}
- String vf_module_description = (String) properties.get("vf_module_description");
- assertEquals("Validate vf_module_description", group.getDescription(), vf_module_description);
-
- Boolean volume_group = (Boolean) properties.get("volume_group");
- boolean isVolume = false;
- List<String> artifactsList = group.getArtifacts();
- List<ArtifactDefinition> artifacts = new ArrayList<>();
- if (artifactsList != null && !artifactsList.isEmpty()) {
- ArtifactDefinition masterArtifact = findMasterArtifact(createdResource.getDeploymentArtifacts(),
- artifacts, artifactsList);
- if (masterArtifact.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
- isVolume = true;
- }
+ }
+ });
+ }
+
+ private void validateGroupsInResource(User sdncModifierDetails, Resource createdResource, boolean includeGroups) throws Exception {
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ assertNotNull(load);
+ Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
+ assertNotNull(topology_template);
+ Map<String, Object> groups = (Map<String, Object>) topology_template.get("groups");
+ if (includeGroups) {
+ assertNotNull(groups);
+ List<GroupDefinition> groupsOrigin = createdResource.getGroups();
+
+ assertEquals("Validate groups size", groupsOrigin.size(), groups.size());
+ for (GroupDefinition group : groupsOrigin) {
+ Map<String, Object> groupTosca = (Map<String, Object>) groups.get(group.getName());
+ assertNotNull(groupTosca);
+
+ Map<String, Object> metadata = (Map<String, Object>) groupTosca.get("metadata");
+ assertNotNull(metadata);
+
+ String invariantUUID;
+ String name;
+ String UUID;
+ String version;
+ Map<String, Object> properties = (Map<String, Object>) groupTosca.get("properties");
+
+ if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ invariantUUID = (String) metadata.get("vfModuleModelInvariantUUID");
+ name = (String) metadata.get("vfModuleModelName");
+ UUID = (String) metadata.get("vfModuleModelUUID");
+ version = (String) metadata.get("vfModuleModelVersion");
+ assertNotNull(properties);
+
+ validateVfModuleProperties(createdResource, group, properties);
+ } else {
+ invariantUUID = (String) metadata.get("invariantUUID");
+ name = (String) metadata.get("name");
+ UUID = (String) metadata.get("UUID");
+ version = (String) metadata.get("version");
+ assertNull(properties);
+
}
- assertEquals("Validate volume_group", isVolume, volume_group);
+ assertEquals("Validate InvariantUUID", group.getInvariantUUID(), invariantUUID);
+ assertEquals("Validate name", group.getName(), name);
+ assertEquals("Validate UUID", group.getGroupUUID(), UUID);
+ assertEquals("Validate version", group.getVersion(), version);
+ }
+ } else {
+ assertEquals(null, groups);
+ }
+ }
+
+ private void validateVfModuleProperties(Resource createdResource, GroupDefinition group, Map<String, Object> properties) {
+ // vf_module_type
+ String vf_module_type = (String) properties.get("vf_module_type");
+ List<GroupProperty> props = group.convertToGroupProperties();
- } else {
- invariantUUID = (String) metadata.get("invariantUUID");
- name = (String) metadata.get("name");
- UUID = (String) metadata.get("UUID");
- version = (String) metadata.get("version");
- assertNull(properties);
+ GroupProperty isBaseProp = getGroupPropertyByName(group, Constants.IS_BASE);
+ assertNotNull(isBaseProp);
+ String value = isBaseProp.getValue() == null ? isBaseProp.getDefaultValue() : isBaseProp.getValue();
+ boolean bvalue = Boolean.parseBoolean(value);
+ if (bvalue) {
+ assertEquals("Validate vf_module_type", "Base", vf_module_type);
+ } else {
+ assertEquals("Validate vf_module_type", "Expansion", vf_module_type);
+ }
+
+ // vf_module_description
+ String vf_module_description = (String) properties.get("vf_module_description");
+ assertEquals("Validate vf_module_description", group.getDescription(), vf_module_description);
+
+ // volume_group
+ Boolean volume_group = (Boolean) properties.get("volume_group");
+ boolean isVolume = false;
+ List<String> artifactsList = group.getArtifacts();
+ List<ArtifactDefinition> artifacts = new ArrayList<>();
+ if (artifactsList != null && !artifactsList.isEmpty()) {
+ ArtifactDefinition masterArtifact = findMasterArtifact(createdResource.getDeploymentArtifacts(), artifacts, artifactsList);
+ if (masterArtifact.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ isVolume = true;
}
- assertEquals("Validate InvariantUUID", group.getInvariantUUID(), invariantUUID);
- assertEquals("Validate name", group.getName(), name);
- assertEquals("Validate UUID", group.getGroupUUID(), UUID);
- assertEquals("Validate version", group.getVersion(), version);
+ }
+ assertEquals("Validate volume_group", isVolume, volume_group);
+
+ // min_vf_module_instances
+ Integer min_vf_module_instances = (Integer) properties.get("min_vf_module_instances");
+ GroupProperty minInstProp = getGroupPropertyByName(group, "min_vf_module_instances");
+ assertNotNull(minInstProp);
+ assertEquals("Validate min_vf_module_instances", minInstProp.getValue(), min_vf_module_instances.toString());
+
+ // vf_module_label
+ String vf_module_label = (String) properties.get("vf_module_label");
+ GroupProperty labelProp = getGroupPropertyByName(group, "vf_module_label");
+ assertNotNull(labelProp);
+ assertEquals("Validate vf_module_label", labelProp.getValue(), vf_module_label);
+
+ // vf_module_label
+ Integer initial_count = (Integer) properties.get("initial_count");
+ GroupProperty initCountProp = getGroupPropertyByName(group, "initial_count");
+ assertNotNull(initCountProp);
+ assertEquals("Validate initial_count", initCountProp.getValue(), initial_count.toString());
+
+ // max_vf_module_instances
+ Integer max_vf_module_instances = (Integer) properties.get("max_vf_module_instances");
+ GroupProperty maxInstProp = getGroupPropertyByName(group, "max_vf_module_instances");
+ assertNotNull(maxInstProp);
+ if (max_vf_module_instances != null) {
+ assertEquals("Validate max_vf_module_instances", maxInstProp.getValue(), max_vf_module_instances.toString());
+ } else {
+ assertEquals("Validate max_vf_module_instances", maxInstProp.getValue(), max_vf_module_instances);
+ }
+ }
+ private GroupProperty getGroupPropertyByName(GroupDefinition group, String name) {
+ List<GroupProperty> props = group.convertToGroupProperties();
+ for (GroupProperty prop : props) {
+ if (prop.getName().equals(name)) {
+ return prop;
+ }
}
+ return null;
}
@Test(enabled = true)
@@ -179,8 +355,7 @@ public class ExportToscaTest extends ComponentBaseTest {
validateInput(inputDef, inputInFile);
}
List<ComponentInstance> componentInstances = createdResource.getComponentInstances();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = createdResource
- .getComponentInstancesProperties();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = createdResource.getComponentInstancesProperties();
Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates");
assertNotNull(node_templates);
@@ -188,8 +363,7 @@ public class ExportToscaTest extends ComponentBaseTest {
for (Map.Entry<String, List<ComponentInstanceProperty>> entry : componentInstancesProperties.entrySet()) {
- Optional<ComponentInstance> findFirst = componentInstances.stream()
- .filter(ci -> ci.getUniqueId().equals(entry.getKey())).findFirst();
+ Optional<ComponentInstance> findFirst = componentInstances.stream().filter(ci -> ci.getUniqueId().equals(entry.getKey())).findFirst();
assertTrue(findFirst.isPresent());
String resourceName = findFirst.get().getName();
Map<String, Object> instance = (Map<String, Object>) node_templates.get(resourceName);
@@ -234,10 +408,8 @@ public class ExportToscaTest extends ComponentBaseTest {
RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
BaseRestUtils.checkCreateResponse(createResource);
Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
- ComponentInstance pmaaServer = resource.getComponentInstances().stream()
- .filter(p -> p.getName().equals("pmaa_server_0")).findAny().get();
- ComponentInstanceProperty jsonProp = resource.getComponentInstancesProperties().get(pmaaServer.getUniqueId())
- .stream().filter(p -> p.getType().equals(ToscaPropertyType.JSON.getType())).findAny().get();
+ ComponentInstance pmaaServer = resource.getComponentInstances().stream().filter(p -> p.getName().equals("pmaa_server_0")).findAny().get();
+ ComponentInstanceProperty jsonProp = resource.getComponentInstancesProperties().get(pmaaServer.getUniqueId()).stream().filter(p -> p.getType().equals(ToscaPropertyType.JSON.getType())).findAny().get();
String jsonValue = "{\"pmaa.sb_nic\":{\"address\":{\"get_input\":\"pmaa_dpu_fixed_ip\"},\"cidr\":{\"get_input\":\"pmaa_dpu_cidr\"},\"gateway\":{\"get_input\":\"pmaa_dpu_gateway\"}}}";
assertEquals(jsonProp.getValue(), jsonValue);
// download and compare
@@ -258,6 +430,187 @@ public class ExportToscaTest extends ComponentBaseTest {
assertEquals(json, jsonValue);
}
+ @Test(enabled = true)
+ public void exportServiceInputValue() throws Exception {
+ // 1 create vf as certified
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csar_1");
+ RestResponse checkinState = LifecycleRestUtils.changeComponentState(createdResource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ BaseRestUtils.checkSuccess(checkinState);
+ ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
+
+ // 2 create service
+ RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
+ ResourceRestUtils.checkCreateResponse(createServiceResponse);
+ Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
+
+ // 3 create vf instance in service
+ ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(createdResource);
+ RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
+ ResourceRestUtils.checkCreateResponse(createComponentInstance);
+
+ RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
+ BaseRestUtils.checkSuccess(getService);
+ service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
+
+ // 4 download tosca template
+ Map<String, Object> tosca = downloadAndParseToscaTemplate(sdncModifierDetails, service);
+ assertNotNull(tosca);
+ Map<String, Object> topology_template = (Map<String, Object>) tosca.get("topology_template");
+ assertNotNull(topology_template);
+
+ // 5 validate no inputs in service
+ Map<String, Object> inputs = (Map<String, Object>) tosca.get("inputs");
+ assertNull(inputs);
+
+ List<ComponentInstance> componentInstances = service.getComponentInstances();
+ assertNotNull(componentInstances);
+ assertEquals(1, componentInstances.size());
+ ComponentInstance vfi = componentInstances.get(0);
+
+ // 6 add instance inputs in service
+ RestResponse getComponentInstanceInputsResponse = InputsRestUtils.getComponentInstanceInputs(service, vfi);
+ BaseValidationUtils.checkSuccess(getComponentInstanceInputsResponse);
+ List<InputDefinition> instanceInputs = new Gson().fromJson(getComponentInstanceInputsResponse.getResponse(), new TypeToken<ArrayList<InputDefinition>>() {
+ }.getType());
+ // Take only the 2 first inputs
+ List<InputDefinition> inputsToAdd = instanceInputs.stream().limit(2).collect(Collectors.toList());
+
+ // 7 Build component instances input map to add to server
+ ComponentInstInputsMap buildComponentInstInputsMap = buildComponentInstInputsMap(vfi.getUniqueId(), inputsToAdd);
+ RestResponse addInputResponse = InputsRestUtils.addInput(service, buildComponentInstInputsMap, UserRoleEnum.DESIGNER);
+ BaseValidationUtils.checkSuccess(addInputResponse);
+
+ // 8 validate inputs in service
+ // 8.1 download tosca template
+ getService = ServiceRestUtils.getService(service.getUniqueId());
+ BaseRestUtils.checkSuccess(getService);
+ service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
+
+ tosca = downloadAndParseToscaTemplate(sdncModifierDetails, service);
+ assertNotNull(tosca);
+ topology_template = (Map<String, Object>) tosca.get("topology_template");
+ assertNotNull(topology_template);
+
+ // 8.2 validate inputs in service
+ inputs = (Map<String, Object>) topology_template.get("inputs");
+ assertNotNull(inputs);
+ assertEquals(2, inputs.size());
+
+ // validate created inputs vs inputs in Tosca inputs section
+ final Map<String, Object> inputsFinal = inputs;
+ buildComponentInstInputsMap.getComponentInstanceInputsMap().values().forEach(listPerInstance -> {
+ listPerInstance.forEach(input -> {
+ Map<String, Object> inputInMap = (Map<String, Object>) inputsFinal.get(input.getName());
+ assertNotNull(inputInMap);
+ });
+ });
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = service.getComponentInstancesInputs();
+
+ // validate created inputs vs inputs in Tosca instance input value
+ List<ComponentInstanceInput> vfiInputs = componentInstancesInputs.get(vfi.getUniqueId());
+ assertNotNull(vfiInputs);
+ assertEquals(2, vfiInputs.size());
+
+ Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates");
+ assertNotNull(node_templates);
+
+ Map<String, Object> instance = (Map<String, Object>) node_templates.get(vfi.getName());
+ assertNotNull(instance);
+ Map<String, Object> properties = (Map<String, Object>) instance.get("properties");
+ assertNotNull(properties);
+
+ vfiInputs.forEach(vfiInput -> {
+ Map<String, Object> inputPropValueInTosca = (Map<String, Object>) properties.get(vfiInput.getName());
+ assertNotNull(inputPropValueInTosca);
+ String instaneInputName = (String) inputPropValueInTosca.get("get_input");
+ assertNotNull(instaneInputName);
+ Map<String, Object> inputInMap = (Map<String, Object>) inputsFinal.get(instaneInputName);
+ assertNotNull(inputInMap);
+ });
+
+ }
+
+ @Test(enabled = true)
+ public void exportComponentInstancesTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csar_1");
+
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ assertNotNull(load);
+ Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
+ assertNotNull(topology_template);
+
+ Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates");
+ assertNotNull(node_templates);
+
+ RestResponse getResource = ResourceRestUtils.getResource(createdResource.getUniqueId());
+ BaseRestUtils.checkSuccess(getResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(getResource.getResponse(), Resource.class);
+ List<ComponentInstance> componentInstances = resource.getComponentInstances();
+
+ assertEquals(componentInstances.size(), node_templates.size());
+
+ for (ComponentInstance ci : componentInstances) {
+ Map<String, Object> instance = (Map<String, Object>) node_templates.get(ci.getName());
+ assertNotNull(instance);
+ Map<String, Object> metadata = (Map<String, Object>) instance.get("metadata");
+ assertNotNull(metadata);
+ String customizationUUD = (String) metadata.get("customizationUUID");
+ assertTrue(ci.getCustomizationUUID().equals(customizationUUD));
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void extendNodeTemplateWithDefaultPropertyValuesTest() throws Exception {
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String payloadCsarName = "ToscaTemplateCsar.csar";
+ Path path = Paths.get(rootPath + CSARS_PATH + "ToscaTemplateCsar.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName(payloadCsarName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource createdResource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ assertNotNull(load);
+
+ Map<String, Object> nodeTemplateProperties = findNodeTemplateProperties(load, "custom_vl");
+
+ assertTrue(nodeTemplateProperties != null);
+ assertTrue(nodeTemplateProperties.get("dhcp_enabled").equals(true));
+ assertTrue(nodeTemplateProperties.get("ip_version").equals(4));
+ assertTrue(nodeTemplateProperties.get("vl_name").equals("customvl"));
+ }
+
+ private Map<String, Object> findNodeTemplateProperties(Map<String, Object> load, String riName) {
+ // find properties of node template (RI)
+ return findToscaElement(
+ // find node template (RI) by name
+ findToscaElement(
+ // find node templates
+ findToscaElement(
+ // find topology template
+ findToscaElement(load, "topology_template"), "node_templates"),
+ riName),
+ "properties");
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> findToscaElement(Map<String, Object> load, String elementName) {
+ return (Map<String, Object>) load.get(elementName);
+ }
+
+ // ----------------------------------------
private void validateInput(InputDefinition inputDef, Map<String, Object> inputInFile) {
assertEquals("validate input type", inputDef.getType(), (String) inputInFile.get("type"));
@@ -273,15 +626,19 @@ public class ExportToscaTest extends ComponentBaseTest {
assertEquals("validate input description", inputDef.getDescription(), (String) inputInFile.get("description"));
}
- // ----------------------------------------
- private Map<String, Object> downloadAndParseToscaTemplate(User sdncModifierDetails, Resource createdResource)
- throws Exception {
- String artifactUniqeId = createdResource.getToscaArtifacts().get("assettoscatemplate").getUniqueId();
-
- RestResponse toscaTemplate = ArtifactRestUtils.downloadResourceArtifactInternalApi(
- createdResource.getUniqueId(), sdncModifierDetails, artifactUniqeId);
- ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(toscaTemplate.getResponse(),
- ArtifactUiDownloadData.class);
+ private Map<String, Object> downloadAndParseToscaTemplate(User sdncModifierDetails, Component createdComponent) throws Exception {
+ String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscatemplate").getUniqueId();
+ RestResponse toscaTemplate;
+
+ if (createdComponent.getComponentType() == ComponentTypeEnum.RESOURCE) {
+ toscaTemplate = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId);
+
+ } else {
+ toscaTemplate = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId);
+ }
+ BaseRestUtils.checkSuccess(toscaTemplate);
+
+ ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(toscaTemplate.getResponse(), ArtifactUiDownloadData.class);
byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
Yaml yaml = new Yaml();
@@ -292,20 +649,7 @@ public class ExportToscaTest extends ComponentBaseTest {
return load;
}
- private Resource createVfFromCSAR(User sdncModifierDetails, String csarId) throws Exception {
- // create new resource from Csar
- ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
-
- resourceDetails.setCsarUUID(csarId);
- resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
- RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
- BaseRestUtils.checkCreateResponse(createResource);
- Resource createdResource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
- return createdResource;
- }
-
- public ArtifactDefinition findMasterArtifact(Map<String, ArtifactDefinition> deplymentArtifact,
- List<ArtifactDefinition> artifacts, List<String> artifactsList) {
+ public ArtifactDefinition findMasterArtifact(Map<String, ArtifactDefinition> deplymentArtifact, List<ArtifactDefinition> artifacts, List<String> artifactsList) {
for (String artifactUid : artifactsList) {
for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
ArtifactDefinition artifact = entry.getValue();
@@ -318,8 +662,7 @@ public class ExportToscaTest extends ComponentBaseTest {
ArtifactDefinition masterArtifact = null;
for (ArtifactDefinition artifactInfo : artifacts) {
String atrifactType = artifactInfo.getArtifactType();
- if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())
- || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType())) {
+ if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()) || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType())) {
masterArtifact = artifactInfo;
continue;
}
@@ -330,4 +673,13 @@ public class ExportToscaTest extends ComponentBaseTest {
}
return masterArtifact;
}
+
+ private ComponentInstInputsMap buildComponentInstInputsMap(String addToInput, List<InputDefinition> inputs) {
+ Map<String, List<InputDefinition>> map = new HashMap<>();
+ map.put(addToInput, inputs);
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setComponentInstanceInputsMap(map);
+ return componentInstInputsMap;
+ }
+
}