Search in sources :

Example 81 with VirtualFile

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

the class MemoryVirtualFileTest method renamesLockedFileWithLockToken.

@Test
public void renamesLockedFileWithLockToken() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    Path filePath = file.getPath();
    String lockToken = file.lock(0);
    VirtualFile renamedFile = file.rename("new name", lockToken);
    assertFalse(renamedFile.isLocked());
    assertEquals(renamedFile, getRoot().getChild(renamedFile.getPath()));
    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 82 with VirtualFile

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

the class MemoryVirtualFileTest method removesPropertyBySetValueToNull.

@Test
public void removesPropertyBySetValueToNull() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), "");
    file.setProperty("property1", "value1");
    Map<String, String> expected = ImmutableMap.of("property1", "value1");
    assertEquals(expected, file.getProperties());
    file.setProperty("property1", null);
    assertTrue(file.getProperties().isEmpty());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 83 with VirtualFile

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

the class MemoryVirtualFileTest method updatesFileInSearcherWhenContentUpdatedByString.

@Test
public void updatesFileInSearcherWhenContentUpdatedByString() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), "");
    file.updateContent(DEFAULT_CONTENT);
    verify(searcher).update(file);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 84 with VirtualFile

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

the class MemoryVirtualFileTest method movesFileUnderNewNameAndOverwriteExistedFile.

@Test
public void movesFileUnderNewNameAndOverwriteExistedFile() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    targetFolder.createFolder("new_name");
    VirtualFile movedFile = file.moveTo(targetFolder, "new_name", true, null);
    assertEquals(movedFile, getRoot().getChild(movedFile.getPath()));
    assertEquals(ImmutableMap.of("property1", "value1"), movedFile.getProperties());
    assertEquals(DEFAULT_CONTENT, movedFile.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 85 with VirtualFile

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

the class MemoryVirtualFileTest method updatesContentOfLockedFileByStreamWithLockToken.

@Test
public void updatesContentOfLockedFileByStreamWithLockToken() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    String lockToken = file.lock(0);
    file.updateContent(new ByteArrayInputStream("updated content".getBytes()), lockToken);
    assertEquals("updated content", file.getContentAsString());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) 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