use of org.kie.dmn.model.v1_1.TTextAnnotation in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testAssociationEdgeDMNDI.
/**
* DROOLS-2569 [DMN Designer] Marshalling of magnet positions -- Association DMN Edge DMNDI serialization.
* This test re-create by hard-code the graph to simulate the behavior of the Stunner framework programmatically.
*/
@SuppressWarnings("unchecked")
@Test
public void testAssociationEdgeDMNDI() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.TextAnnotation dmnTextAnnotation = new TTextAnnotation();
dmnTextAnnotation.setId("textAnnotationID");
Node textAnnotationNode = new TextAnnotationConverter(api.getFactoryManager()).nodeFromDMN(dmnTextAnnotation, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(textAnnotationNode);
View content = (View) textAnnotationNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String edgeID = "edgeID";
final String associationID = "associationID";
Edge myEdge = api.getFactoryManager().newElement(edgeID, DMNMarshallerStandalone.ASSOCIATION_ID).asEdge();
final View<?> edgeView = (View<?>) myEdge.getContent();
((Association) edgeView.getDefinition()).setId(new Id(associationID));
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(textAnnotationNode);
inputDataNode.getOutEdges().add(myEdge);
textAnnotationNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(textAnnotationNode));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, textAnnotationNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
assertThat(dmnDefinitions.getDMNDI().getDMNDiagram().get(0).getDMNDiagramElement().stream().filter(DMNEdge.class::isInstance).count()).isEqualTo(1);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), associationID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
}
Aggregations