Search in sources :

Example 51 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramEditorTest method testGetOnStartupDiagramEditorCallback.

@Test
public void testGetOnStartupDiagramEditorCallback() {
    final Diagram diagram = mock(Diagram.class);
    final Metadata metadata = mock(Metadata.class);
    final String title = "title";
    doNothing().when(editor).updateTitle(Mockito.<String>any());
    doReturn(diagram).when(editor).getDiagram();
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getTitle()).thenReturn(title);
    editor.getOnStartupDiagramEditorCallback().execute();
    verify(editor).updateTitle(title);
    verify(documentationView).initialize(diagram);
}
Also used : Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 52 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class CanvasDiagramValidator method checkViolations.

@SuppressWarnings("unchecked")
private void checkViolations(final H canvasHandler, final Collection<DiagramElementViolation<RuleViolation>> elementViolations) {
    final String uuid = canvasHandler.getUuid();
    final Diagram diagram = canvasHandler.getDiagram();
    final String name = diagram.getName();
    final String title = diagram.getMetadata().getTitle();
    final Stream<ElementViolation> violationsStream = getElementViolationsStream(elementViolations);
    final List<ElementViolation> violationsList = violationsStream.collect(Collectors.toList());
    final boolean valid = violationsList.stream().noneMatch(v -> applyViolation(canvasHandler, v));
    if (valid) {
        validationSuccessEvent.fire(new CanvasValidationSuccessEvent(uuid, name, title));
    } else {
        validationFailEvent.fire(new CanvasValidationFailEvent(uuid, name, title, elementViolations));
    }
}
Also used : ElementViolation(org.kie.workbench.common.stunner.core.validation.ElementViolation) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 53 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DeleteNodeConfirmationImplTest method testInit.

@Test
public void testInit() {
    final ClientSession session = mock(ClientSession.class);
    final CanvasHandler canvasHandler = mock(CanvasHandler.class);
    final Diagram diagram = mock(Diagram.class);
    final Metadata metadata = mock(Metadata.class);
    final String definitionId = "definitionId";
    final Annotation qualifier = mock(Annotation.class);
    final ManagedInstance<GraphsProvider> foundInstances = mock(ManagedInstance.class);
    final GraphsProvider foundInstance = mock(GraphsProvider.class);
    when(foundInstances.isUnsatisfied()).thenReturn(false);
    when(foundInstances.get()).thenReturn(foundInstance);
    when(graphsProviderInstances.select(GraphsProvider.class, qualifier)).thenReturn(foundInstances);
    when(definitionUtils.getQualifier(definitionId)).thenReturn(qualifier);
    when(metadata.getDefinitionSetId()).thenReturn(definitionId);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(sessionManager.getCurrentSession()).thenReturn(session);
    confirmation.init();
    final GraphsProvider actualProvider = confirmation.getGraphsProvider();
    assertEquals(actualProvider, foundInstance);
}
Also used : ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) GraphsProvider(org.kie.workbench.common.stunner.core.diagram.GraphsProvider) Annotation(java.lang.annotation.Annotation) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 54 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
    when(rootElement.getUUID()).thenReturn(ROOT_UUID);
    when(rootElement.getContent()).thenReturn(new ViewImpl<>(rootDefinition, Bounds.create(0, 0, 10, 10)));
    when(element.getUUID()).thenReturn(ELEMENT_UUID);
    when(element.getContent()).thenReturn(new ViewImpl<>(definition, Bounds.create(0, 0, 10, 10)));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
    when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
    when(shape.getUUID()).thenReturn(ELEMENT_UUID);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
    this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
    this.tested.setReadonly(false);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) HasControlPoints(org.kie.workbench.common.stunner.core.client.shape.view.HasControlPoints) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Sets(org.kie.soup.commons.util.Sets) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Captor(org.mockito.Captor) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ArgumentCaptor(org.mockito.ArgumentCaptor) CanvasShapeRemovedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent) ShapeState(org.kie.workbench.common.stunner.core.client.shape.ShapeState) Element(org.kie.workbench.common.stunner.core.graph.Element) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) ViewEventType(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEventType) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Mockito.never(org.mockito.Mockito.never) Assert.assertFalse(org.junit.Assert.assertFalse) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) Optional(java.util.Optional) EventSourceMock(org.uberfire.mocks.EventSourceMock) Collections(java.util.Collections) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) Before(org.junit.Before)

Example 55 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DiagramMarshallerTest method unmarshallWithValidationError.

@Test
public void unmarshallWithValidationError() throws Exception {
    tested = spy(new DiagramMarshaller() {

        @Override
        public Graph unmarshall(Metadata metadata, InputStream input) {
            throw new RuntimeException(MESSAGE);
        }

        @Override
        public String marshall(Diagram diagram) {
            return null;
        }

        @Override
        public DiagramMetadataMarshaller getMetadataMarshaller() {
            return null;
        }
    });
    final MarshallingResponse response = tested.unmarshallWithValidation(request);
    verify(tested).unmarshall(metadata, input);
    assertNull(response.getResult());
    assertEquals(response.getState(), MarshallingResponse.State.ERROR);
    assertEquals(response.getMessages().size(), 1);
    final MarshallingMessage marshallingMessage = (MarshallingMessage) response.getMessages().stream().findFirst().get();
    assertEquals(marshallingMessage.getMessage(), MESSAGE);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) InputStream(java.io.InputStream) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Aggregations

Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)128 Test (org.junit.Test)64 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)48 Node (org.kie.workbench.common.stunner.core.graph.Node)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)31 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)23 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)22 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Inject (javax.inject.Inject)15 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)15 Before (org.junit.Before)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 Map (java.util.Map)13 Optional (java.util.Optional)13 Collectors (java.util.stream.Collectors)13 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)13 Collection (java.util.Collection)12