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