use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class BPMNGraphFactoryImplTest method testBuild.
@Test
@SuppressWarnings("unchecked")
public void testBuild() {
final Node diagramNode = mock(Node.class);
final Node startEventNode = mock(Node.class);
when(factoryManager.newElement(anyString(), eq(BPMNDiagramImpl.class))).thenReturn(diagramNode);
when(factoryManager.newElement(anyString(), eq(StartNoneEvent.class))).thenReturn(startEventNode);
final Graph<DefinitionSet, Node> graph = tested.build("uuid1", "defSetId");
assertNotNull(graph);
assertEquals("uuid1", graph.getUUID());
assertEquals(1, graph.getLabels().size());
assertTrue(graph.getLabels().contains("defSetId"));
final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(graphCommandFactory, times(1)).addNode(eq(diagramNode));
verify(graphCommandFactory, times(1)).addChildNode(eq(diagramNode), eq(startEventNode), eq(new Point2D(BPMNGraphFactoryImpl.START_X, BPMNGraphFactoryImpl.START_Y)));
verify(graphCommandManager, times(1)).execute(any(GraphCommandExecutionContext.class), commandCaptor.capture());
final Command command = commandCaptor.getValue();
assertTrue(command instanceof CompositeCommand);
final CompositeCommand compositeCommand = (CompositeCommand) command;
assertEquals(2, compositeCommand.size());
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateGraph1.
@Test
@SuppressWarnings("unchecked")
public void testValidateGraph1() {
final RuleManager ruleManager = graphTestHandler.ruleManager;
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph1 testGraph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
tested.validate(graph, ruleSet, this::assertNoError);
final int evalCount = testGraph1.evaluationsCount + 10;
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 = testGraph1.evaluationsCount;
verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.startNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph1.edge1, testGraph1.startNode, testGraph1.intermNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.intermNode, testGraph1.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.startNode, testGraph1.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.intermNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph1.edge2, testGraph1.intermNode, testGraph1.endNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.endNode, testGraph1.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.intermNode, testGraph1.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.endNode);
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class AbstractVFSDiagramServiceTest method testGetDiagramByPath.
@Test
public void testGetDiagramByPath() throws IOException {
Path path = mock(Path.class);
when(path.toURI()).thenReturn(FILE_URI);
String fileName = FILE_NAME + "." + RESOURCE_TYPE_SUFFIX;
when(path.getFileName()).thenReturn(fileName);
when(resourceType.accept(path)).thenReturn(true);
final org.uberfire.java.nio.file.Path expectedNioPath = Paths.convert(path);
byte[] content = DIAGRAM_MARSHALLED.getBytes();
when(ioService.readAllBytes(expectedNioPath)).thenReturn(content);
Graph<DefinitionSet, ?> graph = mock(Graph.class);
DefinitionSet graphContent = mock(DefinitionSet.class);
when(graph.getContent()).thenReturn(graphContent);
when(graphContent.getDefinition()).thenReturn("DefinitionSet");
when(diagramMarshaller.unmarshall(anyObject(), anyObject())).thenReturn(graph);
DiagramFactory diagramFactory = mock(DiagramFactory.class);
when(factoryRegistry.getDiagramFactory("DefinitionSet", getMetadataType())).thenReturn(diagramFactory);
when(diagramFactory.build(eq(FILE_NAME), any(Metadata.class), eq(graph))).thenReturn(diagram);
Diagram result = diagramService.getDiagramByPath(path);
assertEquals(diagram, result);
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class CanvasHighlightVisitor method prepareVisit.
@SuppressWarnings("unchecked")
private void prepareVisit(final Command command) {
final Graph graph = canvasHandler.getDiagram().getGraph();
final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl().useStartNodePredicate(this::isStartNode);
new ViewTraverseProcessorImpl(treeWalkTraverseProcessor).traverse(graph, new ContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() {
@Override
public void startGraphTraversal(final Graph<DefinitionSet, Node<View, Edge>> graph) {
}
@Override
public void startEdgeTraversal(final Edge<View<?>, Node> edge) {
addShape(edge.getUUID());
}
@Override
public void endEdgeTraversal(final Edge<View<?>, Node> edge) {
}
@Override
public void startNodeTraversal(final Node<View, Edge> node) {
addShape(node.getUUID());
}
@Override
public void endNodeTraversal(final Node<View, Edge> node) {
}
@Override
public void endGraphTraversal() {
command.execute();
}
private void addShape(final String uuid) {
final Shape shape = canvasHandler.getCanvas().getShape(uuid);
if (null != shape) {
shapes.add(shape);
}
}
});
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet in project kie-wb-common by kiegroup.
the class UpdateElementPositionCommand method checkBounds.
@SuppressWarnings("unchecked")
private CommandResult<RuleViolation> checkBounds(final GraphCommandExecutionContext context) {
final Element<? extends View<?>> element = getNodeNotNull(context);
final Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) getGraph(context);
final BoundsImpl newBounds = getTargetBounds(element);
final GraphCommandResultBuilder result = new GraphCommandResultBuilder();
final Bounds parentBounds = getParentBounds(element, graph);
if (GraphUtils.checkBoundsExceeded(parentBounds, newBounds)) {
((View) element.getContent()).setBounds(newBounds);
} else {
result.addViolation(new BoundsExceededViolation(parentBounds).setUUID(element.getUUID()));
}
return result.build();
}
Aggregations