1

I am testing a Spring controller which accepts @AuthenticationProtocol Customer cusomer and Customer extends the UserDetails which is needed by the @WithUserDetails annotation for the test (Discussed Below).

The controller methods declaration is as follows:

@RequestMapping(value = "/deposit/address/test", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public CryptoAddressQrCodeResponse forTheTest(@AuthenticationPrincipal Customer customer)

After running the test, The customer values I get in the controller are all null. I tried the testing with @WebMvcTest and @SpringBootTest (Auto configured MockMvc) and I get the same results. For the @SpringBootTest, I made a custom class with a UserDetailsService @Bean which returns my custom customers.Is there a way to define the source of my custom UserData model ?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224

0 Answers0