Search in sources :

Example 1 with NodeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.NodeImpl in project kie-wb-common by kiegroup.

the class AcyclicDirectedGraphRuleTest method checkCyclicalConnection.

@Test
@SuppressWarnings("unchecked")
public void checkCyclicalConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge c1 = new EdgeImpl<>("edge1");
    node1.getOutEdges().add(c1);
    node2.getInEdges().add(c1);
    c1.setSourceNode(node1);
    c1.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node2));
    when(context.getTarget()).thenReturn(Optional.of(node1));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(AcyclicDirectedGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 2 with NodeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.NodeImpl in project kie-wb-common by kiegroup.

the class BaseGraphRuleTest method checkNoViolationsWhenNoExistingConnections.

@Test
@SuppressWarnings("unchecked")
public void checkNoViolationsWhenNoExistingConnections() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node1));
    when(context.getTarget()).thenReturn(Optional.of(node2));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertFalse(result.violations().iterator().hasNext());
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Test(org.junit.Test)

Example 3 with NodeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.NodeImpl in project kie-wb-common by kiegroup.

the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.

@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge existingConnector = new EdgeImpl<>("edge1");
    final ViewConnector existingConnectorView = mock(ViewConnector.class);
    existingConnector.setContent(existingConnectorView);
    when(existingConnectorView.getDefinition()).thenReturn(new Definition());
    node1.getOutEdges().add(existingConnector);
    node2.getInEdges().add(existingConnector);
    existingConnector.setSourceNode(node1);
    existingConnector.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node1));
    when(context.getTarget()).thenReturn(Optional.of(node2));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 4 with NodeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.NodeImpl in project kie-wb-common by kiegroup.

the class FormsContainerTest method testDestroyOneDisplayer.

@Test
public void testDestroyOneDisplayer() {
    NodeImpl firstNode = getNode(FIRST_ELEMENT_UID);
    FormDisplayer firstDisplayer = testRender(firstNode, 1, 1);
    NodeImpl secondNode = getNode(SECOND_ELEMENT_UID);
    FormDisplayer secondDisplayer = testRender(secondNode, 2, 1);
    formsContainer.clearFormDisplayer(GRAPH_UID, FIRST_ELEMENT_UID);
    verify(firstDisplayer, times(3)).hide();
    verify(view, times(1)).removeDisplayer(firstDisplayer);
    verify(displayersInstance, times(1)).destroy(firstDisplayer);
    verify(secondDisplayer, times(1)).hide();
    verify(view, never()).removeDisplayer(secondDisplayer);
    verify(displayersInstance, never()).destroy(secondDisplayer);
    formsContainer.clearFormDisplayer(GRAPH_UID, SECOND_ELEMENT_UID);
    verify(secondDisplayer, times(2)).hide();
    verify(view, times(1)).removeDisplayer(secondDisplayer);
    verify(displayersInstance, times(1)).destroy(secondDisplayer);
}
Also used : FormDisplayer(org.kie.workbench.common.stunner.forms.client.widgets.container.displayer.FormDisplayer) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Test(org.junit.Test)

Example 5 with NodeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.NodeImpl in project kie-wb-common by kiegroup.

the class FormsContainerTest method getNode.

protected NodeImpl getNode(final String uuid) {
    NodeImpl node = mock(NodeImpl.class);
    when(node.getUUID()).thenReturn(uuid);
    return node;
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)

Aggregations

NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)22 Test (org.junit.Test)18 Edge (org.kie.workbench.common.stunner.core.graph.Edge)9 GraphImpl (org.kie.workbench.common.stunner.core.graph.impl.GraphImpl)7 GraphNodeStoreImpl (org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl)7 Node (org.kie.workbench.common.stunner.core.graph.Node)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)4 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)4 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)4 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)4 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)3 Consumer (java.util.function.Consumer)2 FlowElement (org.eclipse.bpmn2.FlowElement)2 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)2 RootElement (org.eclipse.bpmn2.RootElement)2 ExclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway)2 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)2