@Test public void testCreateInvalidModel() throws Exception { Location location = new Location(null, null); String json = JackSONUtils.toJSON(location); LOG.info("location json: " + json); // -------- Request --------// MockHttpServletRequestBuilder requestBuilder = post(resourcePath).content(json); ResultActions resultActions = mockMvc.perform( requestBuilder .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)); // -------- Response --------// // Check: Status == 400 (bad request) resultActions.andExpect(status().isBadRequest()); ResultActionsUtil.log(resultActions); }
@Test public void testFetchAll() throws Exception { // Create 3 for (int i = 0; i < 3; i++) { String json = JackSONUtils.toJSON(new Location(null, "karbing")); LOG.info("location json: " + json); mockMvc.perform( post(resourcePath) .content(json) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)); } // Fetch MockHttpServletRequestBuilder requestBuilder = get(resourcePath); ResultActions resultActions = mockMvc.perform(requestBuilder.accept(MediaType.APPLICATION_JSON)); resultActions .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)); // debug the result // ResultActionsUtil.log(resultActions); }