use of org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent in project che by eclipse.
the class WorkspaceDaoTest method shouldNotRemoveWorkspaceWhenSubscriberThrowsExceptionOnWorkspaceRemoving.
@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldNotRemoveWorkspaceWhenSubscriberThrowsExceptionOnWorkspaceRemoving() throws Exception {
final WorkspaceImpl workspace = workspaces[0];
CascadeEventSubscriber<BeforeWorkspaceRemovedEvent> subscriber = mockCascadeEventSubscriber();
doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
eventService.subscribe(subscriber, BeforeWorkspaceRemovedEvent.class);
try {
workspaceDao.remove(workspace.getId());
fail("WorkspaceDao#remove had to throw server exception");
} catch (ServerException ignored) {
}
assertEquals(workspaceDao.get(workspace.getId()), workspace);
eventService.unsubscribe(subscriber, BeforeWorkspaceRemovedEvent.class);
}
use of org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent in project che by eclipse.
the class JpaWorkspaceDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected Optional<WorkspaceImpl> doRemove(String id) throws ServerException {
final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id);
if (workspace == null) {
return Optional.empty();
}
final EntityManager manager = managerProvider.get();
eventService.publish(new BeforeWorkspaceRemovedEvent(new WorkspaceImpl(workspace))).propagateException();
manager.remove(workspace);
manager.flush();
return Optional.of(workspace);
}
Aggregations