Search in sources :

Example 26 with NoEnoughResourcesException

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));
}
Also used : NoEnoughResourcesException(org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Aggregations

NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)26 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)20 Test (org.testng.annotations.Test)16 Resource (org.eclipse.che.multiuser.resource.model.Resource)8 ArrayList (java.util.ArrayList)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)4 WorkspaceConfig (org.eclipse.che.api.core.model.workspace.WorkspaceConfig)2 ResourceManager (org.eclipse.che.multiuser.resource.api.usage.ResourceManager)2