use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsCopyFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile.
@Test
public void failsCopyFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
VirtualFile conflictFolder = targetFolder.createFolder(folder.getName());
VirtualFile lockedFileInConflictFolder = conflictFolder.createFile(generateFileName(), "xxx");
lockedFileInConflictFolder.lock(0);
try {
folder.copyTo(targetFolder, null, true);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileHasContent(lockedFileInConflictFolder.getPath(), "xxx".getBytes());
assertionHelper.assertThatIoFileDoesNotExist(conflictFolder.getPath().newPath(file.getName()));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsRenameLockedFileWhenLockTokenIsInvalid.
@Test
public void failsRenameLockedFileWhenLockTokenIsInvalid() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
Path newPath = folder.getPath().newPath("new name");
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.rename("new name", invalidLockToken);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
assertionHelper.assertThatLockIoFileExists(filePath);
assertionHelper.assertThatIoFileDoesNotExist(newPath);
assertionHelper.assertThatLockIoFileDoesNotExist(newPath);
assertionHelper.assertThatMetadataIoFileDoesNotExist(newPath);
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStringWithoutLockToken.
@Test
public void failsUpdateContentOfLockedFileByStringWithoutLockToken() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
file.lock(0);
try {
file.updateContent("updated content");
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsRenameFolderWheItContainsLockedFile.
@Test
public void failsRenameFolderWheItContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile lockedFile = folder.createFile(generateFileName(), DEFAULT_CONTENT);
lockedFile.lock(0);
Path renamedFolderPath = Path.of("/new_name");
try {
folder.rename("new_name");
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileDoesNotExist(renamedFolderPath);
assertionHelper.assertThatIoFileExists(folder.getPath());
assertionHelper.assertThatIoFileHasContent(lockedFile.getPath(), DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatLockIoFileExists(lockedFile.getPath());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStringWhenLockTokenIsInvalid.
@Test
public void failsUpdateContentOfLockedFileByStringWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.updateContent("updated content", invalidLockToken);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
Aggregations