use of org.eclipse.che.api.vfs.Path in project che by eclipse.
the class LocalVirtualFileTest method failsDeleteLockedFileWhenLockTokenIsInvalid.
@Test
public void failsDeleteLockedFileWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile folder = root.createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.delete(invalidLockToken);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatMetadataIoFileHasContent(file.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
assertionHelper.assertThatLockIoFileExists(filePath);
}
}
use of org.eclipse.che.api.vfs.Path 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);
}
}
use of org.eclipse.che.api.vfs.Path in project che by eclipse.
the class LocalVirtualFileTest method movesFolderUnderNewNameAndReplaceExistedItem.
@Test
public void movesFolderUnderNewNameAndReplaceExistedItem() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
Path folderPath = folder.getPath();
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
targetFolder.createFolder("new_name");
VirtualFile movedFolder = folder.moveTo(targetFolder, "new_name", true, null);
VirtualFile movedFile = movedFolder.getChild(Path.of(file.getName()));
assertionHelper.assertThatIoFileExists(movedFolder.getPath());
assertionHelper.assertThatIoFileHasContent(movedFile.getPath(), DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatIoFileDoesNotExist(folderPath);
}
use of org.eclipse.che.api.vfs.Path in project che by eclipse.
the class LocalVirtualFileTest method deletesFile.
@Test
public void deletesFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
file.delete();
assertionHelper.assertThatIoFileDoesNotExist(filePath);
assertionHelper.assertThatMetadataIoFileDoesNotExist(filePath);
}
use of org.eclipse.che.api.vfs.Path in project che by eclipse.
the class MemoryVirtualFile method moveTo.
@Override
public VirtualFile moveTo(VirtualFile parent, String newName, boolean overwrite, String lockToken) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
MemoryVirtualFile memoryParent = (MemoryVirtualFile) parent;
memoryParent.checkExistence();
if (isRoot()) {
throw new ForbiddenException("Unable move root folder");
}
if (!parent.isFolder()) {
throw new ForbiddenException("Unable move item. Item specified as parent is not a folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
final boolean isFile = isFile();
final Path myPath = getPath();
final Path newParentPath = parent.getPath();
final boolean folder = isFolder();
if (folder) {
if (newParentPath.isChild(myPath)) {
throw new ForbiddenException(String.format("Unable move item %s to %s. Item may not have itself as parent", myPath, newParentPath));
}
final List<VirtualFile> lockedFiles = new LockedFileFinder(this).findLockedFiles();
if (!lockedFiles.isEmpty()) {
throw new ForbiddenException(String.format("Unable move item '%s'. Child items '%s' are locked", getName(), lockedFiles));
}
} else if (fileIsLockedAndLockTokenIsInvalid(lockToken)) {
throw new ForbiddenException(String.format("Unable move item %s. Item is locked", myPath));
}
if (overwrite) {
MemoryVirtualFile existedItem = memoryParent.children.get(newName);
if (existedItem != null) {
existedItem.delete();
}
}
if (memoryParent.children.containsKey(newName)) {
throw new ConflictException(String.format("Item '%s' already exists", parent.getPath().newPath(newName)));
}
this.parent.children.remove(name);
memoryParent.children.put(newName, this);
this.parent = memoryParent;
this.name = newName;
lock = null;
deleteFromSearcher(myPath, isFile);
addInSearcher(this);
return this;
}
Aggregations