Search in sources :

Example 6 with VirtualFile

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

the class LocalVirtualFileTest method locksFile.

@Test
public void locksFile() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    file.lock(0);
    assertionHelper.assertThatLockIoFileExists(file.getPath());
    assertTrue(file.isLocked());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 7 with VirtualFile

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

the class LocalVirtualFileTest method failsCopyFolderUnderNewNameWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled.

@Test
public void failsCopyFolderUnderNewNameWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile conflictFolder = targetFolder.createFolder("new_name");
    try {
        folder.copyTo(targetFolder, "new_name", false);
        thrown.expect(ConflictException.class);
    } catch (ConflictException expected) {
        assertionHelper.assertThatIoFileDoesNotExist(conflictFolder.getPath().newPath(file.getName()));
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Example 8 with VirtualFile

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

the class LocalVirtualFileTest method failsDeleteLockedFileWhenLockTokenIsInvalid.

@Test
public void failsDeleteLockedFileWhenLockTokenIsInvalid() 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();
    String invalidLockToken = invalidateLockToken(file.lock(0));
    try {
        file.delete(invalidLockToken);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
        assertionHelper.assertThatMetadataIoFileHasContent(file.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
        assertionHelper.assertThatLockIoFileExists(filePath);
    }
}
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 9 with VirtualFile

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

the class LocalVirtualFileTest method createFileTree.

private void createFileTree(VirtualFile rootOfTree, int depth) throws Exception {
    if (depth > 0) {
        VirtualFile folder = rootOfTree.createFolder(generateFolderName());
        for (int i = 0; i < 3; i++) {
            folder.createFile(generateFileName(), DEFAULT_CONTENT);
        }
        createFileTree(folder, depth - 1);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile)

Example 10 with VirtualFile

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

the class LocalVirtualFileTest method updatesFileInSearcherWhenItIsMoved.

@Test
public void updatesFileInSearcherWhenItIsMoved() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile newParent = getRoot().createFolder(generateFolderName());
    String oldPath = file.getPath().toString();
    Mockito.reset(searcher);
    VirtualFile moved = file.moveTo(newParent);
    verify(searcher).add(moved);
    verify(searcher).delete(oldPath, true);
}
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