Search in sources :

Example 96 with VirtualFile

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

the class LocalVirtualFileTest method compressFolderToTarArchive.

@Test
public void compressFolderToTarArchive() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    Archiver archiver = mock(Archiver.class);
    when(archiverFactory.createArchiver(eq(folder), eq("tar"))).thenReturn(archiver);
    folder.tar();
    verify(archiver).compress(any(OutputStream.class), any(VirtualFileFilter.class));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFileFilter(org.eclipse.che.api.vfs.VirtualFileFilter) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Archiver(org.eclipse.che.api.vfs.Archiver) Test(org.junit.Test)

Example 97 with VirtualFile

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

the class LocalVirtualFileTest method renamesFile.

@Test
public void renamesFile() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    VirtualFile renamedFile = file.rename("new name");
    assertionHelper.assertThatIoFileHasContent(renamedFile.getPath(), DEFAULT_CONTENT_BYTES);
    assertionHelper.assertThatMetadataIoFileHasContent(renamedFile.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
    assertionHelper.assertThatIoFileDoesNotExist(filePath);
    assertionHelper.assertThatMetadataIoFileDoesNotExist(filePath);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 98 with VirtualFile

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

the class LocalVirtualFileTest method failsMoveFolderWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled.

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

Example 99 with VirtualFile

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

the class MemoryVirtualFileTest method failsUpdateContentOfLockedFileByStringWhenLockTokenIsInvalid.

@Test
public void failsUpdateContentOfLockedFileByStringWhenLockTokenIsInvalid() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    String invalidLockToken = invalidateLockToken(file.lock(0));
    try {
        file.updateContent("updated content", invalidLockToken);
        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 100 with VirtualFile

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

the class MemoryVirtualFileTest method createsFolderHierarchy.

@Test
public void createsFolderHierarchy() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder("a/b");
    assertEquals(folder, root.getChild(Path.of("a/b")));
}
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