Search in sources :

Example 1 with BeforeAccountRemovedEvent

use of org.eclipse.che.account.event.BeforeAccountRemovedEvent in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldRemoveOrganization.

@Test
public void shouldRemoveOrganization() throws Exception {
    doNothing().when(manager).removeSuborganizations(anyString());
    final List<Member> members = Collections.singletonList(mock(Member.class));
    doReturn(members).when(manager).removeMembers(anyString());
    OrganizationImpl toRemove = new OrganizationImpl("org123", "toRemove", null);
    when(organizationDao.getById(anyString())).thenReturn(toRemove);
    BeforeAccountRemovedEvent beforeAccountRemovedEvent = mock(BeforeAccountRemovedEvent.class);
    BeforeOrganizationRemovedEvent beforeOrganizationRemovedEvent = mock(BeforeOrganizationRemovedEvent.class);
    doReturn(beforeAccountRemovedEvent).doReturn(beforeOrganizationRemovedEvent).when(eventService).publish(any());
    manager.remove(toRemove.getId());
    verify(organizationDao).remove(toRemove.getId());
    verify(manager).removeMembers(eq(toRemove.getId()));
    verify(manager).removeSuborganizations(eq(toRemove.getId()));
    verify(eventService, times(3)).publish(anyObject());
    verify(beforeAccountRemovedEvent).propagateException();
    verify(beforeOrganizationRemovedEvent).propagateException();
}
Also used : BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) Member(org.eclipse.che.multiuser.organization.shared.model.Member) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 2 with BeforeAccountRemovedEvent

use of org.eclipse.che.account.event.BeforeAccountRemovedEvent in project che-server by eclipse-che.

the class OrganizationManager method remove.

/**
 * Removes organization with given id
 *
 * @param organizationId organization id
 * @throws NullPointerException when {@code organizationId} is null
 * @throws ServerException when any other error occurs during organization removing
 */
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public void remove(String organizationId) throws ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    try {
        OrganizationImpl organization = organizationDao.getById(organizationId);
        eventService.publish(new BeforeAccountRemovedEvent(organization.getAccount())).propagateException();
        eventService.publish(new BeforeOrganizationRemovedEvent(organization)).propagateException();
        removeSuborganizations(organizationId);
        final List<String> members = removeMembers(organizationId);
        organizationDao.remove(organizationId);
        final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
        eventService.publish(asDto(new OrganizationRemovedEvent(initiator, organization, members)));
    } catch (NotFoundException e) {
    // organization is already removed
    }
}
Also used : OrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.OrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 3 with BeforeAccountRemovedEvent

use of org.eclipse.che.account.event.BeforeAccountRemovedEvent in project che-server by eclipse-che.

the class RemoveWorkspaceBeforeAccountRemovedEventSubscriberTest method shouldStopAndRemoveRunningWorkspaceByOwner.

@Test
public void shouldStopAndRemoveRunningWorkspaceByOwner() throws Exception {
    workspace.setStatus(WorkspaceStatus.RUNNING);
    EnvironmentContext.getCurrent().setSubject(SUBJECT);
    doAnswer(invocation -> {
        workspace.setStatus(WorkspaceStatus.STOPPED);
        return null;
    }).when(workspaceManager).stopWorkspace(workspaceId, of(REMOVE_WORKSPACE_AFTER_STOP, "true"));
    subscriber.onCascadeEvent(new BeforeAccountRemovedEvent(account));
    verify(workspaceManager).stopWorkspace(workspaceId, of(REMOVE_WORKSPACE_AFTER_STOP, "true"));
}
Also used : BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) Test(org.testng.annotations.Test)

Example 4 with BeforeAccountRemovedEvent

use of org.eclipse.che.account.event.BeforeAccountRemovedEvent in project devspaces-images by redhat-developer.

the class OrganizationManager method remove.

/**
 * Removes organization with given id
 *
 * @param organizationId organization id
 * @throws NullPointerException when {@code organizationId} is null
 * @throws ServerException when any other error occurs during organization removing
 */
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public void remove(String organizationId) throws ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    try {
        OrganizationImpl organization = organizationDao.getById(organizationId);
        eventService.publish(new BeforeAccountRemovedEvent(organization.getAccount())).propagateException();
        eventService.publish(new BeforeOrganizationRemovedEvent(organization)).propagateException();
        removeSuborganizations(organizationId);
        final List<String> members = removeMembers(organizationId);
        organizationDao.remove(organizationId);
        final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
        eventService.publish(asDto(new OrganizationRemovedEvent(initiator, organization, members)));
    } catch (NotFoundException e) {
    // organization is already removed
    }
}
Also used : OrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.OrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 5 with BeforeAccountRemovedEvent

use of org.eclipse.che.account.event.BeforeAccountRemovedEvent in project devspaces-images by redhat-developer.

the class OrganizationManagerTest method shouldRemoveOrganization.

@Test
public void shouldRemoveOrganization() throws Exception {
    doNothing().when(manager).removeSuborganizations(anyString());
    final List<Member> members = Collections.singletonList(mock(Member.class));
    doReturn(members).when(manager).removeMembers(anyString());
    OrganizationImpl toRemove = new OrganizationImpl("org123", "toRemove", null);
    when(organizationDao.getById(anyString())).thenReturn(toRemove);
    BeforeAccountRemovedEvent beforeAccountRemovedEvent = mock(BeforeAccountRemovedEvent.class);
    BeforeOrganizationRemovedEvent beforeOrganizationRemovedEvent = mock(BeforeOrganizationRemovedEvent.class);
    doReturn(beforeAccountRemovedEvent).doReturn(beforeOrganizationRemovedEvent).when(eventService).publish(any());
    manager.remove(toRemove.getId());
    verify(organizationDao).remove(toRemove.getId());
    verify(manager).removeMembers(eq(toRemove.getId()));
    verify(manager).removeSuborganizations(eq(toRemove.getId()));
    verify(eventService, times(3)).publish(anyObject());
    verify(beforeAccountRemovedEvent).propagateException();
    verify(beforeOrganizationRemovedEvent).propagateException();
}
Also used : BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) Member(org.eclipse.che.multiuser.organization.shared.model.Member) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Aggregations

BeforeAccountRemovedEvent (org.eclipse.che.account.event.BeforeAccountRemovedEvent)18 Test (org.testng.annotations.Test)14 AccountImpl (org.eclipse.che.account.spi.AccountImpl)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 BeforeOrganizationRemovedEvent (org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent)4 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)4 Transactional (com.google.inject.persist.Transactional)2 Runtime (org.eclipse.che.api.core.model.workspace.Runtime)2 OrganizationRemovedEvent (org.eclipse.che.multiuser.organization.api.event.OrganizationRemovedEvent)2 Member (org.eclipse.che.multiuser.organization.shared.model.Member)2