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);
}
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));
}
}
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);
}
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);
}
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);
}
Aggregations