Search in sources :

Example 86 with VirtualFile

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

the class MemoryVirtualFileTest 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) {
        assertNull(getRoot().getChild(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 87 with VirtualFile

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

the class MemoryVirtualFileTest method failsUpdateContentOfLockedFileByBytesWithoutLockToken.

@Test
public void failsUpdateContentOfLockedFileByBytesWithoutLockToken() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.lock(0);
    try {
        file.updateContent("updated content".getBytes());
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 88 with VirtualFile

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

the class MemoryVirtualFileTest method failsDeleteFolderWhenItContainsLockedFile.

@Test
public void failsDeleteFolderWhenItContainsLockedFile() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    Path folderPath = folder.getPath();
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    Path filePath = file.getPath();
    file.lock(0);
    try {
        folder.delete();
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertEquals(folder, getRoot().getChild(folderPath));
        assertEquals(file, getRoot().getChild(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 89 with VirtualFile

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

the class MemoryVirtualFileTest method updatesFolderInSearcherWhenItIsRenamed.

@Test
public void updatesFolderInSearcherWhenItIsRenamed() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    String oldPath = folder.getPath().toString();
    Mockito.reset(searcher);
    VirtualFile renamed = folder.rename("new_name");
    verify(searcher).add(renamed);
    verify(searcher).delete(oldPath, false);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 90 with VirtualFile

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

the class LocalVirtualFileTest method updatesContentByString.

@Test
public void updatesContentByString() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.updateContent("updated content");
    assertionHelper.assertThatIoFileHasContent(file.getPath(), "updated content".getBytes());
    assertEquals("updated content", file.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