Search in sources :

Example 6 with ContainmentRuleViolation

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

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

the class ContainmentEvaluationHandler method evaluate.

@Override
public RuleViolations evaluate(final CanContain rule, final ContainmentContext context) {
    final DefaultRuleViolations results = new DefaultRuleViolations();
    final boolean present = context.getCandidateRoles().stream().filter(cr -> rule.getAllowedRoles().contains(cr)).findAny().isPresent();
    if (!present) {
        results.addViolation(new ContainmentRuleViolation(rule.getRole(), context.getCandidateRoles().toString()));
    }
    return results;
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)

Example 8 with ContainmentRuleViolation

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

the class AddChildNodeCommandTest 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 9 with ContainmentRuleViolation

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

the class AddNodeCommandTest 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);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
    verify(graph, times(0)).addNode(eq(node));
    verify(graphIndex, times(0)).addNode(eq(node));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graph, times(0)).removeNode(eq(UUID));
    verify(graphIndex, times(0)).removeNode(eq(node));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
}
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) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 10 with ContainmentRuleViolation

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

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

Aggregations

ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)12 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)12 Test (org.junit.Test)11 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)11 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)11 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)11 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)11 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 List (java.util.List)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1