Search in sources :

Example 1 with Entity

use of io.github.edmm.core.parser.Entity in project winery by eclipse.

the class EdmmConverterTest method transformProperties.

@Test
void transformProperties() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_3"));
    // endregion
    TServiceTemplate serviceTemplate = new TServiceTemplate();
    serviceTemplate.setTopologyTemplate(topology.build());
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    assertNotNull(transform);
    assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals("properties")));
    Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
        assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals(key) && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties") && entity.getChildren().size() == 1));
    });
    Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
        assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals(key) && !((ScalarEntity) entity).getValue().isEmpty() && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties")));
    });
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StringWriter(java.io.StringWriter) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) Stream(java.util.stream.Stream) EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Example 2 with Entity

use of io.github.edmm.core.parser.Entity in project winery by eclipse.

the class EdmmConverter method createType.

private EntityId createType(TEntityType toscaType, EntityId parentEntityId, EntityGraph entityGraph) {
    if (!entityGraph.getEntity(parentEntityId).isPresent()) {
        entityGraph.addEntity(new MappingEntity(parentEntityId, entityGraph));
    }
    EntityId typeEntityId = parentEntityId.extend(this.normalizeQName(toscaType.getQName()));
    EdmmType edmmType = oneToOneMappings.get(toscaType.getQName());
    if (edmmType != null) {
        typeEntityId = parentEntityId.extend(edmmType.getValue());
        entityGraph.addEntity(new MappingEntity(typeEntityId, entityGraph));
        EdmmTypeProperties.getDefaultConfiguration(edmmType, entityGraph);
        this.createPropertiesDefinition(toscaType, typeEntityId, entityGraph);
        if (Objects.nonNull(toscaType.getDerivedFrom())) {
            QName inheritsFrom = toscaType.getDerivedFrom().getType();
            TEntityType parent = toscaType instanceof TNodeType ? nodeTypes.get(inheritsFrom) : relationshipTypes.get(inheritsFrom);
            createType(parent, parentEntityId, entityGraph);
        }
    } else {
        Optional<Entity> entity = entityGraph.getEntity(typeEntityId);
        if (!entity.isPresent()) {
            entityGraph.addEntity(new MappingEntity(typeEntityId, entityGraph));
            if (Objects.nonNull(toscaType.getDerivedFrom())) {
                QName inheritsFrom = toscaType.getDerivedFrom().getType();
                TEntityType parent = toscaType instanceof TNodeType ? nodeTypes.get(inheritsFrom) : relationshipTypes.get(inheritsFrom);
                EntityId baseTypeEntityId = createType(parent, parentEntityId, entityGraph);
                entityGraph.addEntity(new ScalarEntity(baseTypeEntityId.getName(), typeEntityId.extend(DefaultKeys.EXTENDS), entityGraph));
            } else {
                String parentElement = "base";
                edmmType = edmmTypeMappings.get(toscaType.getQName());
                if (edmmType != null) {
                    parentElement = edmmType.getValue();
                    EdmmTypeProperties.getDefaultConfiguration(edmmType, entityGraph);
                } else if (toscaType instanceof TRelationshipType) {
                    parentElement = EdmmType.DEPENDS_ON.getValue();
                    EdmmTypeProperties.getDefaultConfiguration(EdmmType.DEPENDS_ON, entityGraph);
                }
                entityGraph.addEntity(new ScalarEntity(parentElement, typeEntityId.extend(DefaultKeys.EXTENDS), entityGraph));
            }
            this.createPropertiesDefinition(toscaType, typeEntityId, entityGraph);
        }
    }
    return typeEntityId;
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) Entity(io.github.edmm.core.parser.Entity) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) SequenceEntity(io.github.edmm.core.parser.SequenceEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) QName(javax.xml.namespace.QName) TEntityType(org.eclipse.winery.model.tosca.TEntityType) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 3 with Entity

use of io.github.edmm.core.parser.Entity in project winery by eclipse.

the class EdmmConverterTest method transformTopologyWithOperations.

