#804 - Avoid log output in MultiMediaTypeWebMvcIntegrationTests.

This commit is contained in:
Oliver Drotbohm
2019-02-07 20:21:41 +01:00
parent c0903cb33e
commit ca72790b4b

View File

@@ -19,7 +19,6 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
@@ -65,14 +64,15 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
/**
* Test one controller, rendered into multiple mediatypes.
*
* Test one controller, rendered into multiple media types.
*
* @author Greg Turnquist
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@WebAppConfiguration
@ContextConfiguration
public class MultiMediatypeWebMvcIntegrationTest {
public class MultiMediaTypeWebMvcIntegrationTest {
@Autowired WebApplicationContext context;
@@ -275,119 +275,113 @@ public class MultiMediatypeWebMvcIntegrationTest {
public void singleEmployeeUber() throws Exception {
this.mockMvc.perform(get("/employees/0").accept(MediaTypes.UBER_JSON)) //
.andDo(print())
.andExpect(status().isOk()) //
.andExpect(status().isOk()) //
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.data.*", hasSize(5)))
.andExpect(jsonPath("$.uber.data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data.*", hasSize(5))).andExpect(jsonPath("$.uber.data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].name", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[3].name", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[4].data.*", hasSize(2)))
.andExpect(jsonPath("$.uber.data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[4].data[0].value", is("ring bearer")))
.andExpect(jsonPath("$.uber.data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[4].data[1].value", is("Frodo Baggins")))
;
.andExpect(jsonPath("$.uber.data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[4].data.*", hasSize(2)))
.andExpect(jsonPath("$.uber.data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[4].data[0].value", is("ring bearer")))
.andExpect(jsonPath("$.uber.data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[4].data[1].value", is("Frodo Baggins")));
}
@Test
public void collectionOfEmployeesUber() throws Exception {
this.mockMvc.perform(get("/employees").accept(MediaTypes.UBER_JSON)) //
.andDo(print())
.andExpect(status().isOk()) //
.andExpect(status().isOk()) //
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.data.*", hasSize(4)))
.andExpect(jsonPath("$.uber.data.*", hasSize(4)))
.andExpect(jsonPath("$.uber.data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[0].name", is("self"))).andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[1].name", is("newEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("newEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[1].action", is("append")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[1].name", is("newEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("newEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[1].action", is("append")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[2].data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[2].data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[2].data[0].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[2].data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[2].data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[2].data[0].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[1].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[2].data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[1].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[2].data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[2].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].data[2].url", is("http://localhost/employees/0")))
.andExpect(jsonPath("$.uber.data[2].data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[2].data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[2].data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[2].data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[2].data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[2].data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[2].data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[0].value", is("ring bearer")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[1].value", is("Frodo Baggins")))
.andExpect(jsonPath("$.uber.data[2].data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[0].value", is("ring bearer")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[2].data[4].data[1].value", is("Frodo Baggins")))
.andExpect(jsonPath("$.uber.data[3].data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[3].data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[3].data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[3].data[0].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[3].data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[3].data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[3].data[0].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[1].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[3].data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[1].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[3].data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[2].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[3].data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[3].data[2].url", is("http://localhost/employees/1")))
.andExpect(jsonPath("$.uber.data[3].data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[3].data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[3].data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[3].data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[0].value", is("burglar")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[1].value", is("Bilbo Baggins")))
;
.andExpect(jsonPath("$.uber.data[3].data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[0].value", is("burglar")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[3].data[4].data[1].value", is("Bilbo Baggins")));
}
@Test
@@ -395,52 +389,44 @@ public class MultiMediatypeWebMvcIntegrationTest {
String input = MappingUtils.read(new ClassPathResource("../uber/create-employee.json", getClass()));
this.mockMvc.perform(post("/employees")
.content(input)
.contentType(MediaTypes.UBER_JSON))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(header().stringValues(HttpHeaders.LOCATION, "http://localhost/employees/2"));
this.mockMvc.perform(post("/employees").content(input).contentType(MediaTypes.UBER_JSON))
.andExpect(status().isCreated())
.andExpect(header().stringValues(HttpHeaders.LOCATION, "http://localhost/employees/2"));
this.mockMvc.perform(get("/employees/2").accept(MediaTypes.UBER_JSON))
.andDo(print())
.andExpect(status().isOk()) //
this.mockMvc.perform(get("/employees/2").accept(MediaTypes.UBER_JSON)).andExpect(status().isOk()) //
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.version", is("1.0")))
.andExpect(jsonPath("$.uber.data.*", hasSize(5)))
.andExpect(jsonPath("$.uber.data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data.*", hasSize(5))).andExpect(jsonPath("$.uber.data[0].name", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[0]", is("self")))
.andExpect(jsonPath("$.uber.data[0].rel[1]", is("findOne")))
.andExpect(jsonPath("$.uber.data[0].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[1].name", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].rel[0]", is("updateEmployee")))
.andExpect(jsonPath("$.uber.data[1].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data[1].action", is("replace")))
.andExpect(jsonPath("$.uber.data[1].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[2].name", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].rel[0]", is("partiallyUpdateEmployee")))
.andExpect(jsonPath("$.uber.data[2].url", is("http://localhost/employees/2")))
.andExpect(jsonPath("$.uber.data[2].action", is("partial")))
.andExpect(jsonPath("$.uber.data[2].model", is("name={name}&role={role}")))
.andExpect(jsonPath("$.uber.data[3].name", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[3].name", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[0]", is("employees")))
.andExpect(jsonPath("$.uber.data[3].rel[1]", is("all")))
.andExpect(jsonPath("$.uber.data[3].url", is("http://localhost/employees")))
.andExpect(jsonPath("$.uber.data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[4].data.*", hasSize(2)))
.andExpect(jsonPath("$.uber.data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[4].data[0].value", is("gardener")))
.andExpect(jsonPath("$.uber.data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[4].data[1].value", is("Samwise Gamgee")))
;
.andExpect(jsonPath("$.uber.data[4].name", is("employee")))
.andExpect(jsonPath("$.uber.data[4].data.*", hasSize(2)))
.andExpect(jsonPath("$.uber.data[4].data[0].name", is("role")))
.andExpect(jsonPath("$.uber.data[4].data[0].value", is("gardener")))
.andExpect(jsonPath("$.uber.data[4].data[1].name", is("name")))
.andExpect(jsonPath("$.uber.data[4].data[1].value", is("Samwise Gamgee")));
}
@RestController
static class EmployeeController {
@@ -573,7 +559,8 @@ public class MultiMediatypeWebMvcIntegrationTest {
@Configuration
@EnableWebMvc
@EnableHypermediaSupport(type = { HypermediaType.HAL, HypermediaType.COLLECTION_JSON, HypermediaType.HAL_FORMS, HypermediaType.UBER })
@EnableHypermediaSupport(
type = { HypermediaType.HAL, HypermediaType.COLLECTION_JSON, HypermediaType.HAL_FORMS, HypermediaType.UBER })
static class TestConfig {
@Bean