Search in sources :

Example 51 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class MemoryVirtualFileTest method copiesFolderAndReplaceExistedItem.

@Test
public void copiesFolderAndReplaceExistedItem() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    targetFolder.createFolder(folder.getName());
    VirtualFile copiedFolder = folder.copyTo(targetFolder, null, true);
    assertNotNull(getRoot().getChild(copiedFolder.getPath()));
    VirtualFile copiedFile = copiedFolder.getChild(Path.of(file.getName()));
    assertEquals(file.getContentAsString(), copiedFile.getContentAsString());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 52 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class MemoryVirtualFileTest method failsDeleteLockedFileWithoutLockToken.

@Test
public void failsDeleteLockedFileWithoutLockToken() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    file.lock(0);
    try {
        file.delete();
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertEquals(file, getRoot().getChild(filePath));
        assertTrue(file.isLocked());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 53 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class MemoryVirtualFileTest method getFileTreeAsList.

private List<VirtualFile> getFileTreeAsList(VirtualFile rootOfTree) throws Exception {
    List<VirtualFile> list = newArrayList();
    rootOfTree.accept(new VirtualFileVisitor() {

        @Override
        public void visit(VirtualFile virtualFile) throws ServerException {
            list.add(virtualFile);
            if (virtualFile.isFolder()) {
                for (VirtualFile child : virtualFile.getChildren()) {
                    child.accept(this);
                }
            }
        }
    });
    return list;
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor)

Example 54 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class MemoryVirtualFileTest method renamesFolder.

@Test
public void renamesFolder() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    Path folderPath = folder.getPath();
    folder.setProperty("property1", "value1");
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    String fileName = file.getName();
    file.setProperty("property2", "value2");
    VirtualFile renamed = folder.rename("new_name");
    assertNotNull(getRoot().getChild(renamed.getPath()));
    assertEquals(ImmutableMap.of("property1", "value1"), renamed.getProperties());
    Path newFilePath = renamed.getPath().newPath(fileName);
    assertEquals(DEFAULT_CONTENT, getRoot().getChild(newFilePath).getContentAsString());
    assertEquals(ImmutableMap.of("property2", "value2"), getRoot().getChild(newFilePath).getProperties());
    assertNull(getRoot().getChild(folderPath.newPath(fileName)));
    assertNull(getRoot().getChild(folderPath));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 55 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class MemoryVirtualFileTest method removesDeletedFolderFromSearcher.

@Test
public void removesDeletedFolderFromSearcher() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    String path = folder.getPath().toString();
    folder.delete();
    verify(searcher).delete(path, false);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Aggregations

VirtualFile (org.eclipse.che.api.vfs.VirtualFile)321 Test (org.junit.Test)267 Path (org.eclipse.che.api.vfs.Path)62 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)54 ByteArrayInputStream (java.io.ByteArrayInputStream)32 ConflictException (org.eclipse.che.api.core.ConflictException)28 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)27 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)22 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)22 ServerException (org.eclipse.che.api.core.ServerException)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Archiver (org.eclipse.che.api.vfs.Archiver)14 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 OutputStream (java.io.OutputStream)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Map (java.util.Map)5