use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.
the class RuleExtensionMultiHandlerTest method testEvaluateOnlyTwo.
@Test
@SuppressWarnings("unchecked")
public void testEvaluateOnlyTwo() {
when(handler1.accepts(eq(rule1), eq(context))).thenReturn(false);
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() == 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 testFailEvaluateParentDefinition.
@Test
@SuppressWarnings("unchecked")
public void testFailEvaluateParentDefinition() {
when(connectionContext.getSource()).thenReturn(Optional.of(nodeA));
when(connectionContext.getTarget()).thenReturn(Optional.of(nodeC));
when(ruleExtension.getTypeArguments()).thenReturn(new Class[] { ParentDefinition.class });
final RuleViolations violations = tested.evaluate(ruleExtension, connectionContext);
assertNotNull(violations);
assertTrue(violations.violations(Violation.Type.ERROR).iterator().hasNext());
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.
the class AbstractGraphRuleHandlerTest method mockNoViolations.
protected RuleViolations mockNoViolations() {
RuleViolations violations = mock(RuleViolations.class);
List<RuleViolation> result = new ArrayList<>(0);
when(violations.violations(eq(RuleViolation.Type.ERROR))).thenReturn(result);
return violations;
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.
the class CardinalityEvaluationHandlerTest method testEvaluateNoLimit.
@Test
public void testEvaluateNoLimit() {
when(context.getCandidateCount()).thenReturn(0);
when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
RuleViolations violations = tested.evaluate(RULE_NO_LIMIT, context);
assertNotNull(violations);
assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
when(context.getCandidateCount()).thenReturn(100);
when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
violations = tested.evaluate(RULE_NO_LIMIT, context);
assertNotNull(violations);
assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext());
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.
the class ConnectionEvaluationHandlerTest method testEvaluateFailed1.
@Test
public void testEvaluateFailed1() {
final Set<String> sourceRoles = new HashSet<String>(1) {
{
add("r1");
}
};
final Set<String> targetRoles = new HashSet<String>(1) {
{
add("o2");
}
};
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());
}
Aggregations