use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project devspaces-images by redhat-developer.
the class ResourceServiceTest method shouldReturnAvailableResourcesForGivenAccount.
@Test
public void shouldReturnAvailableResourcesForGivenAccount() throws Exception {
doReturn(singletonList(resource)).when(resourceManager).getAvailableResources(any());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/available");
assertEquals(response.statusCode(), 200);
verify(resourceManager).getAvailableResources(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 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 devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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 OrganizationResourcesDistributionService method capResources.
@POST
@Path("/{suborganizationId}/cap")
@Consumes(APPLICATION_JSON)
@Operation(summary = "Cap usage of shared resources.. By default suborganization is able to use all parent organization resources." + "Cap allow to limit usage of shared resources by suborganization.", responses = { @ApiResponse(responseCode = "204", description = "Resources successfully capped"), @ApiResponse(responseCode = "400", description = "Missed required parameters, parameters are not valid"), @ApiResponse(responseCode = "404", description = "Specified organization was not found"), @ApiResponse(responseCode = "409", description = "Specified organization is root organization"), @ApiResponse(responseCode = "409", description = "Suborganization is using shared resources"), @ApiResponse(responseCode = "500", description = "Internal server error occurred") })
public void capResources(@Parameter(description = "Suborganization id") @PathParam("suborganizationId") String suborganizationId, @Parameter(description = "Resources to cap") List<ResourceDto> resourcesCap) throws BadRequestException, NotFoundException, ConflictException, ServerException {
checkArgument(resourcesCap != null, "Missed resources caps.");
Set<String> resourcesToSet = new HashSet<>();
for (ResourceDto resource : resourcesCap) {
if (!resourcesToSet.add(resource.getType())) {
throw new BadRequestException(format("Resources to cap must contain only one resource with type '%s'.", resource.getType()));
}
resourceValidator.validate(resource);
}
resourcesDistributor.capResources(suborganizationId, resourcesCap);
}
Aggregations