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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations