디바이스로 Rest 컨트롤러가 있습니다. (디바이스는 resolvem이어야하며 spring-mobile-device를 매개 변수로 사용하고 있습니다). 단위 테스트는 당신이 잘못 요청을 구축하는 테스트 클래스에서RestController를 스프링 모바일 (Spring-mobile-device)로 시작하는 방법
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> authenticationRequest(@RequestBody AuthenticationRequestDto authenticationRequest,
Device device) throws AuthenticationException {
Authentication authentication = this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(
authenticationRequest.getUsername(), authenticationRequest.getPassword()));
SecurityContextHolder.getContext().setAuthentication(authentication);
UserDetails userDetails = this.userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
String token = this.tokenGenerator.generateToken(userDetails, device);
return ResponseEntity.ok(new AuthenticationResponseDto(token));
}
단위 테스트
ResultActions res = mockMvc.perform(post("/auth", authentication, device).contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(authentication)));
res.andExpect(status().isOk());
'AuthenticationController'와'관련 코드를 넣어 재미있을 수도 있습니다 AuthenticationCont rollerTest'라고합니다. 리포지토리에서 코드를 변경하면 향후 독자를위한 질문 (및 대답)이 무효화됩니다. – g00glen00b
코드를 입력하겠습니다. 감사합니다. – neons
어쩌면 config 클래스에 어딘가에'@ EnableWebMvc' 어노테이션을 추가했는지 확인하십시오. 이것은 모의 MVC가 작동하기 위해서 필요합니다. – g00glen00b