Search in sources :

Example 46 with VirtualFile

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

the class LocalVirtualFileTest method getsChildByHierarchicalPath.

@Test
public void getsChildByHierarchicalPath() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder("a/b/c/d");
    String name = generateFileName();
    VirtualFile file = folder.createFile(name, DEFAULT_CONTENT);
    assertEquals(file, root.getChild(folder.getPath().newPath(name)));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 47 with VirtualFile

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

the class MemoryVirtualFileTest method getsContentAsBytes.

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

Example 48 with VirtualFile

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

the class MemoryVirtualFileTest 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");
    assertEquals(renamedFile, getRoot().getChild(renamedFile.getPath()));
    assertEquals(ImmutableMap.of("property1", "value1"), renamedFile.getProperties());
    assertEquals(DEFAULT_CONTENT, renamedFile.getContentAsString());
    assertNull(getRoot().getChild(filePath));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 49 with VirtualFile

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

the class MemoryVirtualFileTest method deletesFolder.

@Test
public void deletesFolder() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    folder.setProperty("property1", "value1");
    Path folderPath = folder.getPath();
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    folder.delete();
    assertNull(getRoot().getChild(folderPath));
    assertNull(getRoot().getChild(filePath));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 50 with VirtualFile

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

the class MemoryVirtualFileTest method updatesFileInSearcherWhenItIsRenamed.

@Test
public void updatesFileInSearcherWhenItIsRenamed() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    String oldPath = file.getPath().toString();
    Mockito.reset(searcher);
    VirtualFile renamed = file.rename("new_name");
    verify(searcher).add(renamed);
    verify(searcher).delete(oldPath, true);
}
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