@Test public void testDeleteOne() throws Exception { MvcResult deleteComment = mvc.perform( delete("/inns/{innId}/comments/{comment}", comment.getInn(), comment.getId()) .principal(MockUser.mock())) .andExpect(request().asyncStarted()) .andReturn(); mvc.perform(asyncDispatch(deleteComment)).andExpect(status().isNoContent()); assertThat( "Object must not exist after deletion", repo.findOne(comment.getId()), is(nullValue(Comment.class))); }
@Test public void testEditComment() throws Exception { MvcResult editAction = mvc.perform( put("/inns/{innId}/comments/{comment}", comment.getInn(), comment.getId()) .principal(MockUser.mock()) .contentType(MediaType.APPLICATION_JSON) .content(parser.encode(contentBody("The pool is awesome, you should try it!!"))) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(request().asyncResult(instanceOf(ResponseEntity.class))) .andReturn(); mvc.perform(asyncDispatch(editAction)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").isString()) .andExpect(jsonPath("$.content", is("The pool is awesome, you should try it!!"))); }
@Test public void testCommentsByInn() throws Exception { MvcResult result = mvc.perform(get(BASE_URI, comment.getInn())) .andExpect(request().asyncStarted()) .andExpect(request().asyncResult(instanceOf(ResponseEntity.class))) .andReturn(); mvc.perform(asyncDispatch(result)) .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.comments").isArray()) .andExpect(jsonPath("_embedded.comments").isArray()) .andExpect(jsonPath("_embedded.comments.[0].id").exists()); }