use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.
the class FreeResourcesProviderTest method shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists.
@Test
public void shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists() throws Exception {
// given
when(accountManager.getById(any())).thenReturn(account);
when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("user123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
// when
List<ProvidedResources> result = provider.getResources("user123");
// then
assertEquals(result.size(), 1);
ProvidedResources providedResources = result.get(0);
assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, "user123", "user123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
verify(freeResourcesLimitManager).get("user123");
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.
the class FreeResourcesProviderTest method shouldNotProvideDefaultResourcesForAccountIfDefaultResourcesProviderProvidesEmptyList.
@Test
public void shouldNotProvideDefaultResourcesForAccountIfDefaultResourcesProviderProvidesEmptyList() throws Exception {
// given
when(accountManager.getById(any())).thenReturn(account);
when(defaultResourcesProvider.getResources(any())).thenReturn(emptyList());
doThrow(new NotFoundException("not found")).when(freeResourcesLimitManager).get(any());
// when
List<ProvidedResources> result = provider.getResources("user123");
// then
assertTrue(result.isEmpty());
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.
the class FreeResourcesProviderTest method shouldProvideResourcesFromFreeResourcesLimitIfItExists.
@Test
public void shouldProvideResourcesFromFreeResourcesLimitIfItExists() throws Exception {
// given
when(account.getType()).thenReturn("anotherTestType");
when(accountManager.getById(any())).thenReturn(account);
when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
// when
List<ProvidedResources> result = provider.getResources("account123");
// then
assertEquals(result.size(), 1);
ProvidedResources providedResources = result.get(0);
assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, "account123", "account123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
verify(freeResourcesLimitManager).get("account123");
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.
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