Search in sources :

Example 1 with RuleViolations

use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.

the class AcyclicDirectedGraphRuleTest method checkMissingConnectionTargetNodeDoesNotTriggerGraphWalk.

@Test
@SuppressWarnings("unchecked")
public void checkMissingConnectionTargetNodeDoesNotTriggerGraphWalk() {
    final Node source = mock(Node.class);
    when(context.getSource()).thenReturn(Optional.of(source));
    when(context.getTarget()).thenReturn(Optional.empty());
    when(context.getConnector()).thenReturn(connector);
    when(check.getTreeWalker(any(Node.class), any(Node.class), any(Edge.class))).thenReturn(walker);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertFalse(result.violations().iterator().hasNext());
    verify(walker, never()).traverse(any(Graph.class), any(TreeTraverseCallback.class));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) TreeTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeTraverseCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 2 with RuleViolations

use of org.kie.workbench.common.stunner.core.rule.RuleViolations 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 3 with RuleViolations

use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.

the class AcyclicDirectedGraphRuleTest method checkCompleteConnectionDefinitionTriggersGraphWalk.

@Test
@SuppressWarnings("unchecked")
public void checkCompleteConnectionDefinitionTriggersGraphWalk() {
    final Node source = mock(Node.class);
    final Node target = mock(Node.class);
    when(context.getSource()).thenReturn(Optional.of(source));
    when(context.getTarget()).thenReturn(Optional.of(target));
    when(context.getConnector()).thenReturn(connector);
    when(check.getTreeWalker(any(Node.class), any(Node.class), any(Edge.class))).thenReturn(walker);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertFalse(result.violations().iterator().hasNext());
    verify(walker).traverse(eq(graph), any(TreeTraverseCallback.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) TreeTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeTraverseCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 4 with RuleViolations

use of org.kie.workbench.common.stunner.core.rule.RuleViolations 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 5 with RuleViolations

use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.

the class SingleConnectorPerTypeGraphRuleTest method checkMissingConnectionNodesDoesNotTriggerCheck.

@Test
@SuppressWarnings("unchecked")
public void checkMissingConnectionNodesDoesNotTriggerCheck() {
    when(context.getSource()).thenReturn(Optional.empty());
    when(context.getTarget()).thenReturn(Optional.empty());
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertFalse(result.violations().iterator().hasNext());
    verify(check, never()).isConnectionAlreadyFormed(any(Node.class), any(Node.class), any(Edge.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Aggregations

RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)76 Test (org.junit.Test)68 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)20 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)19 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)16 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Graph (org.kie.workbench.common.stunner.core.graph.Graph)13 Node (org.kie.workbench.common.stunner.core.graph.Node)12 HashMap (java.util.HashMap)11 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)11 HashSet (java.util.HashSet)8 List (java.util.List)7 Collection (java.util.Collection)3 AbstractGraphDefinitionTypesTest (org.kie.workbench.common.stunner.core.AbstractGraphDefinitionTypesTest)3 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)3 TreeTraverseCallback (org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeTraverseCallback)3 ArrayList (java.util.ArrayList)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)2