Search in sources :

Example 6 with EntityGraph

use of io.github.edmm.core.parser.EntityGraph 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 7 with EntityGraph

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

the class EdmmConverterTest method transformTopology.

@Test
void transformTopology() {
    // 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.addNodeTemplate(nodeTemplates.get("test_node_4"));
    topology.addRelationshipTemplate(relationshipTemplates.get("1_hosted_on_3"));
    topology.addRelationshipTemplate(relationshipTemplates.get("2_hosted_on_3"));
    topology.addRelationshipTemplate(relationshipTemplates.get("4_hosted_on_1"));
    topology.addRelationshipTemplate(relationshipTemplates.get("1_connects_to_2"));
    TServiceTemplate serviceTemplate = new TServiceTemplate();
    serviceTemplate.setTopologyTemplate(topology.build());
    // endregion
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping, false);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    StringWriter stringWriter = new StringWriter();
    transform.generateYamlOutput(stringWriter);
    assertEquals("---\n" + "components:\n" + "  test_node_1:\n" + "    type: software_component\n" + "    relations:\n" + "    - connects_to: test_node_2\n" + "    - hosted_on: test_node_3\n" + "    properties:\n" + "      name: test_node_1\n" + "    artifacts:\n" + "    - war: /artifacttemplates/https%3A%2F%2Fex.org%2Ftosca%2Fto%2Fedmm/testNode1-DA/files/da.war\n" + "  test_node_3:\n" + "    type: https_ex.orgtoscatoedmm__test_node_type_3\n" + "    properties:\n" + "      public_key: '-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----'\n" + "      ssh_port: '22'\n" + "      os_family: ubuntu\n" + "      name: test_node_3\n" + "  test_node_2:\n" + "    relations:\n" + "    - hosted_on: test_node_3\n" + "    type: https_ex.orgtoscatoedmm__test_node_type_2\n" + "    properties:\n" + "      name: test_node_2\n" + "  test_node_4:\n" + "    operations:\n" + "      stop: /artifacttemplates/https%3A%2F%2Fex.org%2Ftosca%2Fto%2Fedmm/startTestNode4/files/script.sh\n" + "      start: /artifacttemplates/https%3A%2F%2Fex.org%2Ftosca%2Fto%2Fedmm/startTestNode4/files/script.sh\n" + "    type: https_ex.orgtoscatoedmm__test_node_type_4\n" + "    relations:\n" + "    - hosted_on: test_node_1\n" + "    properties:\n" + "      name: test_node_4\n" + "relation_types:\n" + "  depends_on:\n" + "    extends: null\n" + "  hosted_on:\n" + "    extends: depends_on\n" + "  connects_to:\n" + "    extends: depends_on\n" + "multi_id: '12345'\n" + "component_types:\n" + "  https_ex.orgtoscatoedmm__test_node_type_2:\n" + "    extends: software_component\n" + "  compute:\n" + "    extends: base\n" + "  https_ex.orgtoscatoedmm__test_node_type_3:\n" + "    extends: compute\n" + "    properties:\n" + "      public_key:\n" + "        type: string\n" + "      ssh_port:\n" + "        type: number\n" + "      os_family:\n" + "        type: string\n" + "  web_application:\n" + "    extends: base\n" + "  https_ex.orgtoscatoedmm__test_node_type_4:\n" + "    extends: web_application\n" + "  software_component:\n" + "    extends: base\n" + "version: edm_1_0\n", stringWriter.toString());
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) 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)

Example 8 with EntityGraph

use of io.github.edmm.core.parser.EntityGraph 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 9 with EntityGraph

use of io.github.edmm.core.parser.EntityGraph 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)

Example 10 with EntityGraph

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

the class EdmmConverterTest method transformOneNodeTemplate.

@Test
void transformOneNodeTemplate() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_1"));
    // 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);
    assertEquals(13, transform.vertexSet().size());
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) 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)

Aggregations

EntityGraph (io.github.edmm.core.parser.EntityGraph)10 EdmmDependantTest (org.eclipse.winery.edmm.EdmmDependantTest)6 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)6 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 Test (org.junit.jupiter.api.Test)6 MappingEntity (io.github.edmm.core.parser.MappingEntity)5 StringWriter (java.io.StringWriter)5 Entity (io.github.edmm.core.parser.Entity)4 ScalarEntity (io.github.edmm.core.parser.ScalarEntity)4 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 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 PluginService (io.github.edmm.core.plugin.PluginService)1