Search in sources :

Example 96 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryListByNameAttribute.

@Test
public void shouldReturnFactoryListByNameAttribute() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.getByAttribute(1, 0, ImmutableList.of(Pair.of("factory.name", factory.getName())))).thenReturn(ImmutableList.of(factory));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).when().expect().statusCode(200).get(SERVICE_PATH + "/find?maxItems=1&skipCount=0&factory.name=" + factory.getName());
    final List<FactoryDto> res = unwrapDtoList(response, FactoryDto.class);
    assertEquals(res.size(), 1);
    assertEquals(res.get(0).withLinks(emptyList()), asDto(factory, user));
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 97 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryByIdentifierWithValidation.

@Test
public void shouldReturnFactoryByIdentifierWithValidation() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    when(factoryManager.getFactoryImages(FACTORY_ID)).thenReturn(emptySet());
    doNothing().when(acceptValidator).validateOnAccept(any(FactoryDto.class));
    final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID + "?validate=true");
    assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 98 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithoutImages.

@Test
public void shouldSaveFactoryWithoutImages() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.saveFactory(any(FactoryDto.class))).thenReturn(factory);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(ContentType.JSON).body(factoryDto).expect().statusCode(200).post(SERVICE_PATH);
    assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 99 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithImagesFromFormData.

@Test
public void shouldSaveFactoryWithImagesFromFormData() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", JsonHelper.toJson(factoryDto), APPLICATION_JSON).multiPart("image", getImagePath().toFile(), FACTORY_IMAGE_MIME_TYPE).expect().statusCode(200).when().post(SERVICE_PATH);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    final boolean found = result.getLinks().stream().anyMatch(link -> link.getRel().equals("image") && link.getProduces().equals(FACTORY_IMAGE_MIME_TYPE) && !link.getHref().isEmpty());
    factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
    assertEquals(result, factoryDto);
    assertTrue(found);
}
Also used : Response(com.jayway.restassured.response.Response) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 100 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithImagesWhenImagesWithoutContent.

@Test
public void shouldSaveFactoryWithImagesWhenImagesWithoutContent() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    final FactoryDto factoryDto = asDto(factory, user);
    doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", DTO.toJson(factoryDto), APPLICATION_JSON).multiPart("image", File.createTempFile("img", ".jpeg"), "image/jpeg").expect().statusCode(200).when().post(SERVICE_PATH);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    verify(factoryManager).saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class));
    factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
    assertEquals(result, factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Aggregations

Response (com.jayway.restassured.response.Response)169 Test (org.testng.annotations.Test)129 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)35 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)31 Test (org.junit.Test)31 Matchers.anyString (org.mockito.Matchers.anyString)21 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)19 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)15 IOException (java.io.IOException)14 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 XPathExpressionException (javax.xml.xpath.XPathExpressionException)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Factory (org.eclipse.che.api.core.model.factory.Factory)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)11 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 InputStream (java.io.InputStream)6