@Test public void testStatusReply() throws Exception { // Create status mockMvc .perform( post("/rest/statuses/") .contentType(MediaType.APPLICATION_JSON) .content("{\"content\":\"Test discussion\"}")) .andExpect(status().isOk()); String statusAsJson = mockMvc .perform(get("/rest/statuses/home_timeline").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType("application/json")) .andReturn() .getResponse() .getContentAsString(); Collection<StatusDTO> statusDTOs = new ObjectMapper().readValue(statusAsJson, new TypeReference<List<StatusDTO>>() {}); String statusId = statusDTOs.iterator().next().getStatusId(); mockMvc .perform( post("/rest/statuses/") .contentType(MediaType.APPLICATION_JSON) .content("{\"replyTo\":\"" + statusId + "\", \"content\":\"Reply discussion\"}")) .andExpect(status().isOk()); String replyAsJson = mockMvc .perform(get("/rest/statuses/home_timeline").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType("application/json")) .andReturn() .getResponse() .getContentAsString(); statusDTOs = new ObjectMapper().readValue(replyAsJson, new TypeReference<List<StatusDTO>>() {}); StatusDTO statusDTO = statusDTOs.iterator().next(); assertEquals("Reply discussion", statusDTO.getContent()); assertEquals(statusId, statusDTO.getReplyTo()); }
private void assertThatLineForUserWithStatusIsOk(String username, Collection<StatusDTO> status) { assertThat(status, notNullValue()); assertThat(status.size(), is(2)); StatusDTO firstStatus = (StatusDTO) status.toArray()[0]; assertThat(firstStatus.getStatusId(), is("fa2bd770-9848-11e1-a6ca-e0f847068d52")); assertThat(firstStatus.getUsername(), is(username)); assertThat(firstStatus.getContent(), is("Tatami is an enterprise social network")); StatusDTO secondStatus = (StatusDTO) status.toArray()[1]; assertThat(secondStatus.getStatusId(), is("f97d6470-9847-11e1-a6ca-e0f847068d52")); assertThat(secondStatus.getUsername(), is(username)); assertThat(secondStatus.getContent(), is("Tatami is fully Open Source")); }