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());
}
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());
}
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));
}
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));
}
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());
}
Aggregations