use of org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException in project devspaces-images by redhat-developer.
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));
}
Aggregations