コード例 #1
0
  @Test
  public void testCreateWithErrors() throws Exception {
    MvcResult result =
        mvc.perform(
                post(BASE_URI, ObjectId.get().toHexString())
                    .principal(MockUser.mock())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(parser.encode(new CommentBody())))
            .andReturn();

    mvc.perform(asyncDispatch(result)).andExpect(status().isBadRequest());
  }
コード例 #2
0
 @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)));
 }
コード例 #3
0
 @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!!")));
 }
コード例 #4
0
 @Test
 public void testCreateComment() throws Exception {
   MvcResult action =
       mvc.perform(
               post(BASE_URI, ObjectId.get().toHexString())
                   .principal(MockUser.mock())
                   .contentType(MediaType.APPLICATION_JSON)
                   .accept(MediaType.APPLICATION_JSON)
                   .content(parser.encode(contentBody("#foos"))))
           .andExpect(request().asyncStarted())
           .andExpect(request().asyncResult(instanceOf(ResponseEntity.class)))
           .andReturn();
   mvc.perform(asyncDispatch(action))
       .andExpect(status().isCreated())
       .andExpect(content().contentType(MediaType.APPLICATION_JSON))
       .andExpect(jsonPath("$.id").isString())
       .andExpect(jsonPath("$.inn").isString())
       .andExpect(jsonPath("$.content", is("#foos")))
       .andExpect(jsonPath("$.author", is(1)));
 }