Search in sources :

Example 91 with VirtualFile

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

the class LocalVirtualFileTest method addsFolderThatCopiedFromOtherFolderInSearcher.

@Test
public void addsFolderThatCopiedFromOtherFolderInSearcher() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile newParent = getRoot().createFolder(generateFolderName());
    VirtualFile copy = folder.copyTo(newParent);
    verify(searcher).add(copy);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 92 with VirtualFile

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

the class LocalVirtualFileTest method failsCopyFileWhenItemWithTheSameNameExistsInTargetFolderAndOverwritingIsDisabled.

@Test
public void failsCopyFileWhenItemWithTheSameNameExistsInTargetFolderAndOverwritingIsDisabled() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = root.createFolder(generateFolderName());
    VirtualFile conflictFile = targetFolder.createFile("existed_name", "xxx");
    try {
        file.copyTo(targetFolder, "existed_name", false);
        thrown.expect(ConflictException.class);
    } catch (ConflictException e) {
        assertionHelper.assertThatIoFileHasContent(conflictFile.getPath(), "xxx".getBytes());
        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 93 with VirtualFile

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

the class LocalVirtualFileTest method createsFileWithStreamContent.

@Test
public void createsFileWithStreamContent() throws Exception {
    VirtualFile folder = getRoot().createFolder("a/b/c");
    VirtualFile file = folder.createFile("new_file", new ByteArrayInputStream(DEFAULT_CONTENT_BYTES));
    assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    assertEquals(file, folder.getChild(Path.of("new_file")));
    assertEquals("/a/b/c/new_file", file.getPath().toString());
    assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 94 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 95 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)

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