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")));
}
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);
}
}
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());
}
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());
}
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);
}
}
Aggregations