Search in sources :

Example 11 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlReaderTest method testPolicyDefinitionsAsList.

@Test
public void testPolicyDefinitionsAsList() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/simple-tests/valid-topology_templates-1_3.yml");
    YTServiceTemplate template = reader.parse(is);
    Assertions.assertNotNull(template);
    YTTopologyTemplateDefinition topologyTemplate = template.getTopologyTemplate();
    Assertions.assertNotNull(topologyTemplate);
    Assertions.assertEquals(2, topologyTemplate.getPolicies().size());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTTopologyTemplateDefinition(org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlReaderTest method testSupportedInterfaceDefinitions.

@Test
public void testSupportedInterfaceDefinitions() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/supported_interfaces.yml");
    YTServiceTemplate template = reader.parse(is);
    Assertions.assertNotNull(template);
    YTNodeType server = template.getNodeTypes().get("server");
    Assertions.assertEquals(2, server.getArtifacts().size());
    YTInterfaceDefinition standard = server.getInterfaces().get("Standard");
    Assertions.assertEquals(2, standard.getOperations().size());
    Assertions.assertEquals(1, standard.getInputs().size());
}
Also used : YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlCsarImporter method parseDefinitionsElement.

@Override
protected Optional<TDefinitions> parseDefinitionsElement(Path entryDefinitionsPath, final List<String> errors) {
    YamlReader reader = new YamlReader();
    YTServiceTemplate serviceTemplate;
    try {
        serviceTemplate = reader.parse(new FileInputStream(entryDefinitionsPath.toFile()));
        String name = serviceTemplate.getMetadata().get("name");
        if (name == null) {
            // fallback to filename
            name = entryDefinitionsPath.toString().substring(entryDefinitionsPath.toString().indexOf("__") + 2, entryDefinitionsPath.toString().indexOf(".tosca"));
        }
        ToCanonical converter = new ToCanonical(targetRepository);
        return Optional.of(converter.convert(serviceTemplate, name, serviceTemplate.getMetadata().get("targetNamespace"), true));
    } catch (MultiException | FileNotFoundException e) {
        e.printStackTrace();
        LOGGER.error("Could not read the given entry definition " + e.getMessage());
    }
    return Optional.empty();
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) FileNotFoundException(java.io.FileNotFoundException) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) ToCanonical(org.eclipse.winery.repository.yaml.converter.ToCanonical) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) FileInputStream(java.io.FileInputStream)

Aggregations

YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)13 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)10 InputStream (java.io.InputStream)9 FileInputStream (java.io.FileInputStream)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)5 AbstractConverterTest (org.eclipse.winery.repository.converter.AbstractConverterTest)5 Test (org.junit.jupiter.api.Test)5 YTTopologyTemplateDefinition (org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition)3 Path (java.nio.file.Path)2 AbstractMap (java.util.AbstractMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)2 Parameter (org.eclipse.winery.repository.converter.validator.support.Parameter)2 DisplayName (org.junit.jupiter.api.DisplayName)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1