Search in sources :

Example 1 with BeforeWorkspaceRemovedEvent

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);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) BeforeWorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent) Test(org.testng.annotations.Test)

Example 2 with BeforeWorkspaceRemovedEvent

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);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EntityManager(javax.persistence.EntityManager) BeforeWorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Aggregations

BeforeWorkspaceRemovedEvent (org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 Transactional (com.google.inject.persist.Transactional)1 EntityManager (javax.persistence.EntityManager)1 ServerException (org.eclipse.che.api.core.ServerException)1 Test (org.testng.annotations.Test)1