Search in sources :

Example 16 with ResourceDto

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);
}
Also used : Response(io.restassured.response.Response) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 17 with ResourceDto

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);
}
Also used : ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 18 with ResourceDto

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'.");
}
Also used : Response(io.restassured.response.Response) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 19 with ResourceDto

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");
}
Also used : Response(io.restassured.response.Response) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 20 with ResourceDto

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);
}
Also used : BadRequestException(org.eclipse.che.api.core.BadRequestException) HashSet(java.util.HashSet) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

ResourceDto (org.eclipse.che.multiuser.resource.shared.dto.ResourceDto)20 Test (org.testng.annotations.Test)18 Response (io.restassured.response.Response)12 Operation (io.swagger.v3.oas.annotations.Operation)2 Consumes (jakarta.ws.rs.Consumes)2 POST (jakarta.ws.rs.POST)2 Path (jakarta.ws.rs.Path)2 HashSet (java.util.HashSet)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 ServiceError (org.eclipse.che.api.core.rest.shared.dto.ServiceError)2 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)2 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)2 ProvidedResourcesDto (org.eclipse.che.multiuser.resource.shared.dto.ProvidedResourcesDto)2 ResourcesDetailsDto (org.eclipse.che.multiuser.resource.shared.dto.ResourcesDetailsDto)2 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)2 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)2 ResourcesDetailsImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl)2