use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testMagnetDockers.
private void testMagnetDockers(Diagram<Graph, Metadata> diagram) {
Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
Node businessRuleTaskNode = (Node) findElementByContentType(diagram, BusinessRuleTask.class);
Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
assertNotNull(userTaskNode);
assertNotNull(businessRuleTaskNode);
assertNotNull(scriptTaskNode);
ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
ViewConnector businessRuleTaskInEdgeConnector = getInEdgeViewConnector(businessRuleTaskNode);
ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskInEdgeConnector);
assertNotNull(businessRuleTaskInEdgeConnector);
assertNotNull(scriptTaskInEdgeConnector);
ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
ViewConnector businessRuleTaskOutEdgeConnector = getOutEdgeViewConnector(businessRuleTaskNode);
ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskOutEdgeConnector);
assertNotNull(businessRuleTaskOutEdgeConnector);
assertNotNull(scriptTaskOutEdgeConnector);
// userTaskInEdgeConnector is from magnet top-middle to left-middle
assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
DiscreteConnection sourceConnection = (DiscreteConnection) userTaskInEdgeConnector.getSourceConnection().get();
DiscreteConnection targetConnection = (DiscreteConnection) userTaskInEdgeConnector.getTargetConnection().get();
assertEquals(20d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(24d, targetConnection.getLocation().getY(), 0.1d);
// Assert both connections for userTaskInEdgeConnector are set to auto.
assertTrue(sourceConnection.isAuto());
assertTrue(targetConnection.isAuto());
// businessRuleTaskInEdgeConnector is from magnet right-middle to top-left
assertTrue(businessRuleTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(businessRuleTaskInEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (DiscreteConnection) businessRuleTaskInEdgeConnector.getSourceConnection().get();
targetConnection = (DiscreteConnection) businessRuleTaskInEdgeConnector.getTargetConnection().get();
assertEquals(40d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(20d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// Assert both connections for businessRuleTaskInEdgeConnector are NOT set to auto.
assertFalse(sourceConnection.isAuto());
assertFalse(targetConnection.isAuto());
// scriptTaskInEdgeConnector is from magnet left-bottom to left-bottom
assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (DiscreteConnection) scriptTaskInEdgeConnector.getSourceConnection().get();
targetConnection = (DiscreteConnection) scriptTaskInEdgeConnector.getTargetConnection().get();
assertEquals(0d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(40d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(48d, targetConnection.getLocation().getY(), 0.1d);
// userTaskOutEdgeConnector is from magnet right-middle to left-middle
assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (DiscreteConnection) userTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (DiscreteConnection) userTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
// businessRuleTaskOutEdgeConnector is from magnet middle-bottom to middle-bottom
assertTrue(businessRuleTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(businessRuleTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (DiscreteConnection) businessRuleTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (DiscreteConnection) businessRuleTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(68d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(14d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(28d, targetConnection.getLocation().getY(), 0.1d);
// scriptTaskOutEdgeConnector is from magnet left-top to left-top
assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (DiscreteConnection) scriptTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (DiscreteConnection) scriptTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(0d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallNotBoundaryEvents.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallNotBoundaryEvents() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_NOT_BOUNDARY_EVENTS);
assertEquals("Not Boundary Event", diagram.getMetadata().getTitle());
assertDiagram(diagram, 6);
// Assert than the intermediate event is connected using a view connector,
// so not boundary to the task ( not docked ).
Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
List<Edge> inEdges = event.getInEdges();
boolean foundViewConnector = false;
for (Edge e : inEdges) {
if (e.getContent() instanceof ViewConnector) {
foundViewConnector = true;
}
}
assertTrue(foundViewConnector);
// Assert absolute position as the node is not docked.
Bounds bounds = ((View) event.getContent()).getBounds();
Bounds.Bound ul = bounds.getUpperLeft();
Bounds.Bound lr = bounds.getLowerRight();
assertEquals(305, ul.getX(), 0);
assertEquals(300, ul.getY(), 0);
assertEquals(335, lr.getX(), 0);
assertEquals(330, lr.getY(), 0);
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallBoundaryEvents.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallBoundaryEvents() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_BOUNDARY_EVENTS);
// Basic assertions.
assertEquals("Boundary Event", diagram.getMetadata().getTitle());
assertDiagram(diagram, 6);
// Assert than the intermediate event is connected using a dock connector,
// so boundary to the task.
Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
List<Edge> inEdges = event.getInEdges();
boolean foundDockConector = false;
for (Edge e : inEdges) {
if (e.getContent() instanceof Dock) {
foundDockConector = true;
}
}
assertTrue(foundDockConector);
// Assert relative position for the docked node.
Bounds bounds = ((View) event.getContent()).getBounds();
Bounds.Bound ul = bounds.getUpperLeft();
Bounds.Bound lr = bounds.getLowerRight();
assertEquals(57, ul.getX(), 0);
assertEquals(70, ul.getY(), 0);
assertEquals(87, lr.getX(), 0);
assertEquals(100, lr.getY(), 0);
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class MockApplicationFactoryManager method newElement.
@Override
public Element<?> newElement(String uuid, Class<?> type) {
String id = BindableAdapterUtils.getGenericClassName(type);
if (BPMNDefinitionSet.class.equals(type)) {
Graph graph = bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
return graph;
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
Node node = viewNodeFactory.build(uuid, model);
return node;
} else if (element.isAssignableFrom(EdgeFactory.class)) {
Edge edge = connectionEdgeFactory.build(uuid, model);
return edge;
}
}
return null;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerBase method getNodes.
@SuppressWarnings("unchecked")
protected List<Node> getNodes(Diagram<Graph, Metadata> diagram) {
Graph graph = diagram.getGraph();
assertNotNull(graph);
Iterator<Node> nodesIterable = graph.nodes().iterator();
List<Node> nodes = new ArrayList<>();
nodesIterable.forEachRemaining(nodes::add);
return nodes;
}
Aggregations