Search in sources :

Example 11 with VirtualFile

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

the class LocalVirtualFileTest method createsFolderHierarchy.

@Test
public void createsFolderHierarchy() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder("a/b");
    assertionHelper.assertThatIoFileExists(folder.getPath());
    assertEquals(folder, root.getChild(Path.of("a/b")));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 12 with VirtualFile

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

the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStreamWhenLockTokenIsInvalid.

@Test
public void failsUpdateContentOfLockedFileByStreamWhenLockTokenIsInvalid() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    String invalidLockToken = invalidateLockToken(file.lock(0));
    try {
        file.updateContent(new ByteArrayInputStream("updated content".getBytes()), invalidLockToken);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 13 with VirtualFile

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

the class LocalVirtualFileTest method getsChildren.

@Test
public void getsChildren() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder(generateFolderName());
    VirtualFile file1 = root.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile file2 = root.createFile(generateFileName(), DEFAULT_CONTENT);
    List<VirtualFile> expectedResult = newArrayList(file1, file2, folder);
    Collections.sort(expectedResult);
    assertEquals(expectedResult, root.getChildren());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 14 with VirtualFile

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

the class LocalVirtualFileTest 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);
    assertionHelper.assertThatMetadataIoFileDoesNotExist(file.getPath());
    assertTrue(file.getProperties().isEmpty());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 15 with VirtualFile

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

the class LocalVirtualFileTest method failsMoveLockedFileWithoutLockToken.

@Test
public void failsMoveLockedFileWithoutLockToken() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    file.lock(0);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    Path movedFilePath = targetFolder.getPath().newPath(file.getName());
    try {
        file.moveTo(targetFolder);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertionHelper.assertThatIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatLockIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatMetadataIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
        assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
        assertionHelper.assertThatLockIoFileExists(filePath);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) 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