use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AcyclicDirectedGraphRuleTest method checkCyclicalConnection.
@Test
@SuppressWarnings("unchecked")
public void checkCyclicalConnection() {
final Node node1 = new NodeImpl<>("node1");
final Node node2 = new NodeImpl<>("node2");
final Edge c1 = new EdgeImpl<>("edge1");
node1.getOutEdges().add(c1);
node2.getInEdges().add(c1);
c1.setSourceNode(node1);
c1.setTargetNode(node2);
graph.addNode(node1);
graph.addNode(node2);
when(context.getSource()).thenReturn(Optional.of(node2));
when(context.getTarget()).thenReturn(Optional.of(node1));
when(context.getConnector()).thenReturn(connector);
final RuleViolations result = check.evaluate(rule, context);
assertNotNull(result);
assertTrue(result.violations().iterator().hasNext());
final RuleViolation violation = result.violations().iterator().next();
assertNotNull(violation);
assertTrue(violation.getArguments().isPresent());
assertEquals(1, violation.getArguments().get().length);
assertEquals(AcyclicDirectedGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.
@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
final Node node1 = new NodeImpl<>("node1");
final Node node2 = new NodeImpl<>("node2");
final Edge existingConnector = new EdgeImpl<>("edge1");
final ViewConnector existingConnectorView = mock(ViewConnector.class);
existingConnector.setContent(existingConnectorView);
when(existingConnectorView.getDefinition()).thenReturn(new Definition());
node1.getOutEdges().add(existingConnector);
node2.getInEdges().add(existingConnector);
existingConnector.setSourceNode(node1);
existingConnector.setTargetNode(node2);
graph.addNode(node1);
graph.addNode(node2);
when(context.getSource()).thenReturn(Optional.of(node1));
when(context.getTarget()).thenReturn(Optional.of(node2));
when(context.getConnector()).thenReturn(connector);
final RuleViolations result = check.evaluate(rule, context);
assertNotNull(result);
assertTrue(result.violations().iterator().hasNext());
final RuleViolation violation = result.violations().iterator().next();
assertNotNull(violation);
assertTrue(violation.getArguments().isPresent());
assertEquals(1, violation.getArguments().get().length);
assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateEmptyViewConnectorNodes.
@Test
@SuppressWarnings("unchecked")
public void testValidateEmptyViewConnectorNodes() {
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph1 testGraph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
// Update the edge2 and remove the connection's target node.
// From this point, a validation error is expected.
graphTestHandler.removeTargetConnection(testGraph1.edge2);
tested.validate(graph, ruleSet, ruleViolations -> {
assertEquals(1, ruleViolations.size());
final RuleViolation violation = ruleViolations.iterator().next();
assertNotNull(violation);
assertTrue(violation instanceof EmptyConnectionViolation);
EmptyConnectionViolation v = (EmptyConnectionViolation) violation;
final Optional<Object[]> arguments = v.getArguments();
assertTrue(arguments.isPresent());
assertEquals(testGraph1.edge2.getUUID(), arguments.get()[0]);
assertEquals(testGraph1.intermNode.getUUID(), arguments.get()[1]);
assertNull(arguments.get()[2]);
});
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AbstractProjectDiagramEditor method save.
/**
* This method is called just once clicking on save.
* Before starting the save process, let's perform a diagram validation
* to check all it's valid.
* It's allowed to continue with the save process event if warnings found,
* but cannot save if any error is present in order to
* guarantee the diagram's consistency.
*/
@Override
protected void save() {
final Command continueSaveOnceValid = () -> super.save();
getCommand(ValidateSessionCommand.class).execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
continueSaveOnceValid.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (maxSeverity.equals(Violation.Type.ERROR)) {
onValidationFailed(violations);
} else {
// Allow saving when only warnings founds.
continueSaveOnceValid.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AddNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> parentResult = super.check(context);
final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
parentResult.getViolations().forEach(builder::addViolation);
final Element<? extends Definition<?>> graph = (Element<? extends Definition<?>>) getGraph(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), graph, getCandidate()));
builder.addViolations(containmentRuleViolations);
return builder.build();
}
Aggregations