package org.openecomp.sdc.be.tosca; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.junit.Test; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; public class ToscaExportUtilsTest { private static final Logger log = LoggerFactory.getLogger(ToscaExportUtilsTest.class); @javax.annotation.Resource private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; @Autowired private ToscaExportHandler exportUtils; @Autowired private ComponentInstanceOperation componentInstanceOperation; Gson gson = new GsonBuilder().setPrettyPrinting().create(); @Test public void testExportService() { /* Resource resource1 = ResourceTestUtils.prepareResource(0); resource1.setResourceType(ResourceTypeEnum.VF); Either createResource1 = resourceBusinessLogic.createResource(resource1, getAdminUser(), null, null); assertTrue(createResource1.isLeft()); Resource certifiedVFC1 = changeResourceStateToCertify(createResource1.left().value()); Resource resource2 = ResourceTestUtils.prepareResource(1); resource2.setResourceType(ResourceTypeEnum.VF); Either createResource2 = resourceBusinessLogic.createResource(resource2, getAdminUser(), null, null); assertTrue(createResource2.isLeft()); Resource certifiedVFC2 = changeResourceStateToCertify(createResource2.left().value()); Service service = ResourceTestUtils.prepareService(0); Either createService = serviceBusinessLogic.createService(service, getAdminUser()); assertTrue(createService.isLeft()); // add VFC instance to VF ComponentInstance vfcResourceInstance1 = new ComponentInstance(); vfcResourceInstance1.setDescription("VFC instance 1"); vfcResourceInstance1.setName(certifiedVFC1.getName()); vfcResourceInstance1.setComponentUid(certifiedVFC1.getUniqueId()); Either createResourceVfcInstance1 = serviceInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, createService.left().value().getUniqueId(), adminUser.getAttuid(), vfcResourceInstance1); assertTrue(createResourceVfcInstance1.isLeft()); ComponentInstance vfcResourceInstance2 = new ComponentInstance(); vfcResourceInstance2.setDescription("VFC instance 2"); vfcResourceInstance2.setName(certifiedVFC2.getName()); vfcResourceInstance2.setComponentUid(certifiedVFC2.getUniqueId()); Either createResourceVfcInstance2 = serviceInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, createService.left().value().getUniqueId(), adminUser.getAttuid(), vfcResourceInstance2); assertTrue(createResourceVfcInstance2.isLeft()); Either serviceFetch = serviceBusinessLogic.getService(createService.left().value().getUniqueId(), adminUser); assertTrue(serviceFetch.isLeft()); List componentInstances = serviceFetch.left().value().getComponentInstances(); String ciname1 = null; String ciname2 = null; for (ComponentInstance ci : componentInstances) { if (ci.getComponentUid().equals(certifiedVFC1.getUniqueId())) { ciname1 = ci.getName(); } if (ci.getComponentUid().equals(certifiedVFC2.getUniqueId())) { ciname2 = ci.getName(); } } Either result = exportUtils.exportComponent(serviceFetch.left().value()); assertTrue(result.isLeft()); String mainYaml = result.left().value().getMainYaml(); assertNotNull(mainYaml); YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); assertTrue(yamlToObjectConverter.isValidYaml(mainYaml.getBytes())); log.debug(mainYaml); Yaml yaml = new Yaml(); InputStream inputStream = new ByteArrayInputStream(mainYaml.getBytes()); Map load = (Map) yaml.load(inputStream); Map imports = (Map) load.get("imports"); assertNotNull(imports); assertEquals("Validate imports size in yml", 2, imports.size()); Map metadata = (Map) load.get("metadata"); assertNotNull(metadata); validateMetadata(metadata, serviceFetch.left().value(), false); Map vf1 = (Map) imports.get(certifiedVFC1.getName()); String fileName = (String) vf1.get(ToscaExportHandler.IMPORTS_FILE_KEY); ArtifactDefinition artifactDefinition = certifiedVFC1.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE); assertEquals("Validate 1 file name", artifactDefinition.getArtifactName(), fileName); Map topology_template = (Map) load.get("topology_template"); Map node_templates = (Map) topology_template.get("node_templates"); Map inst1 = (Map) node_templates.get(ciname1); Map inst2 = (Map) node_templates.get(ciname2); Map inst1MD = (Map) inst1.get("metadata"); Map inst2MD = (Map) inst2.get("metadata"); validateMetadata(inst1MD, certifiedVFC1, true); Map vf2 = (Map) imports.get(certifiedVFC2.getName()); fileName = (String) vf2.get(ToscaExportHandler.IMPORTS_FILE_KEY); artifactDefinition = certifiedVFC2.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE); assertEquals("Validate 2 file name", artifactDefinition.getArtifactName(), fileName); validateMetadata(inst2MD, certifiedVFC2, true);*/ } }