Search in sources :

Example 11 with RuleViolations

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

the class RuleExtensionMultiHandler method evaluate.

@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final RuleExtension rule, final RuleEvaluationContext context) {
    final List<RuleExtensionHandler> candidates = handlers.stream().filter(h -> isHandlerAccepted(h, rule, context)).collect(Collectors.toList());
    final DefaultRuleViolations result = new DefaultRuleViolations();
    candidates.forEach(candidate -> result.addViolations(candidate.evaluate(rule, context)));
    return result;
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) List(java.util.List) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) LinkedList(java.util.LinkedList) Collectors(java.util.stream.Collectors) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)

Example 12 with RuleViolations

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

the class AddNodeCommandTest method testNotAllowed.

@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
    final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), 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 13 with RuleViolations

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

the class DeleteConnectorCommandTest method testExecuteCheckFailed.

@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
    final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID));
    when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
    final List sourceOutEdges = mock(List.class);
    final List targetInEdges = mock(List.class);
    when(source.getOutEdges()).thenReturn(sourceOutEdges);
    when(target.getInEdges()).thenReturn(targetInEdges);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
    verify(sourceOutEdges, times(0)).remove(any(Edge.class));
    verify(targetInEdges, times(0)).remove(any(Edge.class));
    verify(graphIndex, times(0)).removeNode(any(Node.class));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graphIndex, times(0)).addNode(any(Node.class));
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) Node(org.kie.workbench.common.stunner.core.graph.Node) 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) List(java.util.List) 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) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 14 with RuleViolations

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

the class DockNodeCommandTest 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 15 with RuleViolations

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

the class SetChildNodeCommandTest 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)

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