use of org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto 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);
}
use of org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto 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);
}
use of org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto 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);
}
use of org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto 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);
}
use of org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto 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());
}
Aggregations