Search in sources :

Example 1 with FreeResourcesLimit

use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project che-server by eclipse-che.

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 2 with FreeResourcesLimit

use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project che-server by eclipse-che.

the class FreeResourceManagerTest method shouldStoreFreeResourcesLimit.

@Test
public void shouldStoreFreeResourcesLimit() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    ResourceDto resourceDto = DtoFactory.newDto(ResourceDto.class).withAmount(1).withType(TEST_RESOURCE_TYPE).withUnit("unit");
    FreeResourcesLimitDto freeResourcesLimitDto = DtoFactory.newDto(FreeResourcesLimitDto.class).withAccountId("account123").withResources(singletonList(resourceDto));
    // when
    FreeResourcesLimit storedLimit = manager.store(freeResourcesLimitDto);
    // then
    assertEquals(storedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).store(resourcesLimitImpl);
}
Also used : 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) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 3 with FreeResourcesLimit

use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project che-server by eclipse-che.

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)

Example 4 with FreeResourcesLimit

use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit in project devspaces-images by redhat-developer.

the class FreeResourceManagerTest method shouldStoreFreeResourcesLimit.

@Test
public void shouldStoreFreeResourcesLimit() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    ResourceDto resourceDto = DtoFactory.newDto(ResourceDto.class).withAmount(1).withType(TEST_RESOURCE_TYPE).withUnit("unit");
    FreeResourcesLimitDto freeResourcesLimitDto = DtoFactory.newDto(FreeResourcesLimitDto.class).withAccountId("account123").withResources(singletonList(resourceDto));
    // when
    FreeResourcesLimit storedLimit = manager.store(freeResourcesLimitDto);
    // then
    assertEquals(storedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).store(resourcesLimitImpl);
}
Also used : 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) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 5 with FreeResourcesLimit

use of org.eclipse.che.multiuser.resource.model.FreeResourcesLimit 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)

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