use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.
the class OrganizationResourcesDistributionServiceTest method shouldCapOrganizationResources.
@Test
public void shouldCapOrganizationResources() throws Exception {
ResourceDto resource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1020).withUnit("unit");
List<ResourceDto> resources = singletonList(resource);
given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(resources).when().post(SECURE_PATH + "/organization/resource/organization123/cap").then().assertThat().statusCode(204);
verify(organizationResourcesManager).capResources("organization123", resources);
verify(resourceValidator).validate(resource);
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.
the class OrganizationResourcesDistributionServiceTest method shouldReturn400WhenBodyContainTwoResourcesWithTheSameTypeOnDistributingOrganizationResources.
@Test
public void shouldReturn400WhenBodyContainTwoResourcesWithTheSameTypeOnDistributingOrganizationResources() throws Exception {
List<ResourceDto> resources = Arrays.asList(DtoFactory.newDto(ResourceDto.class).withType("test"), DtoFactory.newDto(ResourceDto.class).withType("test"));
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(resources).when().post(SECURE_PATH + "/organization/resource/organization123/cap");
assertEquals(response.statusCode(), 400);
String errorMessage = DtoFactory.getInstance().createDtoFromJson(response.print(), ServiceError.class).getMessage();
assertEquals(errorMessage, "Resources to cap must contain only one resource with type 'test'.");
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.
the class OrganizationResourcesDistributionServiceTest method shouldReturnResourcesCapForSuborganization.
@Test
public void shouldReturnResourcesCapForSuborganization() throws Exception {
final ResourceDto resourcesCap = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1020).withUnit("unit");
final List<ResourceDto> toFetch = singletonList(resourcesCap);
doReturn(toFetch).when(organizationResourcesManager).getResourcesCaps(any());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/organization/resource/organization123/cap");
assertEquals(response.statusCode(), 200);
final List<ResourceDto> fetched = unwrapDtoList(response, ResourceDto.class);
assertEquals(fetched.size(), 1);
assertTrue(fetched.contains(resourcesCap));
verify(organizationResourcesManager).getResourcesCaps("organization123");
}
use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project devspaces-images by redhat-developer.
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 ResourceServiceTest method shouldReturnTotalResourcesForGivenAccount.
@Test
public void shouldReturnTotalResourcesForGivenAccount() throws Exception {
doReturn(singletonList(resource)).when(resourceManager).getTotalResources(any());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123");
assertEquals(response.statusCode(), 200);
verify(resourceManager).getTotalResources(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);
}
Aggregations