Search in sources :

Example 1 with DiagramFactory

use of org.kie.workbench.common.stunner.core.factory.diagram.DiagramFactory 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)

Aggregations

Test (org.junit.Test)1 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1 DiagramFactory (org.kie.workbench.common.stunner.core.factory.diagram.DiagramFactory)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Path (org.uberfire.backend.vfs.Path)1