use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextFromRootWithParent.
@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
this.graphTestHandlerParent = new TestingGraphMockHandler();
graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
Node node = mock(Node.class);
Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
View viewNode = mock(View.class);
when(node.getContent()).thenReturn(viewNode);
when(viewNode.getBounds()).thenReturn(boundsNode);
when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
double[] size = GraphUtils.getNodeSize(start.getContent());
assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
assertTrue(next.getY() > size[1]);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.
// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
when(ruleManager.evaluate(eq(ruleSet), any(RuleEvaluationContext.class))).thenReturn(ruleViolations);
when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(true);
this.graphTestHandler = new TestingGraphMockHandler();
graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
Node newNode = mock(Node.class);
Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(300d, 400d));
View viewNewNode = mock(View.class);
when(newNode.getContent()).thenReturn(viewNewNode);
when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
when(graphBoundsIndexer.getAt(140.0, 0.0, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
graphInstance.startNode.getOutEdges().clear();
Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
assertTrue(next.getY() > sizeIntermNode[1]);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class AbstractGraphCommandTest method mockBounds.
public static Bounds mockBounds(final double x, final double y, final double w, final double h) {
Bounds bounds = mock(Bounds.class);
Bounds.Bound boundUL = mock(Bounds.Bound.class);
Bounds.Bound boundLR = mock(Bounds.Bound.class);
when(boundUL.getX()).thenReturn(x);
when(boundUL.getY()).thenReturn(y);
when(boundLR.getX()).thenReturn(x + w);
when(boundLR.getY()).thenReturn(y + h);
when(bounds.getLowerRight()).thenReturn(boundLR);
when(bounds.getUpperLeft()).thenReturn(boundUL);
return bounds;
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class UpdateElementPositionCommandTest method testExecute.
@Test
public void testExecute() {
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
ArgumentCaptor<Bounds> bounds = ArgumentCaptor.forClass(Bounds.class);
verify(content, times(1)).setBounds(bounds.capture());
assertEquals(CommandResult.Type.INFO, result.getType());
Bounds b = bounds.getValue();
assertEquals(UUID, tested.getUuid());
assertEquals(LOCATION, tested.getLocation());
assertEquals(PREVIOUS_LOCATION, tested.getPreviousLocation());
assertEquals(PREVIOUS_LOCATION.getY(), tested.getPreviousLocation().getY(), 0d);
assertEquals(Double.valueOf(LOCATION.getX() + W), b.getLowerRight().getX());
assertEquals(Double.valueOf(LOCATION.getY() + H), b.getLowerRight().getY());
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class GraphUtilsTest method checkBoundsExceededTest.
@Test
public void checkBoundsExceededTest() {
Bounds parentBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
Bounds childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(199d, 199d));
assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(200d, 200d));
assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(199d, 199d));
assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(200d, 200d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(199d, 199d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(50d, 49d), new BoundImpl(201d, 201d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
childBounds = new BoundsImpl(new BoundImpl(51d, 49d), new BoundImpl(201d, 201d));
assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
}
Aggregations