@Test public final void testUpdatePerson() throws Exception { Person person = createSamplePerson(); Mockito.when(peopleServiceMock.updatePerson(Mockito.any(Person.class))).thenReturn(person); mockMvc .perform( MockMvcRequestBuilders.post("/person/update") .contentType(MediaType.APPLICATION_JSON) .content(JSONUtil.toJSonString(person).getBytes())) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(JSONUtil.toJSonString(person))); }
@Test public final void testAddFamily() throws Exception { Family family = createSampleFamily(); Mockito.when(peopleServiceMock.addFamily(Mockito.any(Family.class))).thenReturn(family); mockMvc .perform( MockMvcRequestBuilders.post("/family") .contentType(MediaType.APPLICATION_JSON) .content(JSONUtil.toJSonString(family).getBytes())) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(JSONUtil.toJSonString(family))); }
@Test public final void testGetFamily() throws Exception { Family family = createSampleFamily(); Mockito.when(peopleServiceMock.getFamily(new Long(1))).thenReturn(family); mockMvc .perform(MockMvcRequestBuilders.get("/family/1").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(MockMvcResultMatchers.content().string(JSONUtil.toJSonString(family))); }
@Test public final void testFindPerson() throws Exception { Person person = createSamplePerson(); List<Person> list = new ArrayList<Person>(); list.add(person); Mockito.when(peopleServiceMock.findPerson("Andy")).thenReturn(list); mockMvc .perform(MockMvcRequestBuilders.get("/person/find/Andy").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(MockMvcResultMatchers.content().string(JSONUtil.toJSonString(list))); }
@Test public final void testFindFamily() throws Exception { Family family = createSampleFamily(); List<Family> list = new ArrayList<Family>(); list.add(family); Mockito.when(peopleServiceMock.findFamily("Weber")).thenReturn(list); mockMvc .perform( MockMvcRequestBuilders.get("/family/find/Weber").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(MockMvcResultMatchers.content().string(JSONUtil.toJSonString(list))); }