@Test
void transformTopologyWithOperations() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_4"));
    // endregion
    TServiceTemplate serviceTemplate = new TServiceTemplate.Builder("testST", topology.build()).build();
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping, false);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    assertNotNull(transform);
    Optional<Entity> operations = transform.getEntity(Arrays.asList("0", "components", "test_node_4", "operations"));
    assertTrue(operations.isPresent());
    Optional<Entity> start = transform.getEntity(Arrays.asList("0", "components", "test_node_4", "operations", "start"));
    assertTrue(start.isPresent());
    assertTrue(start.get() instanceof ScalarEntity);
    assertEquals("/artifacttemplates/https%3A%2F%2Fex.org%2Ftosca%2Fto%2Fedmm/startTestNode4/files/script.sh", ((ScalarEntity) start.get()).getValue());
    Optional<Entity> stop = transform.getEntity(Arrays.asList("0", "components", "test_node_4", "operations", "stop"));
    assertTrue(stop.isPresent());
    assertTrue(stop.get() instanceof ScalarEntity);
    assertEquals("/artifacttemplates/https%3A%2F%2Fex.org%2Ftosca%2Fto%2Fedmm/startTestNode4/files/script.sh", ((ScalarEntity) stop.get()).getValue());
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Example 4 with Entity

use of io.github.edmm.core.parser.Entity in project winery by eclipse.

the class EdmmConverterTest method transformDerivedFrom.

@Test
void transformDerivedFrom() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_2"));
    // endregion
    TServiceTemplate serviceTemplate = new TServiceTemplate();
    serviceTemplate.setTopologyTemplate(topology.build());
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    assertNotNull(transform);
    assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals("extends") && ((ScalarEntity) entity).getValue().equals("software_component")));
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StringWriter(java.io.StringWriter) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) Stream(java.util.stream.Stream) EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Example 5 with Entity

use of io.github.edmm.core.parser.Entity in project winery by eclipse.

the class EdmmConverterTest method transformTopologyWithRelationsAndRelationTypes.

@Test
void transformTopologyWithRelationsAndRelationTypes() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_1"));
    topology.addNodeTemplate(nodeTemplates.get("test_node_2"));
    topology.addNodeTemplate(nodeTemplates.get("test_node_3"));
    topology.addRelationshipTemplate(relationshipTemplates.get("1_hosted_on_3"));
    topology.addRelationshipTemplate(relationshipTemplates.get("2_hosted_on_3"));
    topology.addRelationshipTemplate(relationshipTemplates.get("1_connects_to_2"));
    // endregion
    TServiceTemplate serviceTemplate = new TServiceTemplate();
    serviceTemplate.setTopologyTemplate(topology.build());
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    assertNotNull(transform);
    assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals("hosted_on") && ((ScalarEntity) entity).getValue().equals("test_node_3") && entity.getParent().isPresent() && entity.getParent().get().getName().equals("relations")));
    assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals("connects_to") && ((ScalarEntity) entity).getValue().equals("test_node_2") && entity.getParent().isPresent() && entity.getParent().get().getName().equals("relations")));
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StringWriter(java.io.StringWriter) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) Stream(java.util.stream.Stream) EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Aggregations

Entity (io.github.edmm.core.parser.Entity)5 MappingEntity (io.github.edmm.core.parser.MappingEntity)5 ScalarEntity (io.github.edmm.core.parser.ScalarEntity)5 EntityGraph (io.github.edmm.core.parser.EntityGraph)4 EdmmDependantTest (org.eclipse.winery.edmm.EdmmDependantTest)4 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 Test (org.junit.jupiter.api.Test)4 StringWriter (java.io.StringWriter)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Arrays (java.util.Arrays)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 EntityId (io.github.edmm.core.parser.EntityId)1 SequenceEntity (io.github.edmm.core.parser.SequenceEntity)1 QName (javax.xml.namespace.QName)1 TEntityType (org.eclipse.winery.model.tosca.TEntityType)1