@Test public void allowsPostRequestForAdmin() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE); headers.set( HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("ollie:gierke").getBytes()))); mvc.perform( get("/employees") . // headers(headers)) . // andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) . // andExpect(status().isOk()) . // andDo(print()); headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); String location = mvc.perform( post("/employees") . // content(PAYLOAD) . // headers(headers)) . // andExpect(status().isCreated()) . // andDo(print()) . // andReturn() .getResponse() .getHeader(HttpHeaders.LOCATION); ObjectMapper mapper = new ObjectMapper(); String content = mvc.perform(get(location)) . // andReturn() .getResponse() .getContentAsString(); Employee employee = mapper.readValue(content, Employee.class); assertThat(employee.getFirstName(), is("Saruman")); assertThat(employee.getLastName(), is("the White")); assertThat(employee.getTitle(), is("Wizard")); }
@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))); }