use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnAvailableResourcesAsTotalMinusUsedByItselfAndItsSuborganizations.
@Test
public void shouldReturnAvailableResourcesAsTotalMinusUsedByItselfAndItsSuborganizations() throws Exception {
// given
ResourceImpl totalResource = new ResourceImpl("test", 9000, "unit");
doReturn(singletonList(totalResource)).when(resourceManager).getTotalResources(anyString());
ResourceImpl usedResource = new ResourceImpl("test", 3000, "unit");
doReturn(singletonList(usedResource)).when(resourceManager).getUsedResources(anyString());
ResourceImpl usedBySuborgResource = new ResourceImpl("test", 1500, "unit");
ResourceImpl usedBySubsuborgResource = new ResourceImpl("test", 2000, "unit");
doReturn(asList(usedBySuborgResource, usedBySubsuborgResource)).when(availableResourcesProvider).getUsedResourcesBySuborganizations(anyString());
ResourceImpl availableResource = new ResourceImpl("test", 2500, "unit");
doReturn(singletonList(availableResource)).when(resourceAggregator).deduct(anyList(), anyList());
// when
List<? extends Resource> availableResources = availableResourcesProvider.getAvailableOrganizationResources(rootOrganization);
// then
assertEquals(availableResources.size(), 1);
assertEquals(availableResources.get(0), availableResource);
verify(resourceManager).getTotalResources(ROOT_ORG_ID);
verify(resourceManager).getUsedResources(ROOT_ORG_ID);
verify(availableResourcesProvider).getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
verify(resourceAggregator).deduct(singletonList(totalResource), asList(usedResource, usedBySuborgResource, usedBySubsuborgResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class OrganizationalAccountAvailableResourcesProviderTest method shouldCalculateUsedResourceBySuborganizations.
@Test
public void shouldCalculateUsedResourceBySuborganizations() throws Exception {
// given
doReturn(new Page<>(singletonList(suborganization), 0, 1, 2)).doReturn(new Page<>(singletonList(subsuborganization), 1, 1, 2)).when(organizationManager).getSuborganizations(anyString(), anyInt(), anyLong());
ResourceImpl usedBySuborgResource = new ResourceImpl("test", 1500, "unit");
doReturn(singletonList(usedBySuborgResource)).when(resourceManager).getUsedResources(SUBORG_ID);
ResourceImpl usedBySubsuborgResource = new ResourceImpl("test", 2000, "unit");
doReturn(singletonList(usedBySubsuborgResource)).when(resourceManager).getUsedResources(SUBSUBORG_ID);
// when
List<? extends Resource> usedResources = availableResourcesProvider.getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
// then
assertEquals(usedResources.size(), 2);
assertTrue(usedResources.contains(usedBySuborgResource));
assertTrue(usedResources.contains(usedBySubsuborgResource));
verify(organizationManager, times(2)).getSuborganizations(eq(ROOT_ORG_NAME), anyInt(), anyLong());
verify(resourceManager).getUsedResources(SUBORG_ID);
verify(resourceManager).getUsedResources(SUBSUBORG_ID);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnAvailableResourcesForSuborganization.
@Test
public void shouldReturnAvailableResourcesForSuborganization() throws Exception {
// given
ResourceImpl parentAvailableResource = new ResourceImpl("test", 3000, "unit");
prepareAvailableResource(ROOT_ORG_ID, parentAvailableResource);
ResourceImpl suborgAvailableResource = new ResourceImpl("test", 5000, "unit");
prepareAvailableResource(SUBORG_ID, suborgAvailableResource);
doReturn(asList(parentAvailableResource, suborgAvailableResource)).when(resourceAggregator).intersection(anyList(), anyList());
doReturn(singletonList(parentAvailableResource)).when(resourceAggregator).min(anyList());
// when
List<? extends Resource> availableResources = availableResourcesProvider.getAvailableResources(SUBORG_ID);
// then
assertEquals(availableResources.size(), 1);
assertEquals(availableResources.get(0), parentAvailableResource);
verify(availableResourcesProvider).getAvailableOrganizationResources(rootOrganization);
verify(availableResourcesProvider).getAvailableOrganizationResources(suborganization);
verify(resourceAggregator).intersection(singletonList(parentAvailableResource), singletonList(suborgAvailableResource));
verify(resourceAggregator).min(asList(parentAvailableResource, suborgAvailableResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnExcessiveResourcesWhenUsedResourceAreGreaterThanTotal.
@Test
public void shouldReturnExcessiveResourcesWhenUsedResourceAreGreaterThanTotal() throws Exception {
// given
ResourceImpl totalResource = new ResourceImpl("test", 9000, "unit");
ResourceImpl excessiveTotalResource = new ResourceImpl("test1", 1000, "unit");
doReturn(asList(totalResource, excessiveTotalResource)).when(resourceManager).getTotalResources(anyString());
ResourceImpl usedResource = new ResourceImpl("test", 10000, "unit");
doReturn(singletonList(usedResource)).when(resourceManager).getUsedResources(anyString());
doReturn(emptyList()).when(availableResourcesProvider).getUsedResourcesBySuborganizations(anyString());
doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(resourceAggregator).deduct(anyList(), anyList());
doReturn(singletonList(excessiveTotalResource)).when(resourceAggregator).excess(anyList(), anyList());
// when
List<? extends Resource> availableResources = availableResourcesProvider.getAvailableOrganizationResources(rootOrganization);
// then
assertEquals(availableResources.size(), 1);
assertEquals(availableResources.get(0), excessiveTotalResource);
verify(resourceManager).getTotalResources(ROOT_ORG_ID);
verify(resourceManager).getUsedResources(ROOT_ORG_ID);
verify(availableResourcesProvider).getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
verify(resourceAggregator).deduct(asList(totalResource, excessiveTotalResource), singletonList(usedResource));
verify(resourceAggregator).excess(asList(totalResource, excessiveTotalResource), singletonList(usedResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class SuborganizationResourcesProviderTest method shouldProvideResourcesForSuborganizationalAccount.
@Test
public void shouldProvideResourcesForSuborganizationalAccount() throws Exception {
// given
when(account.getType()).thenReturn(OrganizationImpl.ORGANIZATIONAL_ACCOUNT);
when(organization.getParent()).thenReturn("parentOrg");
final ResourceImpl parentNotCapedResource = new ResourceImpl("test", 1234, "unit");
final ResourceImpl parentCapedResource = new ResourceImpl("caped", 20, "unit");
final ResourceImpl parentUnlimitedCapedResource = new ResourceImpl("unlimited", -1, "unit");
doReturn(asList(parentNotCapedResource, parentCapedResource, parentUnlimitedCapedResource)).when(resourceManager).getTotalResources(anyString());
final ResourceImpl capedResourceCap = new ResourceImpl("caped", 10, "unit");
final ResourceImpl unlimitedCapedResourceCap = new ResourceImpl("unlimited", 40, "unit");
doReturn(asList(capedResourceCap, unlimitedCapedResourceCap)).when(resourcesDistributor).getResourcesCaps(any());
// when
final List<ProvidedResources> providedResources = suborganizationResourcesProvider.getResources("organization123");
// then
assertEquals(providedResources.size(), 1);
assertEquals(providedResources.get(0), new ProvidedResourcesImpl(SuborganizationResourcesProvider.PARENT_RESOURCES_PROVIDER, null, "organization123", -1L, -1L, asList(parentNotCapedResource, capedResourceCap, unlimitedCapedResourceCap)));
verify(accountManager).getById("organization123");
verify(organizationManager).getById("organization123");
verify(resourcesDistributor).getResourcesCaps("organization123");
verify(resourceManager).getTotalResources("parentOrg");
}
Aggregations