use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest 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) {
assertEquals("xxx", lockedFileInConflictFolder.getContentAsString());
assertNull(getRoot().getChild(conflictFolder.getPath().newPath(file.getName())));
assertNotNull(getRoot().getChild(folder.getPath()));
assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest 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) {
assertNull(getRoot().getChild(movedFolderPath.newPath(lockedFile.getName())));
assertNull(getRoot().getChild(movedFolderPath));
assertNotNull(getRoot().getChild(folder.getPath()));
assertEquals(DEFAULT_CONTENT, lockedFile.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid.
@Test
public void failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.updateContent("updated content".getBytes(), 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 MemoryVirtualFileTest 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) {
assertNull(getRoot().getChild(movedFilePath));
assertTrue(file.isLocked());
assertEquals(file, getRoot().getChild(filePath));
assertEquals(ImmutableMap.of("property1", "value1"), file.getProperties());
assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest 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) {
assertEquals(DEFAULT_CONTENT, file.getContentAsString());
}
}
Aggregations