Search in sources :

Example 56 with RuleViolations

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

the class ConnectionEvaluationHandlerTest method testEvaluateFailed2.

@Test
public void testEvaluateFailed2() {
    final Set<String> sourceRoles = new HashSet<String>(1) {

        {
            add("r2");
        }
    };
    final Set<String> targetRoles = new HashSet<String>(1) {

        {
            add("o1");
        }
    };
    when(context.getConnectorRole()).thenReturn(EDGE_ID);
    when(context.getSourceRoles()).thenReturn(Optional.of(sourceRoles));
    when(context.getTargetRoles()).thenReturn(Optional.of(targetRoles));
    final RuleViolations violations = tested.evaluate(RULE, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with RuleViolations

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

the class ConnectorCardinalityEvaluationHandlerTest method testEvaluateInNoLimit.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateInNoLimit() {
    when(evalUtils.countEdges(anyString(), any(List.class))).thenReturn(0);
    when(context.getDirection()).thenReturn(EdgeCardinalityContext.Direction.INCOMING);
    when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
    RuleViolations violations = tested.evaluate(RULE_IN_NO_LIMIT, context);
    assertNotNull(violations);
    assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) List(java.util.List) Test(org.junit.Test)

Example 58 with RuleViolations

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

the class ConnectorCardinalityEvaluationHandlerTest method testEvaluateInMaxOneSucess.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateInMaxOneSucess() {
    when(evalUtils.countEdges(anyString(), any(List.class))).thenReturn(0);
    when(context.getDirection()).thenReturn(EdgeCardinalityContext.Direction.INCOMING);
    when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
    RuleViolations violations = tested.evaluate(RULE_IN_MAX_1, context);
    assertNotNull(violations);
    assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) List(java.util.List) Test(org.junit.Test)

Example 59 with RuleViolations

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

the class ConnectorCardinalityEvaluationHandlerTest method testEvaluateInMinOneFailed.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateInMinOneFailed() {
    when(evalUtils.countEdges(anyString(), any(List.class))).thenReturn(1);
    when(context.getDirection()).thenReturn(EdgeCardinalityContext.Direction.INCOMING);
    when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE));
    RuleViolations violations = tested.evaluate(RULE_IN_MIN_1, context);
    assertNotNull(violations);
    assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) List(java.util.List) Test(org.junit.Test)

Example 60 with RuleViolations

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

the class ContainmentEvaluationHandlerTest method testEvaluateSuccess.

@Test
public void testEvaluateSuccess() {
    final Set<String> candidateRoles = new HashSet<String>(1) {

        {
            add("role2");
        }
    };
    when(context.getParentRoles()).thenReturn(PARENT_ROLES);
    when(context.getCandidateRoles()).thenReturn(candidateRoles);
    final RuleViolations violations = tested.evaluate(RULE, context);
    assertNotNull(violations);
    assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) HashSet(java.util.HashSet) 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