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