Search in sources :

Example 31 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation 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));
}
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 32 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AbstractGraphRuleHandlerTest method mockWithViolations.

protected RuleViolations mockWithViolations() {
    RuleViolation v1 = mock(RuleViolation.class);
    when(v1.getViolationType()).thenReturn(RuleViolation.Type.ERROR);
    RuleViolations violations = mock(RuleViolations.class);
    List<RuleViolation> result = new ArrayList<RuleViolation>(1) {

        {
            add(v1);
        }
    };
    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 33 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AbstractCanvasGraphCommand method performOperationOnGraph.

private CommandResult<CanvasViolation> performOperationOnGraph(final AbstractCanvasHandler context, final CommandOperation op) {
    // Ensure the canvas command is initialized before updating the element on the graph side.
    getCanvasCommand(context);
    // Obtain the graph execution context and execute the graph command updates.
    final GraphCommandExecutionContext graphContext = context.getGraphExecutionContext();
    if (Objects.isNull(graphContext)) {
        // skipping command in case there is no graph execution context
        return CanvasCommandResultBuilder.SUCCESS;
    }
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = getGraphCommand(context);
    CommandResult<RuleViolation> graphResult = null;
    switch(op) {
        case ALLOW:
            graphResult = graphCommand.allow(graphContext);
            break;
        case EXECUTE:
            graphResult = graphCommand.execute(graphContext);
            break;
        case UNDO:
            graphResult = graphCommand.undo(graphContext);
            break;
    }
    return new CanvasCommandResultBuilder(graphResult).build();
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 34 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class NotificationMessageUtilsTest method testRuleValidationMessage.

@Test
public void testRuleValidationMessage() {
    final RuleViolation ruleViolation = mock(RuleViolation.class);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING);
    when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1");
    final String message = NotificationMessageUtils.getRuleValidationMessage(translationService, ruleViolation);
    assertEquals("(WARNING) " + "rv1", message);
}
Also used : RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 35 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class NotificationMessageUtilsTest method testCanvasValidationMessage.

@Test
public void testCanvasValidationMessage() {
    final RuleViolation ruleViolation = mock(RuleViolation.class);
    final CanvasViolation canvasViolation = mock(CanvasViolation.class);
    when(canvasViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(canvasViolation.getRuleViolation()).thenReturn(ruleViolation);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    final Iterable<CanvasViolation> violations = Collections.singletonList(canvasViolation);
    when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
    when(translationService.getViolationMessage(eq(canvasViolation))).thenReturn("cv1");
    String message = NotificationMessageUtils.getCanvasValidationsErrorMessage(translationService, "aKey", violations);
    message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
    assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "1" + CLOSE_BRA + "(ERROR) " + "cv1" + HTML_NEW_LINE, message);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

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