Search in sources :

Example 71 with RuleViolations

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

the class ElementCardinalityEvaluationHandlerTest method testMax0Failed.

@Test
@SuppressWarnings("unchecked")
public void testMax0Failed() {
    final Map<String, Integer> count = new HashMap<String, Integer>(1) {

        {
            put(CANDIDATE_ROLE1, 0);
        }
    };
    doReturn(count).when(tested).countLabels(any(Graph.class), anySet());
    when(context.getCandidate()).thenReturn(Optional.of(candidate));
    when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
    final RuleViolations violations = tested.evaluate(RULE_MAX_0, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) HashMap(java.util.HashMap) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Test(org.junit.Test)

Example 72 with RuleViolations

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

the class ElementCardinalityEvaluationHandlerTest method testMax0EvaluateFailed.

@Test
@SuppressWarnings("unchecked")
public void testMax0EvaluateFailed() {
    final Map<String, Integer> count = new HashMap<String, Integer>(1) {

        {
            put(CANDIDATE_ROLE1, 1);
        }
    };
    doReturn(count).when(tested).countLabels(any(Graph.class), anySet());
    when(context.getCandidate()).thenReturn(Optional.empty());
    when(context.getOperation()).thenReturn(Optional.empty());
    final RuleViolations violations = tested.evaluate(RULE_MAX_0, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) HashMap(java.util.HashMap) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Test(org.junit.Test)

Example 73 with RuleViolations

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

the class ElementCardinalityEvaluationHandlerTest method testMin1DeleteFailed.

@Test
@SuppressWarnings("unchecked")
public void testMin1DeleteFailed() {
    final Map<String, Integer> count = new HashMap<String, Integer>(2) {

        {
            put(CANDIDATE_ROLE1, 1);
            put(CANDIDATE_ROLE2, 0);
        }
    };
    doReturn(count).when(tested).countLabels(any(Graph.class), anySet());
    when(context.getCandidate()).thenReturn(Optional.of(candidate));
    when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE));
    final RuleViolations violations = tested.evaluate(RULE_MIN_1, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) HashMap(java.util.HashMap) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Test(org.junit.Test)

Example 74 with RuleViolations

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

the class NodeContainmentEvaluationHandlerTest method testEvaluateFailed.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateFailed() {
    when(context.getCandidate()).thenReturn(candidate);
    final RuleViolations violations = tested.evaluate(RULE_INVALID, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Test(org.junit.Test)

Example 75 with RuleViolations

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

the class AcyclicDirectedGraphRuleTest method checkMissingConnectionNodesDoesNotTriggerGraphWalk.

@Test
@SuppressWarnings("unchecked")
public void checkMissingConnectionNodesDoesNotTriggerGraphWalk() {
    when(context.getSource()).thenReturn(Optional.empty());
    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)

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