Spring MvcTest控制器@WithUserData使用@AuthenticationProtocol

时间:2018-11-21 06:39:22

标签: java spring spring-mvc spring-boot

我正在测试一个接受@AuthenticationProtocol Customer cusomer的Spring控制器,而Customer扩展了UserDetails注释所需要的@WithUserDetails来进行测试(下面讨论)。

控制器方法声明如下:

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

运行测试后,我在控制器中获得的客户值都为空。我尝试使用@WebMvcTest@SpringBootTest(自动配置MockMvc)进行测试,结果相同。对于@SpringBootTest,我制作了一个带有UserDetailsService @Bean的自定义类,该类返回了我的自定义客户。是否可以定义我的自定义UserData模型的来源? / p>

0 个答案:

没有答案