Search in sources :

Example 11 with OrganizationDistributedResourcesImpl

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

the class OrganizationResourcesDistributorTest method shouldGetDistributedResources.

@Test
public void shouldGetDistributedResources() throws Exception {
    // given
    final OrganizationDistributedResourcesImpl distributedResources = createDistributedResources(1000);
    doReturn(new Page<>(singletonList(distributedResources), 0, 10, 1)).when(distributedResourcesDao).getByParent(anyString(), anyInt(), anyLong());
    // when
    final Page<? extends OrganizationDistributedResources> fetchedDistributedResources = manager.getByParent(ORG_ID, 10, 0);
    // then
    assertEquals(fetchedDistributedResources.getTotalItemsCount(), 1);
    assertEquals(fetchedDistributedResources.getItems().get(0), distributedResources);
    verify(distributedResourcesDao).getByParent(ORG_ID, 10, 0);
}
Also used : OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 12 with OrganizationDistributedResourcesImpl

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

the class OrganizationResourcesDistributorTest method shouldGetResourcesCap.

@Test
public void shouldGetResourcesCap() throws Exception {
    // given
    final OrganizationDistributedResourcesImpl distributedResources = createDistributedResources(1000);
    when(distributedResourcesDao.get(anyString())).thenReturn(distributedResources);
    // when
    final List<? extends Resource> fetchedDistributedResources = manager.getResourcesCaps(ORG_ID);
    // then
    assertEquals(fetchedDistributedResources, distributedResources.getResourcesCap());
    verify(distributedResourcesDao).get(ORG_ID);
}
Also used : OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 13 with OrganizationDistributedResourcesImpl

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

the class OrganizationResourcesDistributorTest method shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne.

@Test
public void shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne() throws Exception {
    ResourceImpl toCap = new ResourceImpl("test1", 1000, "init");
    ResourceImpl toReset = new ResourceImpl("test2", -1, "init");
    List<ResourceImpl> resourcesToCap = asList(toCap, toReset);
    // when
    manager.capResources(ORG_ID, resourcesToCap);
    // then
    verify(manager).checkResourcesAvailability(ORG_ID, singletonList(toCap));
    verify(distributedResourcesDao).store(new OrganizationDistributedResourcesImpl(ORG_ID, singletonList(toCap)));
    verify(resourcesLocks).lock(ORG_ID);
    verify(lock).close();
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 14 with OrganizationDistributedResourcesImpl

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

the class OrganizationDistributedResourcesDaoTest method shouldCreateDistributedResourcesWhenStoringNotExistentOne.

@Test
public void shouldCreateDistributedResourcesWhenStoringNotExistentOne() throws Exception {
    // given
    OrganizationDistributedResourcesImpl toStore = distributedResources[0];
    distributedResourcesDao.remove(toStore.getOrganizationId());
    // when
    distributedResourcesDao.store(toStore);
    // then
    assertEquals(distributedResourcesDao.get(toStore.getOrganizationId()), copy(toStore));
}
Also used : OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 15 with OrganizationDistributedResourcesImpl

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

the class OrganizationDistributedResourcesDaoTest method setUp.

@BeforeMethod
private void setUp() throws Exception {
    parentOrganization = new OrganizationImpl("parentOrg", "parentOrgName", null);
    suborganizations = new OrganizationImpl[ORGANIZATION_RESOURCES_COUNT];
    distributedResources = new OrganizationDistributedResourcesImpl[ORGANIZATION_RESOURCES_COUNT];
    for (int i = 0; i < ORGANIZATION_RESOURCES_COUNT; i++) {
        suborganizations[i] = new OrganizationImpl("suborgId-" + i, "suborgName" + i, parentOrganization.getId());
        distributedResources[i] = new OrganizationDistributedResourcesImpl(suborganizations[i].getId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, i, "test")));
    }
    organizationsRepository.createAll(Collections.singletonList(parentOrganization));
    organizationsRepository.createAll(Arrays.asList(suborganizations));
    distributedResourcesRepository.createAll(Arrays.asList(distributedResources));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)32 Test (org.testng.annotations.Test)16 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)8 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 Transactional (com.google.inject.persist.Transactional)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 MemberDao (org.eclipse.che.multiuser.organization.spi.MemberDao)6 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)6 OrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.OrganizationDistributedResourcesDao)6 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)6 JpaMemberDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaMemberDao)6 JpaOrganizationDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDao)6 JpaOrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDistributedResourcesDao)6 HashMap (java.util.HashMap)4