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));
}
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;
}
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();
}
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);
}
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);
}
Aggregations