use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsMoveLockedFileWhenLockTokenIsInvalid.
@Test
public void failsMoveLockedFileWhenLockTokenIsInvalid() throws Exception {
VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
String invalidLockToken = invalidateLockToken(file.lock(0));
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
Path movedFilePath = targetFolder.getPath().newPath(file.getName());
try {
file.moveTo(targetFolder, null, false, invalidLockToken);
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.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsUpdateContentOfLockedFileByBytesWithoutLockToken.
@Test
public void failsUpdateContentOfLockedFileByBytesWithoutLockToken() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
file.lock(0);
try {
file.updateContent("updated content".getBytes());
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsDeleteFolderWhenItContainsLockedFile.
@Test
public void failsDeleteFolderWhenItContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
Path folderPath = folder.getPath();
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
Path filePath = file.getPath();
file.lock(0);
try {
folder.delete();
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertEquals(folder, getRoot().getChild(folderPath));
assertEquals(file, getRoot().getChild(filePath));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest 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) {
assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsRenameLockedFileWithoutLockToken.
@Test
public void failsRenameLockedFileWithoutLockToken() 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");
file.lock(0);
try {
file.rename("new name");
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);
}
}
Aggregations