Search in sources :

Example 21 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class MemberDaoTest method setUp.

@BeforeMethod
private void setUp() throws TckRepositoryException {
    users = new UserImpl[3];
    users[0] = new UserImpl("user1-id", "user1@test.com", "user1-name");
    users[1] = new UserImpl("user2-id", "user2@test.com", "user2-name");
    users[2] = new UserImpl("user3-id", "user3@test.com", "user3-name");
    userRepo.createAll(asList(users));
    orgs = new OrganizationImpl[3];
    orgs[0] = new OrganizationImpl("org1-id", "org1-name", null);
    orgs[1] = new OrganizationImpl("org2-id", "org2-name", null);
    orgs[2] = new OrganizationImpl("org3-id", "org3-name", null);
    organizationRepo.createAll(asList(orgs));
    members = new MemberImpl[5];
    members[0] = new MemberImpl(users[0].getId(), orgs[0].getId(), asList("read", "update"));
    members[1] = new MemberImpl(users[1].getId(), orgs[0].getId(), asList("read", "update"));
    members[2] = new MemberImpl(users[2].getId(), orgs[0].getId(), asList("read", "update"));
    members[3] = new MemberImpl(users[1].getId(), orgs[1].getId(), asList("read", "update"));
    members[4] = new MemberImpl(users[1].getId(), orgs[2].getId(), asList("read", "update"));
    memberRepo.createAll(Stream.of(members).map(MemberImpl::new).collect(Collectors.toList()));
}
Also used : MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 22 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationDaoTest method shouldGetOrganizationByName.

@Test
public void shouldGetOrganizationByName() throws Exception {
    final OrganizationImpl organization = organizations[0];
    final OrganizationImpl found = organizationDao.getByName(organization.getName());
    assertEquals(organization, found);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 23 with OrganizationImpl

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

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

the class OrganizationManagerTest method shouldGetOrganizationsByMember.

@Test
public void shouldGetOrganizationsByMember() throws Exception {
    final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
    when(memberDao.getOrganizations(eq("org123"), anyInt(), anyLong())).thenReturn(new Page<>(singletonList(toFetch), 0, 1, 1));
    final Page<? extends Organization> organizations = manager.getByMember("org123", 30, 0);
    assertEquals(organizations.getItemsCount(), 1);
    assertEquals(organizations.getItems().get(0), toFetch);
    verify(memberDao).getOrganizations("org123", 30, 0);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 25 with OrganizationImpl

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

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)

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