http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd\r
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">\r
\r
+ <!--\r
+ I am declaring my beans without the automatic annotation. :/\r
+ Better because we are saving memory but it requires more configuration.\r
+ \r
+ See: org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser\r
+ <mvc:annotation-driven/>\r
+ -->\r
+ \r
+ \r
<context:annotation-config />\r
\r
<context:component-scan base-package="de.spring.webservices.rest"/>\r
</bean>\r
</property>\r
<property name="messageConverters" ref="messageConverters" />\r
+ \r
+ \r
+ <property name="requestBodyAdvice">\r
+ <util:list>\r
+ <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>\r
+ </util:list>\r
+ </property>\r
+ \r
+ \r
<property name="responseBodyAdvice">\r
<util:list>\r
<bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>\r
@Test
public void testWhenGetAllCarsThenRetrieveJsonValues() throws Exception {
mockMvc.perform(get("/api/cars/")
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].id", any(Integer.class)))
.andExpect(jsonPath("$[1].id", any(Integer.class)))
.andExpect(jsonPath("$[2].content", is("Car: 3")))
.andExpect(jsonPath("$[2].id", any(Integer.class)))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
@Test
public void testWhenGetOneCarThenRetrieveJsonValue() throws Exception {
mockMvc.perform(get("/api/cars/{id}", 1L)
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("id", any(Integer.class)))
.andExpect(jsonPath("content", is("Car: 1")))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
@Test
public void testWhenCreateNewCarThenRetrieveJsonValue() throws Exception {
Car car = new Car(2L, "nothing");
mockMvc.perform(post("/api/cars/")
- .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_UTF8)
.content(asJsonString(car))
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isCreated())
.andExpect(jsonPath("id", any(Integer.class)))
.andExpect(jsonPath("content", is("Car: 1")))
.andExpect(header().string(HttpHeaders.LOCATION, "/api/cars/1"))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
private static String asJsonString(final Object obj) throws JsonProcessingException {