Search in sources :

Example 16 with RuleViolations

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

the class SetChildNodeCommandTest method testExecuteCheckFailed.

@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
    final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID));
    when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
    assertTrue(parent.getOutEdges().isEmpty());
    assertTrue(candidate.getInEdges().isEmpty());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 17 with RuleViolations

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

the class SetParentNodeCommandTest method testNotAllowed.

@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
    final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID));
    when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
    CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 18 with RuleViolations

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

the class RuleExtensionMultiHandlerTest method testEvaluateAll.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateAll() {
    when(handler1.accepts(eq(rule1), eq(context))).thenReturn(true);
    when(handler2.accepts(eq(rule1), eq(context))).thenReturn(true);
    when(handler1.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    when(handler2.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    final RuleViolations result = tested.evaluate(rule1, context);
    assertNotNull(result);
    final Collection<RuleViolation> violations = (Collection<RuleViolation>) result.violations();
    assertTrue(violations.size() == 2);
    assertTrue(violations.contains(violation1));
    assertTrue(violations.contains(violation1));
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 19 with RuleViolations

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

the class RuleExtensionMultiHandlerTest method testEvaluateOnlyOne.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateOnlyOne() {
    when(handler1.accepts(eq(rule1), eq(context))).thenReturn(true);
    when(handler2.accepts(eq(rule1), eq(context))).thenReturn(false);
    when(handler1.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    when(handler2.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    final RuleViolations result = tested.evaluate(rule1, context);
    assertNotNull(result);
    final Collection<RuleViolation> violations = (Collection<RuleViolation>) result.violations();
    assertTrue(violations.size() == 1);
    assertTrue(violations.contains(violation1));
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 20 with RuleViolations

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

the class ConnectorParentsMatchConnectionHandlerTest method assertEvalSuccess.

private void assertEvalSuccess(final Optional<Node<? extends View<?>, ? extends Edge>> source, final Optional<Node<? extends View<?>, ? extends Edge>> target) {
    when(connectionContext.getSource()).thenReturn(source);
    when(connectionContext.getTarget()).thenReturn(target);
    when(ruleExtension.getTypeArguments()).thenReturn(new Class[] { ParentDefinition.class });
    final RuleViolations violations = tested.evaluate(ruleExtension, connectionContext);
    assertNotNull(violations);
    assertFalse(violations.violations(Violation.Type.ERROR).iterator().hasNext());
}
Also used : RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations)

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