use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.
the class DefaultImportsEditorWidget method loadServerDataTypes.
protected void loadServerDataTypes() {
final Diagram diagram = sessionManager.getCurrentSession().getCanvasHandler().getDiagram();
final Path path = diagram.getMetadata().getPath();
dataTypeNamesService.call(path).then(serverDataTypes -> {
addDataTypes(serverDataTypes, true);
return null;
}).catch_(exception -> {
notification.fire(new NotificationEvent(StunnerFormsClientFieldsConstants.CONSTANTS.Error_retrieving_datatypes(), NotificationEvent.NotificationType.ERROR));
return null;
});
}
use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) {
ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
view = new ViewImpl<>(new Object(), Bounds.create(0.0, 0.0, 10.0, 20.0));
Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
item.setContent(view);
callback.onSuccess(item);
return null;
}
}).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
AdapterManager adapters = mock(AdapterManager.class);
DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
when(definitionAdapter.getId(any())).thenReturn(DefinitionId.build("Object"));
when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
when(adapters.forDefinition()).thenReturn(definitionAdapter);
when(adapters.forRules()).thenReturn(rulesAdapter);
when(definitionAdapter.getId(DEF)).thenReturn(DefinitionId.build(DEF_ID));
when(definitionAdapter.getLabels(DEF)).thenReturn(new String[0]);
when(clientDefinitionManager.adapters()).thenReturn(adapters);
when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
when(canvasCommandFactory.addNode(any(Node.class), any())).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
String uid = (String) invocationOnMock.getArguments()[1];
return new AddCanvasNodeCommand(node, uid);
}
});
when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
Point2D location = (Point2D) invocationOnMock.getArguments()[1];
return new UpdateElementPositionCommand(node, location);
}
});
when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
ShapeSet shapeSet = mock(ShapeSet.class);
ShapeFactory shapeFactory = mock(ShapeFactory.class);
when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
when(shapeManager.getShapeSet(any())).thenReturn(shapeSet);
when(shapeManager.getDefaultShapeSet(any())).thenReturn(shapeSet);
tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, ruleManager, canvasCommandFactory, mock(ClientTranslationMessages.class), graphBoundsIndexer, mock(EventSourceMock.class));
Diagram diagram = mock(Diagram.class);
Metadata metadata = mock(Metadata.class);
when(metadata.getCanvasRootUUID()).thenReturn("ID");
when(diagram.getMetadata()).thenReturn(metadata);
MutableIndex index = mock(MutableIndex.class);
Graph graph = mock(Graph.class);
DefinitionSet graphContent = mock(DefinitionSet.class);
when(graph.getContent()).thenReturn(graphContent);
when(index.getGraph()).thenReturn(graph);
when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.emptyList());
CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
doAnswer(invocationOnMock -> {
Command command = (Command) invocationOnMock.getArguments()[1];
command.execute(invocationOnMock.getArguments()[0]);
return null;
}).when(commandManager).execute(any(), any(Command.class));
when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
canvas = mock(AbstractCanvas.class);
canvasTransform = spy(new TransformImpl(new Point2D(0, 0), new Point2D(1, 1)));
canvasView = mock(AbstractCanvas.CanvasView.class);
canvasWidget = mock(Widget.class);
canvasElement = mock(com.google.gwt.user.client.Element.class);
document = mock(Document.class);
when(canvas.getView()).thenReturn(canvasView);
when(canvas.getTransform()).thenReturn(canvasTransform);
when(canvasView.asWidget()).thenReturn(canvasWidget);
when(canvasWidget.getElement()).thenReturn(canvasElement);
when(canvasElement.getOwnerDocument()).thenReturn(document);
canvasPanel = mock(CanvasPanel.class);
when(canvasView.getPanel()).thenReturn(canvasPanel);
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(EventSourceMock.class), null, null, null);
GraphCommandExecutionContext graphCommandExecutionContext = mock(GraphCommandExecutionContext.class);
when(graphCommandExecutionContext.getGraphIndex()).thenReturn(index);
canvasHandler.setGraphExecutionContext(() -> graphCommandExecutionContext);
canvasHandler.handle(canvas);
canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
tested.init(canvasHandler);
tested.setCommandManagerProvider(commandManagerProvider);
}
use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.
the class ProjectDiagramServiceControllerTest method testGetDiagramByPathWhenStunnerJBPMFileExists.
@Test
public void testGetDiagramByPathWhenStunnerJBPMFileExists() throws IOException {
final Path path = mockGetDiagramByPathObjects();
final Path expectedSVGPath = prepareSVGFile(path, JBPM_DIAGRAM_SVG);
prepareLoadDiagramByPath(path);
final Diagram result = diagramService.getDiagramByPath(path);
assertEquals(diagram, result);
verifyExpectedResult(path, result, expectedSVGPath, ProjectMetadata.SVGGenerator.JBPM_DESIGNER);
}
use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.
the class ProjectDiagramServiceControllerTest method testGetDiagramByPath.
@Test
@Override
public void testGetDiagramByPath() throws IOException {
final Path path = mockGetDiagramByPathObjects();
prepareLoadDiagramByPath(path);
final Diagram result = diagramService.getDiagramByPath(path);
assertEquals(diagram, result);
verifyExpectedResult(path, result, null, null);
}
use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallIntermediateCompensationEventsWithAssociations.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallIntermediateCompensationEventsWithAssociations() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_INTERMEDIATE_COMPENSATION_EVENTS_WITH_ASSOCIATION);
assertDiagram(diagram, 6);
assertEquals("IntermediateCompensationEventsWithAssociation", diagram.getMetadata().getTitle());
Node<? extends Definition, ?> catchingEventNode = diagram.getGraph().getNode("_DF70C614-A641-4109-8A8D-506B15E3F31B");
assertNotNull(catchingEventNode);
IntermediateCompensationEvent intermediateCompensationEvent = (IntermediateCompensationEvent) catchingEventNode.getContent().getDefinition();
assertTrue(GraphUtils.isDockedNode(catchingEventNode));
assertNotNull(intermediateCompensationEvent.getGeneral());
assertEquals("IntermediateCompensationEventName", intermediateCompensationEvent.getGeneral().getName().getValue());
assertEquals("IntermediateCompensationEventDocumentation", intermediateCompensationEvent.getGeneral().getDocumentation().getValue());
assertEquals("12/25/1983", intermediateCompensationEvent.getExecutionSet().getSlaDueDate().getValue());
Node<? extends Definition, ?> userTask1Node = diagram.getGraph().getNode("_C18CC8D2-D7CA-457D-9258-01D1E6973A86");
assertNotNull(userTask1Node);
UserTask userTask1 = (UserTask) userTask1Node.getContent().getDefinition();
assertEquals("Task1", userTask1.getGeneral().getName().getValue());
assertEquals("Task1Documentation", userTask1.getGeneral().getDocumentation().getValue());
assertEquals(userTask1Node, GraphUtils.getDockParent(catchingEventNode).orElse(null));
Node<? extends Definition, ?> userTask2Node = diagram.getGraph().getNode("_7EF24042-BD4E-4843-9874-8AC3F7AFF3CD");
assertNotNull(userTask2Node);
UserTask userTask2 = (UserTask) userTask2Node.getContent().getDefinition();
assertEquals("Task2", userTask2.getGeneral().getName().getValue());
assertEquals("Task2Documentation", userTask2.getGeneral().getDocumentation().getValue());
Edge associationEdge = userTask2Node.getInEdges().stream().filter(edge -> edge.getUUID().equals("_B41D28D1-FC39-40E8-BF89-C57649989014")).map(e -> e.asEdge()).findFirst().orElse(null);
assertNotNull(associationEdge);
assertNotNull(associationEdge.getContent());
Association association = (Association) ((View) associationEdge.getContent()).getDefinition();
assertEquals("AssociationDocumentation", association.getGeneral().getDocumentation().getValue());
assertEquals(associationEdge.getSourceNode(), catchingEventNode);
assertEquals(associationEdge.getTargetNode(), userTask2Node);
}
Aggregations