@Test public void test_authenticate_success() throws JsonProcessingException { // authenticate HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); final String json = new ObjectMapper().writeValueAsString( new UsernamePasswordToken(USER_EMAIL, USER_PWD)); System.out.println(json); final ResponseEntity<String> response = new TestRestTemplate( HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"), HttpMethod.POST, new HttpEntity<>(json, headers), String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
@Test public void test_authenticate_failure() throws JsonProcessingException { // authenticate HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); final String json = new ObjectMapper().writeValueAsString( new UsernamePasswordToken(USER_EMAIL, "wrong password")); System.out.println(json); final ResponseEntity<String> response = new TestRestTemplate( HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"), HttpMethod.POST, new HttpEntity<>(json, headers), String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
@Test public void options() throws Exception { TestRestTemplate template = new TestRestTemplate( HttpClientOption.ENABLE_REDIRECTS); CustomHttpComponentsClientHttpRequestFactory factory = (CustomHttpComponentsClientHttpRequestFactory) template .getRequestFactory(); RequestConfig config = factory.getRequestConfig(); assertThat(config.isRedirectsEnabled(), equalTo(true)); }
@Test public void test_authenticate_failure() throws JsonProcessingException { // authenticate HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); final String json = new ObjectMapper().writeValueAsString( new UsernamePasswordToken(USER_EMAIL, "wrong password")); System.out.println(json); final ResponseEntity<String> response = new TestRestTemplate( HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"), HttpMethod.POST, new HttpEntity<>(json, headers), String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED)); }