use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet 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.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateGraph2.
@Test
@SuppressWarnings("unchecked")
public void testValidateGraph2() {
final RuleManager ruleManager = graphTestHandler.ruleManager;
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph2 testGraph2 = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
tested.validate(getGraph(), graphTestHandler.ruleSet, this::assertNoError);
final int evalCount = testGraph2.evaluationsCount + 11;
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(evalCount)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(evalCount, contexts.size());
int cindex = testGraph2.evaluationsCount;
verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph2.parentNode);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.startNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge1, testGraph2.startNode, testGraph2.intermNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.startNode, testGraph2.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.intermNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge2, testGraph2.intermNode, testGraph2.endNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.endNode, testGraph2.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.endNode);
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class GraphImpl method hashCode.
@Override
public int hashCode() {
// dirty trick to allow inner class to modify variable
int[] hashArr = { 0 };
final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl();
treeWalkTraverseProcessor.traverse(this, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {
int[] myHashArr = hashArr;
@Override
public boolean startEdgeTraversal(final Edge edge) {
super.startEdgeTraversal(edge);
final Object content = edge.getContent();
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], content.hashCode());
return true;
}
@Override
public boolean startNodeTraversal(final Node node) {
super.startNodeTraversal(node);
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], node.hashCode());
if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
Object def = ((Definition) (node.getContent())).getDefinition();
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], def.hashCode());
}
return true;
}
});
// Get the hash from the graph traversal
return hashArr[0];
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class AbstractGraphFactory method build.
@Override
@SuppressWarnings("unchecked ")
public Graph<DefinitionSet, Node> build(final String uuid, final String definitionSetId) {
final GraphImpl graph = new GraphImpl<>(uuid, new GraphNodeStoreImpl());
final DefinitionSet content = new DefinitionSetImpl(definitionSetId);
graph.setContent(content);
graph.getLabels().add(definitionSetId);
content.setBounds(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(getWidth(), getHeight())));
return graph;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class LocationControlImpl method getLocationBounds.
@SuppressWarnings("unchecked")
private double[] getLocationBounds() {
final Graph<DefinitionSet, ? extends Node> graph = canvasHandler.getDiagram().getGraph();
final Bounds bounds = graph.getContent().getBounds();
return new double[] { bounds.getUpperLeft().getX(), bounds.getUpperLeft().getY(), bounds.getLowerRight().getX(), bounds.getLowerRight().getY() };
}
Aggregations