Search in sources :

Example 71 with VirtualFile

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

the class LocalVirtualFileTest method convertsToIoFile.

@Test
public void convertsToIoFile() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    assertEquals(new File(testDirectory, file.getPath().toString()), file.toIoFile());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Example 72 with VirtualFile

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

the class LocalVirtualFileTest method getsContentAsBytes.

@Test
public void getsContentAsBytes() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    byte[] content = file.getContentAsBytes();
    assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    assertEquals(DEFAULT_CONTENT, new String(content));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 73 with VirtualFile

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

the class LocalVirtualFileTest method failsRenameFileWhenFolderContainsItemWithSameName.

@Test
public void failsRenameFileWhenFolderContainsItemWithSameName() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    Path filePath = file.getPath();
    file.setProperty("property1", "value1");
    VirtualFile conflictFile = folder.createFile("existed_name", "xxx");
    Path conflictFilePath = conflictFile.getPath();
    conflictFile.setProperty("property2", "value2");
    try {
        file.rename("existed_name");
        thrown.expect(ConflictException.class);
    } catch (ConflictException e) {
        assertionHelper.assertThatIoFileHasContent(conflictFilePath, "xxx".getBytes());
        assertionHelper.assertThatMetadataIoFileHasContent(conflictFilePath, serializeVirtualFileMetadata(ImmutableMap.of("property2", "value2")));
        assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
        assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
    }
}
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 74 with VirtualFile

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

the class LocalVirtualFileTest method checksIsFile.

@Test
public void checksIsFile() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    assertTrue(file.isFile());
    VirtualFile folder = root.createFolder(generateFolderName());
    assertFalse(folder.isFile());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 75 with VirtualFile

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

the class LocalVirtualFileTest method movesFolder.

@Test
public void movesFolder() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    createFileTree(folder, 3);
    List<VirtualFile> originalTree = getFileTreeAsList(folder);
    for (int i = 0; i < originalTree.size(); i++) {
        originalTree.get(i).setProperty("property" + i, "value" + i);
    }
    List<Path> originalTreePaths = originalTree.stream().map(VirtualFile::getPath).collect(toList());
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile movedFolder = folder.moveTo(targetFolder);
    List<VirtualFile> movedTree = getFileTreeAsList(movedFolder);
    Iterator<Path> originalPathIterator = originalTreePaths.iterator();
    Iterator<VirtualFile> movedIterator = movedTree.iterator();
    int i = 0;
    while (originalPathIterator.hasNext() && movedIterator.hasNext()) {
        Path originalPath = originalPathIterator.next();
        VirtualFile moved = movedIterator.next();
        assertEquals(originalPath, moved.getPath().subPath(targetFolder.getPath()));
        if (moved.isFile()) {
            assertionHelper.assertThatIoFileHasContent(moved.getPath(), DEFAULT_CONTENT_BYTES);
        }
        assertionHelper.assertThatMetadataIoFileHasContent(moved.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property" + i, "value" + i)));
        assertionHelper.assertThatIoFileDoesNotExist(originalPath);
        assertionHelper.assertThatMetadataIoFileDoesNotExist(originalPath);
        i++;
    }
    assertFalse(originalPathIterator.hasNext() || movedIterator.hasNext());
}
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