use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project devspaces-images by redhat-developer.
the class FreeResourcesLimitServiceTest method shouldReturnResourcesLimitForGivenAccount.
@Test
public void shouldReturnResourcesLimitForGivenAccount() throws Exception {
FreeResourcesLimit resourcesLimit = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
when(freeResourcesLimitManager.get("account123")).thenReturn(resourcesLimit);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/free/account123");
assertEquals(response.statusCode(), 200);
final FreeResourcesLimitDto fetchedLimit = unwrapDto(response, FreeResourcesLimitDto.class);
assertEquals(fetchedLimit, DtoConverter.asDto(resourcesLimit));
verify(freeResourcesLimitManager).get("account123");
}
use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project devspaces-images by redhat-developer.
the class FreeResourcesProvider method getResources.
@Override
public List<ProvidedResources> getResources(String accountId) throws ServerException, NotFoundException {
Map<String, ResourceImpl> freeResources = new HashMap<>();
String limitId = null;
try {
FreeResourcesLimit resourcesLimit = freeResourcesLimitManager.get(accountId);
for (Resource resource : resourcesLimit.getResources()) {
freeResources.put(resource.getType(), new ResourceImpl(resource));
}
limitId = resourcesLimit.getAccountId();
} catch (NotFoundException ignored) {
// there is no resources limit for given account
}
// add default resources which are not specified by limit
for (ResourceImpl resource : getDefaultResources(accountId)) {
freeResources.putIfAbsent(resource.getType(), resource);
}
if (!freeResources.isEmpty()) {
return singletonList(new ProvidedResourcesImpl(FREE_RESOURCES_PROVIDER, limitId, accountId, -1L, -1L, freeResources.values()));
} else {
return emptyList();
}
}
Aggregations