diff options
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/tosca')
5 files changed, 345 insertions, 271 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertorTest.java new file mode 100644 index 0000000000..3c42257446 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertorTest.java @@ -0,0 +1,124 @@ +package org.openecomp.sdc.be.tosca; +// + +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.Resource; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; + +public class CapabiltyRequirementConvertorTest { + + CapabiltyRequirementConvertor capabiltyRequirementConvertor = Mockito.spy(new CapabiltyRequirementConvertor()); + ComponentInstance instanceProxy = Mockito.spy( new ComponentInstance() ); + ComponentInstance vfInstance = Mockito.spy( new ComponentInstance() ); + Component vfComponent = Mockito.spy( new Resource() ); + ComponentInstance vfcInstance = Mockito.spy( new ComponentInstance() ); + Component vfcComponent = Mockito.spy( new Resource() ); + + @Test + public void getReducedPathByOwner() throws Exception { + List<String> pathList = new ArrayList<>(); + String uniqueId = "41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693.lb_2"; + + String exerpt = "41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693.lb_1"; + String duplicate = "a77df84e-83eb-4edc-9823-d1f9f6549693.c79e9a4a-b172-4323-a2e2-1c48d6603241.lb_swu_direct_4_rvmi"; + pathList.add(exerpt); + pathList.add(duplicate); + pathList.add(duplicate); + pathList.add(uniqueId); + + pathList.add("5f172af9-1588-443e-8897-1432b19aad8c.2cb7514a-1e50-4280-8457-baacb97b50bf.vepdgtp4837vf0"); + pathList.add("86ae128e-3d0a-41f7-a957-db1df9fe598c.9cc8f8ac-6869-4dd6-a6e1-74ecb9570dc4.vepdgtp4837svc_proxy0"); + + List<String> reducedMap = new CapabiltyRequirementConvertor().getReducedPathByOwner( pathList , uniqueId ); + + assertThat( reducedMap ).isNotNull().doesNotContain(exerpt).containsOnlyOnce(duplicate).hasSize(4); + } + + //generate stub capability + private Map<String, List<CapabilityDefinition>> newCapabilities(String capabilityName){ + Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>(); + List<CapabilityDefinition> list = new ArrayList<>(); + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName( capabilityName ); + capabilityDefinition.setType("att.Node"); + List<String> pathList = new ArrayList<>(); + + capabilityDefinition.setOwnerId("41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693"); + pathList.add("41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693.lb_1"); + //pathList.add("a77df84e-83eb-4edc-9823-d1f9f6549693.c79e9a4a-b172-4323-a2e2-1c48d6603241.lb_swu_direct_4_rvmi"); + pathList.add("5f172af9-1588-443e-8897-1432b19aad8c.2cb7514a-1e50-4280-8457-baacb97b50bf.vepdgtp4837vf0"); + pathList.add("86ae128e-3d0a-41f7-a957-db1df9fe598c.9cc8f8ac-6869-4dd6-a6e1-74ecb9570dc4.vepdgtp4837svc_proxy0"); + + capabilityDefinition.setPath(pathList); + list.add(capabilityDefinition); + capabilities.put(capabilityDefinition.getType() , list ); + + return capabilities; + } + + + @Test + public void testBuildName(){ + doReturn("1").when(instanceProxy).getActualComponentUid(); + doReturn("2").when(vfInstance).getActualComponentUid(); + doReturn("3").when(vfcInstance).getActualComponentUid(); + //region proxy + Component proxyOrigin = new Resource(); + + proxyOrigin.setName( "vepdgtp4837svc_proxy0" ); + proxyOrigin.setComponentType(ComponentTypeEnum.RESOURCE); + proxyOrigin.setComponentInstances( asList( vfInstance ) ); + + //endregion + //region vf+vfc + vfInstance.setName("vepdgtp4837vf0"); + vfInstance.setNormalizedName("vepdgtp4837vf0"); + vfInstance.setUniqueId("5f172af9-1588-443e-8897-1432b19aad8c.2cb7514a-1e50-4280-8457-baacb97b50bf.vepdgtp4837vf0"); + vfComponent.setName("vepdgtp4837vf0"); //origin + vfComponent.setComponentInstances(Arrays.asList(vfcInstance)); + vfcInstance.setUniqueId("41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693.lb_1"); + vfcInstance.setName("lb_1"); + vfcInstance.setNormalizedName("lb_1"); + vfcInstance.setName("41d3a665-1313-4b5e-9bf0-e901ecf4b806.a77df84e-83eb-4edc-9823-d1f9f6549693.lb_1"); + vfcComponent.setName("lb_1"); + //endregion + Map<String, List<CapabilityDefinition>> capabilities = newCapabilities("port"); + vfcComponent.setCapabilities(capabilities); + Map<Component, ComponentInstance> map = Collections.unmodifiableMap(new HashMap<Component, ComponentInstance>() { + { + put( proxyOrigin, null ); + put( vfComponent, vfInstance ); + put( vfcComponent, vfcInstance ); + } } ) ; + Map<String, Component> cache = Collections.unmodifiableMap(new HashMap<String, Component>() {{ + put( "1",proxyOrigin); + put( "2" ,vfComponent); + put( "3" ,vfcComponent); + }}); + instanceProxy.setCapabilities(capabilities); + proxyOrigin.setCapabilities( capabilities ); + List<CapabilityDefinition> flatList = capabilities.values().stream().flatMap(List::stream).collect(Collectors.toList()); + flatList.stream().forEach( (CapabilityDefinition capabilityDefinition) -> { + String name = capabiltyRequirementConvertor.buildCapabilityNameForComponentInstance(cache, instanceProxy, capabilityDefinition); + System.out.println("built name -> " + name); + assertThat(name).isEqualTo( "vepdgtp4837vf0.lb_1."+capabilityDefinition.getName() ); + }); + } +} + diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java index 7348156923..8883786d7e 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java @@ -20,116 +20,71 @@ package org.openecomp.sdc.be.tosca; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.Assert; +import fj.data.Either; import org.junit.Before; import org.junit.Test; import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; -import fj.data.Either; - -public class CsarUtilsTest { - @Before - public void setup() { - ExternalConfiguration.setAppName("catalog-be"); - - // Init Configuration - String appConfigDir = "src/test/resources/config/catalog-be"; - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), - appConfigDir); - ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - } - - @Test - public void testValidateNonMetaArtifactHappyScenario() { - String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml"; - byte[] payloadData = "some payload data".getBytes(); - Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); - Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, - payloadData, collectedWarningMessages); - assertTrue(eitherNonMetaArtifact.isLeft()); - assertTrue(collectedWarningMessages.isEmpty()); - - artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml"; - eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); - assertTrue(eitherNonMetaArtifact.isLeft()); - assertTrue(collectedWarningMessages.isEmpty()); - } - - @Test - public void testValidateNonMetaArtifactScenarioWithWarnnings() { - String artifactPath = "Artifacts/Deployment/Buga/myYang.xml"; - byte[] payloadData = "some payload data".getBytes(); - Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); - Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, - payloadData, collectedWarningMessages); - assertTrue(eitherNonMetaArtifact.isLeft()); - - artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml"; - eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); - assertTrue(eitherNonMetaArtifact.isLeft()); - - assertTrue(collectedWarningMessages.size() == 1); - assertTrue(collectedWarningMessages.values().iterator().next().size() == 2); - } - - @Test - public void testValidateNonMetaArtifactUnhappyScenario() { - String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml"; - byte[] payloadData = "some payload data".getBytes(); - Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); - Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, - payloadData, collectedWarningMessages); - assertTrue(eitherNonMetaArtifact.isRight()); - assertTrue(!collectedWarningMessages.isEmpty()); - } - - private CsarUtils createTestSubject() { - return new CsarUtils(); - } - - - @Test - public void testExtractVfcsArtifactsFromCsar() throws Exception { - Map<String, byte[]> csar = null; - Map<String, List<ArtifactDefinition>> result; - - // test 1 - csar = null; - result = CsarUtils.extractVfcsArtifactsFromCsar(csar); - Assert.assertEquals(new HashMap<String, List<ArtifactDefinition>>() , result); - } - - - @Test - public void testHandleWarningMessages() throws Exception { - Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); - - // default test - CsarUtils.handleWarningMessages(collectedWarningMessages); - } - - - @Test - public void testValidateNonMetaArtifact() throws Exception { - String artifactPath = ""; - byte[] payloadData = new byte[] { ' ' }; - Map<String, Set<List<String>>> collectedWarningMessages = null; - Either<NonMetaArtifactInfo, Boolean> result; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; - // default test - result = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); - } +import static org.junit.Assert.assertTrue; +public class CsarUtilsTest { + @Before + public void setup() { + ExternalConfiguration.setAppName("catalog-be"); + + // init Configuration + String appConfigDir = "src/test/resources/config/catalog-be"; + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); + ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); + } + + @Test + public void testValidateNonMetaArtifactHappyScenario(){ + String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml"; + byte[] payloadData = "some payload data".getBytes(); + Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); + Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); + assertTrue(eitherNonMetaArtifact.isLeft() ); + assertTrue(collectedWarningMessages.isEmpty() ); + + artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml"; + eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); + assertTrue(eitherNonMetaArtifact.isLeft() ); + assertTrue(collectedWarningMessages.isEmpty() ); + } + + @Test + public void testValidateNonMetaArtifactScenarioWithWarnnings(){ + String artifactPath = "Artifacts/Deployment/Buga/myYang.xml"; + byte[] payloadData = "some payload data".getBytes(); + Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); + Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); + assertTrue(eitherNonMetaArtifact.isLeft() ); + + artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml"; + eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); + assertTrue(eitherNonMetaArtifact.isLeft() ); + + assertTrue(collectedWarningMessages.size() == 1 ); + assertTrue(collectedWarningMessages.values().iterator().next().size() == 2); + } + + @Test + public void testValidateNonMetaArtifactUnhappyScenario(){ + String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml"; + byte[] payloadData = "some payload data".getBytes(); + Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); + Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages); + assertTrue(eitherNonMetaArtifact.isRight() ); + assertTrue( !collectedWarningMessages.isEmpty() ); + } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java index 139de137d9..dbdec12193 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java @@ -1,18 +1,6 @@ package org.openecomp.sdc.be.tosca; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - +import fj.data.Either; import org.junit.Before; import org.junit.Test; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; @@ -23,7 +11,18 @@ import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; -import fj.data.Either; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; public class PropertyConvertorTest { private PropertyDefinition property; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/SchemaFiles.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/SchemaFiles.java index acfeaf1abc..839095f1ca 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/SchemaFiles.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/SchemaFiles.java @@ -20,8 +20,8 @@ package org.openecomp.sdc.be.tosca; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.yaml.snakeyaml.Yaml; import java.io.FileInputStream; import java.io.IOException; @@ -31,46 +31,46 @@ import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; -import org.junit.Test; -import org.yaml.snakeyaml.Yaml; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class SchemaFiles { - - @Test - public void testValidateYamlNormativeFiles(){ - String importToscaPath = "src/main/resources/import/tosca"; - assertTrue(checkValidYamlInFileTree(importToscaPath)); - } - - @Test - public void testRainyYamlNormativeFiles(){ - String importToscaPathTest = "src/test/resources/yamlValidation"; - assertFalse(checkValidYamlInFileTree(importToscaPathTest)); - } - - private boolean checkValidYamlInFileTree(String fileTree) { - - try { - List<Path> fileTreeYamlList = Files.walk(Paths.get(fileTree)) - .filter(path -> path.getFileName().toString().toLowerCase().endsWith(".yml")) - .collect(Collectors.toList()); - - for (Path yamlFile : fileTreeYamlList) { - try { - FileInputStream inputStream = new FileInputStream(yamlFile.toAbsolutePath().toString()); - Yaml yaml = new Yaml(); - Object content = yaml.load(inputStream); - } catch (Exception e) { - System.out.println("Not valid yaml in file creation : " + yamlFile.toAbsolutePath().toString()); - return false; - } - } - } catch (IOException e) { - System.out.println("Error in reading file from folder : " + fileTree); - return false; - } - return true; - } - - + + @Test + public void testValidateYamlNormativeFiles(){ + String importToscaPath = "src/main/resources/import/tosca"; + assertTrue(checkValidYamlInFileTree(importToscaPath)); + } + + @Test + public void testRainyYamlNormativeFiles(){ + String importToscaPathTest = "src/test/resources/yamlValidation"; + assertFalse(checkValidYamlInFileTree(importToscaPathTest)); + } + + private boolean checkValidYamlInFileTree(String fileTree) { + + try { + List<Path> fileTreeYamlList = Files.walk(Paths.get(fileTree)) + .filter(path -> path.getFileName().toString().toLowerCase().endsWith(".yml")) + .collect(Collectors.toList()); + + for (Path yamlFile : fileTreeYamlList) { + try { + FileInputStream inputStream = new FileInputStream(yamlFile.toAbsolutePath().toString()); + Yaml yaml = new Yaml(); + Object content = yaml.load(inputStream); + } catch (Exception e) { + System.out.println("Not valid yaml in file creation : " + yamlFile.toAbsolutePath().toString()); + return false; + } + } + } catch (IOException e) { + System.out.println("Error in reading file from folder : " + fileTree); + return false; + } + return true; + } + + } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java index 4c22cf3599..efc89a9f9d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java @@ -1,124 +1,120 @@ 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.ServiceComponentInstanceBusinessLogic; -import org.openecomp.sdc.be.components.impl.VFComponentInstanceBusinessLogic; +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; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public class ToscaExportUtilsTest { - private static Logger log = LoggerFactory.getLogger(ToscaExportUtilsTest.class.getName()); - @javax.annotation.Resource - private VFComponentInstanceBusinessLogic componentInstanceBusinessLogic; - @javax.annotation.Resource - private ServiceComponentInstanceBusinessLogic serviceInstanceBusinessLogic; - @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<Resource, ResponseFormat> 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<Resource, ResponseFormat> createResource2 = resourceBusinessLogic.createResource(resource2, getAdminUser(), null, null); - assertTrue(createResource2.isLeft()); - Resource certifiedVFC2 = changeResourceStateToCertify(createResource2.left().value()); - - Service service = ResourceTestUtils.prepareService(0); - Either<Service, ResponseFormat> 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<ComponentInstance, ResponseFormat> 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<ComponentInstance, ResponseFormat> createResourceVfcInstance2 = serviceInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, createService.left().value().getUniqueId(), adminUser.getAttuid(), - vfcResourceInstance2); - assertTrue(createResourceVfcInstance2.isLeft()); - - Either<Service, ResponseFormat> serviceFetch = serviceBusinessLogic.getService(createService.left().value().getUniqueId(), adminUser); - assertTrue(serviceFetch.isLeft()); - - List<ComponentInstance> 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<ToscaRepresentation, ToscaError> 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<String, Object> load = (Map<String, Object>) yaml.load(inputStream); - Map<String, Object> imports = (Map<String, Object>) load.get("imports"); - assertNotNull(imports); - assertEquals("Validate imports size in yml", 2, imports.size()); - - Map<String, Object> metadata = (Map<String, Object>) load.get("metadata"); - assertNotNull(metadata); - validateMetadata(metadata, serviceFetch.left().value(), false); - - Map<String, Object> vf1 = (Map<String, Object>) 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<String, Object> topology_template = (Map<String, Object>) load.get("topology_template"); - Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates"); - Map<String, Object> inst1 = (Map<String, Object>) node_templates.get(ciname1); - Map<String, Object> inst2 = (Map<String, Object>) node_templates.get(ciname2); - - Map<String, Object> inst1MD = (Map<String, Object>) inst1.get("metadata"); - Map<String, Object> inst2MD = (Map<String, Object>) inst2.get("metadata"); - - validateMetadata(inst1MD, certifiedVFC1, true); - - Map<String, Object> vf2 = (Map<String, Object>) 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);*/ - } + 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<Resource, ResponseFormat> 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<Resource, ResponseFormat> createResource2 = resourceBusinessLogic.createResource(resource2, getAdminUser(), null, null); + assertTrue(createResource2.isLeft()); + Resource certifiedVFC2 = changeResourceStateToCertify(createResource2.left().value()); + + Service service = ResourceTestUtils.prepareService(0); + Either<Service, ResponseFormat> 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<ComponentInstance, ResponseFormat> 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<ComponentInstance, ResponseFormat> createResourceVfcInstance2 = serviceInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, createService.left().value().getUniqueId(), adminUser.getAttuid(), + vfcResourceInstance2); + assertTrue(createResourceVfcInstance2.isLeft()); + + Either<Service, ResponseFormat> serviceFetch = serviceBusinessLogic.getService(createService.left().value().getUniqueId(), adminUser); + assertTrue(serviceFetch.isLeft()); + + List<ComponentInstance> 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<ToscaRepresentation, ToscaError> 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<String, Object> load = (Map<String, Object>) yaml.load(inputStream); + Map<String, Object> imports = (Map<String, Object>) load.get("imports"); + assertNotNull(imports); + assertEquals("Validate imports size in yml", 2, imports.size()); + + Map<String, Object> metadata = (Map<String, Object>) load.get("metadata"); + assertNotNull(metadata); + validateMetadata(metadata, serviceFetch.left().value(), false); + + Map<String, Object> vf1 = (Map<String, Object>) 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<String, Object> topology_template = (Map<String, Object>) load.get("topology_template"); + Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates"); + Map<String, Object> inst1 = (Map<String, Object>) node_templates.get(ciname1); + Map<String, Object> inst2 = (Map<String, Object>) node_templates.get(ciname2); + + Map<String, Object> inst1MD = (Map<String, Object>) inst1.get("metadata"); + Map<String, Object> inst2MD = (Map<String, Object>) inst2.get("metadata"); + + validateMetadata(inst1MD, certifiedVFC1, true); + + Map<String, Object> vf2 = (Map<String, Object>) 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);*/ + } } |