Search in sources :

Example 11 with OrganizationDto

use of org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldThrowBadRequestWhenCreatingNonValidOrganization.

@Test
public void shouldThrowBadRequestWhenCreatingNonValidOrganization() throws Exception {
    doThrow(new BadRequestException("non valid organization")).when(validator).checkOrganization(any());
    final OrganizationDto toCreate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toCreate).when().post(SECURE_PATH + "/organization");
    assertEquals(response.statusCode(), 400);
    final ServiceError error = unwrapDto(response, ServiceError.class);
    assertEquals(error.getMessage(), "non valid organization");
    verify(validator).checkOrganization(toCreate);
}
Also used : Response(io.restassured.response.Response) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) BadRequestException(org.eclipse.che.api.core.BadRequestException) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) Test(org.testng.annotations.Test)

Example 12 with OrganizationDto

use of org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldThrowBadRequestWhenUpdatingNonValidOrganization.

@Test
public void shouldThrowBadRequestWhenUpdatingNonValidOrganization() throws Exception {
    doThrow(new BadRequestException("non valid organization")).when(validator).checkOrganization(any());
    final OrganizationDto toUpdate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toUpdate).when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.statusCode(), 400);
    final ServiceError error = unwrapDto(response, ServiceError.class);
    assertEquals(error.getMessage(), "non valid organization");
    verify(validator).checkOrganization(toUpdate);
}
Also used : Response(io.restassured.response.Response) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) BadRequestException(org.eclipse.che.api.core.BadRequestException) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) Test(org.testng.annotations.Test)

Example 13 with OrganizationDto

use of org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldUpdateOrganization.

@Test
public void shouldUpdateOrganization() throws Exception {
    when(orgManager.update(anyString(), any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[1]));
    final OrganizationDto toUpdate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toUpdate).when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.statusCode(), 200);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toUpdate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).update(eq("organization123"), eq(toUpdate));
}
Also used : Response(io.restassured.response.Response) Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 14 with OrganizationDto

use of org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldFindOrganizationByName.

@Test
public void shouldFindOrganizationByName() throws Exception {
    final OrganizationDto toFetch = createOrganization();
    when(orgManager.getByName(eq("subOrg"))).thenReturn(toFetch);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").get(SECURE_PATH + "/organization/find?name=subOrg");
    assertEquals(response.statusCode(), 200);
    final OrganizationDto fetchedOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(fetchedOrganization, toFetch);
    verify(orgManager).getByName(eq("subOrg"));
    verify(linksInjector).injectLinks(any(), any());
}
Also used : Response(io.restassured.response.Response) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) Test(org.testng.annotations.Test)

Example 15 with OrganizationDto

use of org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto in project devspaces-images by redhat-developer.

the class OrganizationServiceTest method shouldCreateOrganization.

@Test
public void shouldCreateOrganization() throws Exception {
    when(orgManager.create(any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[0]));
    final OrganizationDto toCreate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toCreate).when().post(SECURE_PATH + "/organization");
    assertEquals(response.statusCode(), 201);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toCreate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).create(eq(toCreate));
}
Also used : Response(io.restassured.response.Response) Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Aggregations

OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)22 Test (org.testng.annotations.Test)20 Response (io.restassured.response.Response)18 Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)6 BadRequestException (org.eclipse.che.api.core.BadRequestException)4 ServiceError (org.eclipse.che.api.core.rest.shared.dto.ServiceError)4 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 Subject (org.eclipse.che.commons.subject.Subject)2