use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsMoveFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile.
@Test
public void failsMoveFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile() 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.moveTo(targetFolder, null, true, null);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileHasContent(lockedFileInConflictFolder.getPath(), "xxx".getBytes());
assertionHelper.assertThatIoFileDoesNotExist(conflictFolder.getPath().newPath(file.getName()));
assertionHelper.assertThatIoFileExists(folder.getPath());
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStreamWithoutLockToken.
@Test
public void failsUpdateContentOfLockedFileByStreamWithoutLockToken() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
file.lock(0);
try {
file.updateContent(new ByteArrayInputStream("updated content".getBytes()));
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 failsCreateFileWhenParenIsNotFolder.
@Test
public void failsCreateFileWhenParenIsNotFolder() throws Exception {
VirtualFile parent = getRoot().createFile("parent", "");
try {
parent.createFile("file", DEFAULT_CONTENT);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileDoesNotExist(parent.getPath().newPath("file"));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUnlockFileWhenLockTokenIsInvalid.
@Test
public void failsUnlockFileWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.unlock(invalidLockToken);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatLockIoFileExists(file.getPath());
assertTrue(file.isLocked());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsMoveFolderWhenItContainsLockedFile.
@Test
public void failsMoveFolderWhenItContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile lockedFile = folder.createFile(generateFileName(), DEFAULT_CONTENT);
lockedFile.lock(0);
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
Path movedFolderPath = targetFolder.getPath().newPath(folder.getName());
try {
folder.moveTo(targetFolder);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileDoesNotExist(movedFolderPath);
assertionHelper.assertThatIoFileExists(folder.getPath());
assertionHelper.assertThatIoFileExists(lockedFile.getPath());
assertionHelper.assertThatLockIoFileExists(lockedFile.getPath());
}
}
Aggregations