Search in sources :

Example 66 with VirtualFile

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

the class LocalVirtualFileTest 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) {
        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 67 with VirtualFile

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

the class LocalVirtualFileTest method unlocksFile.

@Test
public void unlocksFile() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    String lockToken = file.lock(0);
    file.unlock(lockToken);
    assertionHelper.assertThatLockIoFileDoesNotExist(file.getPath());
    assertFalse(file.isLocked());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 68 with VirtualFile

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

the class LocalVirtualFileTest method failsMoveFileWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled.

@Test
public void failsMoveFileWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    Path filePath = file.getPath();
    VirtualFile existedFile = targetFolder.createFile("existed_name", "existed content");
    try {
        file.moveTo(targetFolder, "existed_name", false, null);
        thrown.expect(ConflictException.class);
    } catch (ConflictException e) {
        assertEquals(file, getRoot().getChild(filePath));
        assertEquals("existed content", existedFile.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Example 69 with VirtualFile

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

the class LocalVirtualFileTest method updatesFolderInSearcherWhenItIsMoved.

@Test
public void updatesFolderInSearcherWhenItIsMoved() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFileName());
    VirtualFile newParent = getRoot().createFolder(generateFolderName());
    String oldPath = folder.getPath().toString();
    Mockito.reset(searcher);
    VirtualFile moved = folder.moveTo(newParent);
    verify(searcher).add(moved);
    verify(searcher).delete(oldPath, false);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 70 with VirtualFile

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

the class LocalVirtualFileTest method failsGetContentOfFolderAsString.

@Test
public void failsGetContentOfFolderAsString() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder(generateFolderName());
    thrown.expect(ForbiddenException.class);
    folder.getContentAsString();
}
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