Код: Выделить всё
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AuthControllerITest {
@Autowired
private TestRestTemplate template;
@Test
public void shouldGetAccessToken() throws Exception {
String email = "a@a.pl";
String url = AuthController.GET_TOKEN_PATH+"?email="+email;
ResponseEntity response = template.getForEntity(url, AuthResponse.class);
assertThat(response.getStatusCode().is2xxSuccessful());
}
}
Код: Выделить всё
org.springframework.web.client.RestClientException: Error while extracting response for type [class com.my.app.security.ui.response.AuthResponse] and content type [application/json]
Код: Выделить всё
@GetMapping(AuthController.GET_TOKEN_PATH)
public ResponseEntity auth(@RequestParam(required = false) String email)
{
if (null == email) {
throw new RuntimeException("Email must be provided");
}
User user = userRepository.findUserByEmail(email);
return ResponseEntity.ok(new AuthResponse(jwtService.createToken(user)));
}
Код: Выделить всё
public class AuthResponse {
private String token = "some token";
public AuthResponse(String token) {
this.token = token;
}
public String getToken() {
return token;
}
}
Код: Выделить всё
ResponseEntity response = template.getForEntity(url, String.class);
Так и могло бы быть Скажите, почему я не могу получить сопоставленный объект AuthResponse?
Подробнее здесь: https://stackoverflow.com/questions/788 ... ation-test