use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto 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.ResourceDto in project che-server by eclipse-che.
the class ResourceValidatorTest method shouldSetDefaultResourceUnitWhenItIsMissed.
@Test
public void shouldSetDefaultResourceUnitWhenItIsMissed() throws Exception {
// given
ResourceDto toValidate = DtoFactory.newDto(ResourceDto.class).withType(RESOURCE_TYPE).withUnit(null);
// when
validator.validate(toValidate);
// then
assertEquals(toValidate.getUnit(), DEFAULT_RESOURCE_UNIT);
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.
the class ResourceServiceTest method shouldReturnUsedResourcesForGivenAccount.
@Test
public void shouldReturnUsedResourcesForGivenAccount() throws Exception {
doReturn(singletonList(resource)).when(resourceManager).getUsedResources(any());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/used");
assertEquals(response.statusCode(), 200);
verify(resourceManager).getUsedResources(eq("account123"));
final List<ResourceDto> resources = unwrapDtoList(response, ResourceDto.class);
assertEquals(resources.size(), 1);
final ResourceDto fetchedResource = resources.get(0);
assertEquals(fetchedResource.getType(), RESOURCE_TYPE);
assertEquals(new Long(fetchedResource.getAmount()), RESOURCE_AMOUNT);
assertEquals(fetchedResource.getUnit(), RESOURCE_UNIT);
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project devspaces-images by redhat-developer.
the class ResourceValidatorTest method shouldSetDefaultResourceUnitWhenItIsMissed.
@Test
public void shouldSetDefaultResourceUnitWhenItIsMissed() throws Exception {
// given
ResourceDto toValidate = DtoFactory.newDto(ResourceDto.class).withType(RESOURCE_TYPE).withUnit(null);
// when
validator.validate(toValidate);
// then
assertEquals(toValidate.getUnit(), DEFAULT_RESOURCE_UNIT);
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project devspaces-images by redhat-developer.
the class ResourceServiceTest method testGetsResourceDetails.
@Test
public void testGetsResourceDetails() throws Exception {
// given
final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
// when
when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
// then
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
assertEquals(response.statusCode(), 200);
final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
assertEquals(resourceDetailsDto, toFetch);
verify(resourceManager).getResourceDetails("account123");
}
Aggregations