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")));
});
}
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;
}
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());
}
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")));
}
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")));
}
Aggregations