Search in sources :

Example 6 with OrganizationImpl

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();
}
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 7 with OrganizationImpl

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);
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 8 with OrganizationImpl

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");
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 9 with OrganizationImpl

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));
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 10 with OrganizationImpl

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()));
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Aggregations

OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)100 Test (org.testng.annotations.Test)56 Transactional (com.google.inject.persist.Transactional)18 BeforeMethod (org.testng.annotations.BeforeMethod)16 EntityManager (javax.persistence.EntityManager)14 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)14 Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)13 Response (io.restassured.response.Response)12 Page (org.eclipse.che.api.core.Page)10 ServerException (org.eclipse.che.api.core.ServerException)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)7 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)6 UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)5 DBInitializer (org.eclipse.che.core.db.DBInitializer)5