Search in sources :

Example 1 with SimpleFileVisitor

use of org.uberfire.java.nio.file.SimpleFileVisitor in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramServiceTest method testGetAll.

@Test
public void testGetAll() {
    ArgumentCaptor<SimpleFileVisitor> visitorArgumentCaptor = ArgumentCaptor.forClass(SimpleFileVisitor.class);
    org.uberfire.java.nio.file.Path root = mock(org.uberfire.java.nio.file.Path.class);
    D diagram = mockDiagram();
    List<Pair<Path, org.uberfire.java.nio.file.Path>> visitedPaths = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Path diagramPath = mock(Path.class);
        org.uberfire.java.nio.file.Path nioDiagramPath = mock(org.uberfire.java.nio.file.Path.class);
        doReturn(nioDiagramPath).when(diagramService).convertToNioPath(diagramPath);
        doReturn(diagramPath).when(diagramService).convertToBackendPath(nioDiagramPath);
        visitedPaths.add(new Pair<>(diagramPath, nioDiagramPath));
        when(resourceType.accept(diagramPath)).thenReturn(true);
        doReturn(diagram).when(diagramService).getDiagramByPath(diagramPath);
    }
    BasicFileAttributes attrs = mock(BasicFileAttributes.class);
    when(ioService.exists(root)).thenReturn(true);
    doNothing().when(diagramService).walkFileTree(eq(root), visitorArgumentCaptor.capture());
    diagramService.getDiagramsByPath(root);
    visitedPaths.forEach(pair -> {
        visitorArgumentCaptor.getValue().visitFile(pair.getK2(), attrs);
        verify(diagramService, times(1)).getDiagramByPath(pair.getK1());
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) SimpleFileVisitor(org.uberfire.java.nio.file.SimpleFileVisitor) UUID(org.kie.workbench.common.stunner.core.util.UUID) ArrayList(java.util.ArrayList) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes) Pair(org.uberfire.commons.data.Pair) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 UUID (org.kie.workbench.common.stunner.core.util.UUID)1 Path (org.uberfire.backend.vfs.Path)1 Pair (org.uberfire.commons.data.Pair)1 SimpleFileVisitor (org.uberfire.java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)1