问题描述
我想用 jpa 数据测试控制器。
我该怎么做?
我有这个控制器:
@RestController
@RequestMapping("/api")
public class AuthenticateController {
@Autowired private AuthenticationManager authenticationManager;
@Autowired private ClientRepository client;
@Autowired private JwtUtil jwt;
@Autowired private UserDetailsService details;
@PostMapping("/authenticate") public ResponseEntity<?> createAuthenticationToken(@RequestBody AuthenticationRequest authenticate) throws Exception {
try {
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authenticate.getIdentification(),authenticate.getpassword()));
}
catch (BadCredentialsException e) { throw new Exception("Incorrect username or password",e); }
final UserDetails userDetails = details.loadUser(authenticate.getIdentification());
final String jwt = this.jwt.generatetoken(userDetails);
final String identification = userDetails.getIdentification();
Client c = client.findByUsernameOrEmailOrPhone(identification,identification,identification).orElseThrow();
return ResponseEntity.ok(new AuthenticationResponse(jwt,c));
}
}
还有这个 jpa 数据
public interface ClientRepository extends JpaRepository<Client,Integer> {
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)