use of org.kie.workbench.common.stunner.core.rule.RuleViolation 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.RuleViolation 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.RuleViolation in project kie-wb-common by kiegroup.
the class NotificationMessageUtilsTest method testDiagramValidationMessage.
@Test
@SuppressWarnings("unchecked")
public void testDiagramValidationMessage() {
final ConstraintViolation<?> rootViolation = mock(ConstraintViolation.class);
final Path propertyPath = mock(Path.class);
when(propertyPath.toString()).thenReturn("path1");
when(rootViolation.getPropertyPath()).thenReturn(propertyPath);
when(rootViolation.getMessage()).thenReturn("message1");
final ModelBeanViolation beanViolation = ModelBeanViolationImpl.Builder.build(rootViolation);
final RuleViolation ruleViolation = mock(RuleViolation.class);
final DiagramElementViolation<RuleViolation> diagramViolation = mock(DiagramElementViolation.class);
when(diagramViolation.getUUID()).thenReturn("uuid1");
when(diagramViolation.getModelViolations()).thenReturn(Collections.singletonList(beanViolation));
when(diagramViolation.getGraphViolations()).thenReturn(Collections.singletonList(ruleViolation));
when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING);
when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1");
when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
String message = NotificationMessageUtils.getDiagramValidationsErrorMessage(translationService, "aKey", Collections.singleton(diagramViolation));
message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "E" + COLON + "uuid1" + CLOSE_BRA + HTML_NEW_LINE + "(WARNING) " + HTML_OPEN_COMMENT + "path1" + HTML_CLOSE_COMMENT + "message1" + HTML_NEW_LINE + "(WARNING) rv1" + HTML_NEW_LINE, message);
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AddOutputClauseCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT - dtable.getInput().size();
dtable.getOutput().add(clauseIndex, outputClause);
dtable.getRule().forEach(rule -> {
final LiteralExpression le = new LiteralExpression();
le.setText(OUTPUT_CLAUSE_DEFAULT_VALUE);
rule.getOutputEntry().add(clauseIndex, le);
});
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
final int clauseIndex = dtable.getOutput().indexOf(outputClause);
dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex));
dtable.getOutput().remove(outputClause);
return GraphCommandResultBuilder.SUCCESS;
}
};
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class DeleteInputClauseCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
final int clauseIndex = getInputClauseIndex();
dtable.getRule().forEach(row -> row.getInputEntry().remove(clauseIndex));
dtable.getInput().remove(clauseIndex);
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
final int clauseIndex = getInputClauseIndex();
dtable.getInput().add(clauseIndex, oldInputClause);
IntStream.range(0, dtable.getRule().size()).forEach(rowIndex -> {
final UnaryTests value = oldColumnData.get(rowIndex);
dtable.getRule().get(rowIndex).getInputEntry().add(clauseIndex, value);
});
return GraphCommandResultBuilder.SUCCESS;
}
};
}
Aggregations