Since TestRestTemplate won't work in conjuction with the useful @DataJpaTest annotation, so there's an issue how to integration test a controller having dedicated embedded database at the classpath without lots of configuration.
Spring doc offers to use slice approach to test a controller, but have no idea how to use it with the following common structure:
@RequestMapping(value="/Person/Add", method=RequestMethod.POST)
public ResponseEntity checkPersonInfo(@Valid @RequestBody PersonForm personForm,
Errors errors) {
personValidator.validate(personForm, errors):
if (errors.hasErrors())
return new ResponseEntity(HttpStatus.BAD_REQUEST);
personService.add(personForm);
return new ResponseEntity(HttpStatus.OK);
}
It's easy to mock the personService as it offers the slice approach but how to be with .validate() method that returns nothing so there's no opts to mock? This moment forces me to run the full-value integration test for the controller. But there's another fail, I cannot query for the controller using TestRestTemplate that uses autoconfigured embedded database specified by @DataJpaTest in bounds of the same class.
So there's a question how to test such controller architecture using Spring Boot testing features without real (not-embedded) database?
Aucun commentaire:
Enregistrer un commentaire