use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsUnlockFileWhenLockTokenIsNull.
@Test
public void failsUnlockFileWhenLockTokenIsNull() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
file.lock(0);
try {
file.unlock(null);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertTrue(file.isLocked());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class Workspace method createResource.
public void createResource(IResource resource, int updateFlags) throws CoreException {
try {
IPath path = resource.getFullPath();
switch(resource.getType()) {
case IResource.FILE:
String newName = path.lastSegment();
VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
if (child == null) {
throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
}
FolderEntry entry = (FolderEntry) child;
entry.createFile(newName, new byte[0]);
break;
case IResource.FOLDER:
getProjectsRoot().createFolder(path.toOSString());
break;
case IResource.PROJECT:
ProjectConfigImpl projectConfig = new ProjectConfigImpl();
projectConfig.setPath(resource.getName());
projectConfig.setName(resource.getName());
projectConfig.setType(BaseProjectType.ID);
projectManager.get().createProject(projectConfig, new HashMap<>());
break;
default:
throw new UnsupportedOperationException();
}
} catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class ProjectServiceTest method registerImporter.
private void registerImporter(String importType, InputStream zip) throws Exception {
final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
importerRegistry.register(new ProjectImporter() {
@Override
public String getId() {
return importType;
}
@Override
public boolean isInternal() {
return false;
}
@Override
public String getDescription() {
return "Chuck importer";
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
importSources(baseFolder, storage, LineConsumerFactory.NULL);
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
// Don't really use location in this test.
baseFolder.getVirtualFile().unzip(zip, true, 0);
folderHolder.set(baseFolder);
}
@Override
public ImporterCategory getCategory() {
return ImporterCategory.ARCHIVE;
}
});
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUnlockFileWhenLockTokenIsNull.
@Test
public void failsUnlockFileWhenLockTokenIsNull() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
file.lock(0);
try {
file.unlock(null);
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 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);
}
}
Aggregations