Search in sources :

Example 6 with ResourceDto

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

Example 7 with ResourceDto

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'.");
}
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 8 with ResourceDto

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

Example 9 with ResourceDto

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

Example 10 with ResourceDto

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

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