Search in sources :

Example 86 with RuleViolation

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));
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 87 with RuleViolation

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;
}
Also used : ArrayList(java.util.ArrayList) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 88 with RuleViolation

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);
}
Also used : Path(javax.validation.Path) ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

Example 89 with RuleViolation

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;
        }
    };
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 90 with RuleViolation

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;
        }
    };
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Aggregations

RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)122 Test (org.junit.Test)81 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)59 Node (org.kie.workbench.common.stunner.core.graph.Node)27 Edge (org.kie.workbench.common.stunner.core.graph.Edge)26 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)21 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)16 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)15 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)15 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)11 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 Collection (java.util.Collection)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7