use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project rest-assured by rest-assured.
the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_post_greeting_controller.
@Test
public void mock_mvc_example_for_post_greeting_controller() throws Exception {
MockMvc mockMvc = standaloneSetup(new PostController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
String contentAsString = mockMvc.perform(post("/greetingPost").param("name", "Johan").contentType(MediaType.APPLICATION_FORM_URLENCODED)).andReturn().getResponse().getContentAsString();
JsonPath jsonPath = new JsonPath(contentAsString);
assertThat(jsonPath.getInt("id"), equalTo(1));
assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project rest-assured by rest-assured.
the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_get_greeting_controller.
@Test
public void mock_mvc_example_for_get_greeting_controller() throws Exception {
MockMvc mockMvc = standaloneSetup(new GreetingController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
String contentAsString = mockMvc.perform(get("/greeting?name={name}", "Johan").accept(APPLICATION_JSON)).andReturn().getResponse().getContentAsString();
JsonPath jsonPath = new JsonPath(contentAsString);
assertThat(jsonPath.getInt("id"), equalTo(1));
assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project nakadi by zalando.
the class WebConfig method mappingJackson2HttpMessageConverter.
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(objectMapper);
return converter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project taskana by Taskana.
the class TaskControllerIntTest method getRestTemplate.
/**
* Return a REST template which is capable of dealing with responses in HAL format
*
* @return RestTemplate
*/
private RestTemplate getRestTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
converter.setObjectMapper(mapper);
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
return template;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project thingsboard by thingsboard.
the class AbstractControllerTest method readResponse.
@SuppressWarnings("unchecked")
protected <T> T readResponse(ResultActions result, Class<T> responseClass) throws Exception {
byte[] content = result.andReturn().getResponse().getContentAsByteArray();
MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(content);
HttpMessageConverter converter = responseClass.equals(String.class) ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
return (T) converter.read(responseClass, mockHttpInputMessage);
}
Aggregations