use of org.kie.workbench.common.stunner.core.rule.RuleViolations in project kie-wb-common by kiegroup.
the class ElementCardinalityEvaluationHandlerTest method testMax1Ok.
@Test
@SuppressWarnings("unchecked")
public void testMax1Ok() {
final Map<String, Integer> count = new HashMap<String, Integer>(2) {
{
put(CANDIDATE_ROLE1, 0);
put(CANDIDATE_ROLE2, 0);
}
};
doReturn(count).when(tested).countLabels(any(Graph.class), anySet());
when(context.getCandidate()).thenReturn(Optional.of(candidate));
when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD));
final RuleViolations violations = tested.evaluate(RULE_MAX_1, 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 ElementCardinalityEvaluationHandlerTest method testMin1DeleteOk.
@Test
@SuppressWarnings("unchecked")
public void testMin1DeleteOk() {
final Map<String, Integer> count = new HashMap<String, Integer>(1) {
{
put(CANDIDATE_ROLE1, 2);
}
};
doReturn(count).when(tested).countLabels(any(Graph.class), anySet());
when(context.getCandidate()).thenReturn(Optional.of(candidate));
when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE));
final RuleViolations violations = tested.evaluate(RULE_MIN_1, 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 NodeDockingEvaluationHandlerTest method testEvaluateSuccess.
@Test
@SuppressWarnings("unchecked")
public void testEvaluateSuccess() {
when(context.getCandidate()).thenReturn(candidate);
final RuleViolations violations = tested.evaluate(RULE, 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 NodeDockingEvaluationHandlerTest method testEvaluateFailed.
@Test
@SuppressWarnings("unchecked")
public void testEvaluateFailed() {
when(context.getCandidate()).thenReturn(candidate);
final RuleViolations violations = tested.evaluate(RULE_INVALID, context);
assertNotNull(violations);
assertTrue(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 AbstractElementBuilderControl method allows.
@Override
@SuppressWarnings("unchecked")
public boolean allows(final ElementBuildRequest<AbstractCanvasHandler> request) {
final double x = request.getX();
final double y = request.getY();
final Object definition = request.getDefinition();
final Node<View<?>, Edge> parent = getParent(x, y);
final Set<String> labels = clientDefinitionManager.adapters().forDefinition().getLabels(definition);
final RuleSet ruleSet = canvasHandler.getRuleSet();
// Check containment rules.
if (null != parent) {
final Object parentDef = parent.getContent().getDefinition();
final Set<String> parentLabels = clientDefinitionManager.adapters().forDefinition().getLabels(parentDef);
final RuleViolations containmentViolations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.containment(parentLabels, labels));
if (!isValid(containmentViolations)) {
return false;
}
}
// Check cardinality rules.
final Map<String, Integer> graphLabelCount = GraphUtils.getLabelsCount(canvasHandler.getDiagram().getGraph(), labels);
final DefaultRuleViolations cardinalityViolations = new DefaultRuleViolations();
labels.forEach(role -> {
final Integer roleCount = Optional.ofNullable(graphLabelCount.get(role)).orElse(0);
final RuleViolations violations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.cardinality(Collections.singleton(role), roleCount, Optional.of(CardinalityContext.Operation.ADD)));
cardinalityViolations.addViolations(violations);
});
labels.stream().forEach(role -> {
});
return isValid(cardinalityViolations);
}
Aggregations