Search in sources :

Example 86 with MappingJackson2HttpMessageConverter

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!"));
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JsonPath(io.restassured.path.json.JsonPath) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 87 with MappingJackson2HttpMessageConverter

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!"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) JsonPath(io.restassured.path.json.JsonPath) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 88 with MappingJackson2HttpMessageConverter

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;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 89 with MappingJackson2HttpMessageConverter

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;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule)

Example 90 with MappingJackson2HttpMessageConverter

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);
}
Also used : MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Aggregations

MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)122 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)51 ArrayList (java.util.ArrayList)46 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)38 Test (org.junit.jupiter.api.Test)28 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)25 RestTemplate (org.springframework.web.client.RestTemplate)25 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)20 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)19 HandlerMethod (org.springframework.web.method.HandlerMethod)17 Method (java.lang.reflect.Method)16 Test (org.junit.Test)16 MethodParameter (org.springframework.core.MethodParameter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Bean (org.springframework.context.annotation.Bean)14 List (java.util.List)9 HttpEntity (org.springframework.http.HttpEntity)7 MediaType (org.springframework.http.MediaType)6 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)6