use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl 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();
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldUpdateOrganizationAndIgnoreNewIdAndParentFields.
@Test
public void shouldUpdateOrganizationAndIgnoreNewIdAndParentFields() throws Exception {
final OrganizationImpl existing = new OrganizationImpl("org123", "oldName", "parent123");
final OrganizationImpl expectedExistingToUpdate = new OrganizationImpl(existing);
expectedExistingToUpdate.setQualifiedName("newName");
final OrganizationImpl suborganization = new OrganizationImpl("org321", "oldName/suborgName", "org123");
final OrganizationImpl expectedSuborganizationToUpdate = new OrganizationImpl(suborganization);
expectedSuborganizationToUpdate.setQualifiedName(expectedExistingToUpdate.getQualifiedName() + "/" + suborganization.getName());
when(organizationDao.getById(any())).thenReturn(existing);
doReturn(new Page<>(singletonList(suborganization), 0, 1, 1)).when(organizationDao).getSuborganizations(anyString(), anyInt(), anyLong());
final OrganizationImpl update = new OrganizationImpl("newId", "newName", "newParentId");
final Organization updated = manager.update("organizationId", update);
verify(organizationDao).getById("organizationId");
verify(organizationDao, times(2)).update(organizationCaptor.capture());
List<OrganizationImpl> updatedOrganizations = organizationCaptor.getAllValues();
assertEquals(updatedOrganizations.get(0), expectedExistingToUpdate);
assertEquals(updatedOrganizations.get(1), expectedSuborganizationToUpdate);
verify(organizationDao).getSuborganizations(eq("oldName"), anyInt(), anyLong());
assertEquals(updated, expectedExistingToUpdate);
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldGetOrganizationByName.
@Test
public void shouldGetOrganizationByName() throws Exception {
final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
when(organizationDao.getByName(eq("org123"))).thenReturn(toFetch);
final Organization fetched = manager.getByName("org123");
assertEquals(fetched, toFetch);
verify(organizationDao).getByName("org123");
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldThrowConflictExceptionOnUpdatingIfOrganizationNameIsReserved.
@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnUpdatingIfOrganizationNameIsReserved() throws Exception {
when(organizationDao.getById("id")).thenReturn(new OrganizationImpl("id", "oldName", null));
manager.update("id", new OrganizationImpl("id", "reserved", null));
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldCreateSuborganization.
@Test
public void shouldCreateSuborganization() throws Exception {
final OrganizationImpl parentOrganization = new OrganizationImpl("org123", "parentOrg", null);
when(organizationDao.getById(anyString())).thenReturn(parentOrganization);
final Organization toCreate = new OrganizationImpl(null, "orgName", parentOrganization.getId());
manager.create(toCreate);
verify(organizationDao).create(organizationCaptor.capture());
final OrganizationImpl createdOrganization = organizationCaptor.getValue();
assertEquals(createdOrganization.getName(), toCreate.getName());
assertEquals(createdOrganization.getQualifiedName(), parentOrganization.getQualifiedName() + "/" + toCreate.getName());
assertEquals(createdOrganization.getParent(), toCreate.getParent());
verify(eventService).publish(persistEventCaptor.capture());
assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
Aggregations