Search in sources :

Example 66 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class FreeResourcesLimitServiceTest method shouldReturnResourcesLimits.

@Test
public void shouldReturnResourcesLimits() throws Exception {
    FreeResourcesLimit resourcesLimit1 = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    FreeResourcesLimit resourcesLimit2 = new FreeResourcesLimitImpl("account321", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 2000, "unit")));
    doReturn(new Page<>(Arrays.asList(resourcesLimit1, resourcesLimit2), 1, 2, 2)).when(freeResourcesLimitManager).getAll(anyInt(), anyInt());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/free?skipCount=1&maxItems=5");
    assertEquals(response.statusCode(), 200);
    final List<FreeResourcesLimitDto> freeResourcesLimits = unwrapDtoList(response, FreeResourcesLimitDto.class);
    assertEquals(freeResourcesLimits.size(), 2);
    assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit1)));
    assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit2)));
    verify(freeResourcesLimitManager).getAll(5, 1);
}
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 67 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class AbstractExhaustibleResource method deduct.

@Override
public Resource deduct(Resource total, Resource deduction) throws NoEnoughResourcesException {
    checkResource(total);
    checkResource(deduction);
    if (total.getAmount() == -1) {
        return total;
    }
    if (deduction.getAmount() == -1) {
        throw new NoEnoughResourcesException(total, deduction, deduction);
    }
    final long resultAmount = total.getAmount() - deduction.getAmount();
    if (resultAmount < 0) {
        throw new NoEnoughResourcesException(total, deduction, new ResourceImpl(getId(), -resultAmount, getDefaultUnit()));
    }
    return new ResourceImpl(getId(), resultAmount, getDefaultUnit());
}
Also used : NoEnoughResourcesException(org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)

Example 68 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class FreeResourcesLimitServiceTest method shouldStoreResourcesLimit.

@Test
public void shouldStoreResourcesLimit() throws Exception {
    FreeResourcesLimit toCreate = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    FreeResourcesLimit created = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    when(freeResourcesLimitManager.store(any())).thenReturn(created);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoConverter.asDto(toCreate)).when().post(SECURE_PATH + "/resource/free");
    assertEquals(response.statusCode(), 201);
    final FreeResourcesLimitDto result = unwrapDto(response, FreeResourcesLimitDto.class);
    assertEquals(DtoConverter.asDto(created), result);
    verify(freeResourcesLimitManager).store(DtoConverter.asDto(toCreate));
    verify(resourcesLimitValidator).check(any());
}
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 69 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

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 70 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class AbstractExhaustibleResourceTest method shouldReturnResourceWithMinusOneAmountWhenFirstResourceHasMinusOneAmountOnResourcesDeduction.

@Test
public void shouldReturnResourceWithMinusOneAmountWhenFirstResourceHasMinusOneAmountOnResourcesDeduction() throws Exception {
    final Resource aggregate = resourceType.aggregate(new ResourceImpl(TestResourceType.ID, -1, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
    assertEquals(aggregate.getType(), TestResourceType.ID);
    assertEquals(aggregate.getAmount(), -1);
    assertEquals(aggregate.getUnit(), TestResourceType.UNIT);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Aggregations

ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)138 Test (org.testng.annotations.Test)116 Resource (org.eclipse.che.multiuser.resource.model.Resource)24 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)20 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)20 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)14 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 AccountManager (org.eclipse.che.account.api.AccountManager)8 Account (org.eclipse.che.account.shared.model.Account)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)8 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Singleton (javax.inject.Singleton)6 Pages (org.eclipse.che.api.core.Pages)6