My request has a body and test is finished, but I need test response body but this is empty, why ???
@RunWith(SpringRunner.class)
@WebMvcTest(RentalController.class)
public class RentalControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private RentalService rentalService;
@MockBean
private RentalMapper rentalMapper;
@Test
public void shouldReturnRentalByUsername() throws Exception {
User user = new User(1L,"janek22", "janek", "janek2@wp.pl");
Bike bike = new Bike("AB123", false);
LocalDateTime dateTime = LocalDateTime.of(2019,5,24,1,0,0);
Rental rental = new Rental(user, bike, dateTime , dateTime,
"22.222", "33.444", "33.444", "33.444", "33.444" );
given(rentalService.findByUsername(anyString())).willReturn(Collections.singletonList(rental));
ObjectMapper objectMapper = new ObjectMapper();
String content = objectMapper.writeValueAsString(user);
mockMvc.perform(get("/rental/" + user.getUsername())
.contentType(MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE)
.content(content))
.andExpect(status().isOk())
.andDo(print());
}
}
MockHttpServletResponse:
Status = 200
Error message = null
Headers = [Content-Type:"application/json;charset=UTF-8"]
Content type = application/json;charset=UTF-8
Body = []
Forwarded URL = null
Redirected URL = null
Cookies = []
Aucun commentaire:
Enregistrer un commentaire