Search in sources :

Example 31 with OrganizationImpl

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

the class OrganizationServiceTest method shouldCreateOrganization.

@Test
public void shouldCreateOrganization() throws Exception {
    when(orgManager.create(any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[0]));
    final OrganizationDto toCreate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toCreate).when().post(SECURE_PATH + "/organization");
    assertEquals(response.statusCode(), 201);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toCreate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).create(eq(toCreate));
}
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)

Example 32 with OrganizationImpl

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

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationUpdating.

@Test
public void shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationUpdating() throws Exception {
    when(manager.getById(anyString())).thenReturn(new OrganizationImpl("organization123", "test", "parent123"));
    when(subject.hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS)).thenReturn(true);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.getStatusCode(), 204);
    verify(service).update(eq("organization123"), any());
    verify(subject).hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS);
    verify(superPrivilegesChecker, never()).hasSuperPrivileges();
    verifyNoMoreInteractions(subject);
}
Also used : Response(io.restassured.response.Response) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 33 with OrganizationImpl

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

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationRemoving.

@Test
public void shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationRemoving() throws Exception {
    when(manager.getById(anyString())).thenReturn(new OrganizationImpl("organization123", "test", "parent123"));
    when(subject.hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS)).thenReturn(true);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().delete(SECURE_PATH + "/organization/organization123");
    assertEquals(response.getStatusCode(), 204);
    verify(service).remove(eq("organization123"));
    verify(subject).hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS);
    verify(superPrivilegesChecker, never()).hasSuperPrivileges();
    verifyNoMoreInteractions(subject);
}
Also used : Response(io.restassured.response.Response) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 34 with OrganizationImpl

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

the class OrganizationResourcesDistributorTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    lenient().doNothing().when(manager).checkResourcesAvailability(anyString(), any());
    lenient().when(resourcesLocks.lock(anyString())).thenReturn(lock);
    lenient().when(organizationManager.getById(ORG_ID)).thenReturn(new OrganizationImpl(ORG_ID, ORG_ID + "name", PARENT_ORG_ID));
    lenient().when(organizationManager.getById(PARENT_ORG_ID)).thenReturn(new OrganizationImpl(PARENT_ORG_ID, PARENT_ORG_ID + "name", null));
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 35 with OrganizationImpl

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

the class JpaOrganizationImplTckRepository method removeAll.

@Override
public void removeAll() throws TckRepositoryException {
    uow.begin();
    final EntityManager manager = managerProvider.get();
    try {
        manager.getTransaction().begin();
        for (int i = createdOrganizations.size() - 1; i > -1; i--) {
            // and may also ignore some configuration options, while EntityManager#remove won't
            try {
                final OrganizationImpl organizationToRemove = manager.createQuery("SELECT o FROM Organization o " + "WHERE o.id = :id", OrganizationImpl.class).setParameter("id", createdOrganizations.get(i).getId()).getSingleResult();
                manager.remove(organizationToRemove);
            } catch (NoResultException ignored) {
            // it is already removed
            }
        }
        createdOrganizations.clear();
        manager.getTransaction().commit();
    } catch (RuntimeException x) {
        if (manager.getTransaction().isActive()) {
            manager.getTransaction().rollback();
        }
        throw new TckRepositoryException(x.getLocalizedMessage(), x);
    } finally {
        uow.end();
    }
    // remove all objects that was created in tests
    super.removeAll();
}
Also used : EntityManager(javax.persistence.EntityManager) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) NoResultException(javax.persistence.NoResultException) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)

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