Search in sources :

Example 11 with FreeResourcesLimit

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");
}
Also used : Response(io.restassured.response.Response) FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) FreeResourcesLimitDto(org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto) Test(org.testng.annotations.Test)

Example 12 with FreeResourcesLimit

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();
    }
}
Also used : ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) HashMap(java.util.HashMap) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) Resource(org.eclipse.che.multiuser.resource.model.Resource) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Aggregations

FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)12 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)10 Test (org.testng.annotations.Test)10 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 HashMap (java.util.HashMap)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 Resource (org.eclipse.che.multiuser.resource.model.Resource)2 ResourceDto (org.eclipse.che.multiuser.resource.shared.dto.ResourceDto)2 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)2