Search in sources :

Example 11 with DefinitionSet

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());
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Test(org.junit.Test)

Example 12 with DefinitionSet

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);
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Test(org.junit.Test)

Example 13 with DefinitionSet

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);
}
Also used : Path(org.uberfire.backend.vfs.Path) DiagramFactory(org.kie.workbench.common.stunner.core.factory.diagram.DiagramFactory) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with DefinitionSet

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);
            }
        }
    });
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ViewTraverseProcessorImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 15 with DefinitionSet

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();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)15 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Graph (org.kie.workbench.common.stunner.core.graph.Graph)6 Test (org.junit.Test)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)4 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)4 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)3 TreeWalkTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)3 Command (org.kie.workbench.common.stunner.core.command.Command)2 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)2 TreeNode (com.fasterxml.jackson.core.TreeNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1