本文整理汇总了Java中org.springframework.boot.test.TestRestTemplate.HttpClientOption类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientOption类的具体用法?Java HttpClientOption怎么用?Java HttpClientOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientOption类属于org.springframework.boot.test.TestRestTemplate包,在下文中一共展示了HttpClientOption类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_authenticate_success
import org.springframework.boot.test.TestRestTemplate.HttpClientOption; //导入依赖的package包/类
@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));
}
示例2: test_authenticate_failure
import org.springframework.boot.test.TestRestTemplate.HttpClientOption; //导入依赖的package包/类
@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));
}
示例3: options
import org.springframework.boot.test.TestRestTemplate.HttpClientOption; //导入依赖的package包/类
@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));
}
示例4: test_authenticate_failure
import org.springframework.boot.test.TestRestTemplate.HttpClientOption; //导入依赖的package包/类
@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));
}