Search in sources :

Example 26 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl 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)

Example 27 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationManagerTest method shouldCreateOrganization.

@Test
public void shouldCreateOrganization() throws Exception {
    final Organization toCreate = DtoFactory.newDto(OrganizationDto.class).withName("newOrg");
    manager.create(toCreate);
    verify(organizationDao).create(organizationCaptor.capture());
    final OrganizationImpl createdOrganization = organizationCaptor.getValue();
    assertEquals(createdOrganization.getName(), toCreate.getName());
    assertEquals(createdOrganization.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) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 28 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationManagerTest method shouldGetOrganizationById.

@Test
public void shouldGetOrganizationById() throws Exception {
    final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
    when(organizationDao.getById(eq("org123"))).thenReturn(toFetch);
    final Organization fetched = manager.getById("org123");
    assertEquals(fetched, toFetch);
    verify(organizationDao).getById("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 29 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationManagerTest method shouldRemoveSuborganizationsByParentOrganizationId.

@Test
public void shouldRemoveSuborganizationsByParentOrganizationId() throws Exception {
    doNothing().when(manager).remove(any());
    OrganizationImpl subOrg1 = new OrganizationImpl("subOrg1", "subOrg1", "org1");
    OrganizationImpl subOrg2 = new OrganizationImpl("subOrg2", "subOrg2", "org1");
    doReturn(new Page<>(singletonList(subOrg1), 0, 1, 2)).doReturn(new Page<>(singletonList(subOrg2), 1, 1, 2)).when(organizationDao).getByParent(anyString(), anyInt(), anyLong());
    manager.removeSuborganizations("org1");
    verify(organizationDao, times(2)).getByParent("org1", 100, 0);
    verify(manager).remove("subOrg1");
    verify(manager).remove("subOrg2");
}
Also used : Page(org.eclipse.che.api.core.Page) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 30 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldUpdateOrganization.

@Test
public void shouldUpdateOrganization() throws Exception {
    when(orgManager.update(anyString(), any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[1]));
    final OrganizationDto toUpdate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toUpdate).when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.statusCode(), 200);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toUpdate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).update(eq("organization123"), eq(toUpdate));
}
Also used : Response(io.restassured.response.Response) Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) 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