[JAVA-8145] Fix formatting
This commit is contained in:
parent
b64024d003
commit
ab97eda9d9
@ -45,13 +45,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||||
public class WebClientIntegrationTest {
|
public class WebClientIntegrationTest {
|
||||||
|
|
||||||
@LocalServerPort
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
private static final String BODY_VALUE = "bodyValue";
|
private static final String BODY_VALUE = "bodyValue";
|
||||||
private static final ParameterizedTypeReference<Map<String, String>> MAP_RESPONSE_REF = new ParameterizedTypeReference<Map<String, String>>() {
|
private static final ParameterizedTypeReference<Map<String, String>> MAP_RESPONSE_REF = new ParameterizedTypeReference<Map<String, String>>() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@LocalServerPort
|
||||||
|
private int port;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenDifferentWebClientCreationMethods_whenUsed_thenObtainExpectedResponse() {
|
public void givenDifferentWebClientCreationMethods_whenUsed_thenObtainExpectedResponse() {
|
||||||
// WebClient creation
|
// WebClient creation
|
||||||
@ -106,9 +106,11 @@ public class WebClientIntegrationTest {
|
|||||||
public void givenDifferentUriSpecifications_whenUsed_thenObtainExpectedResponse() {
|
public void givenDifferentUriSpecifications_whenUsed_thenObtainExpectedResponse() {
|
||||||
// uri specification
|
// uri specification
|
||||||
RequestBodySpec bodySpecUsingString = createDefaultPostRequest().uri("/resource");
|
RequestBodySpec bodySpecUsingString = createDefaultPostRequest().uri("/resource");
|
||||||
RequestBodySpec bodySpecUsingUriBuilder = createDefaultPostRequest().uri(uriBuilder -> uriBuilder.pathSegment("resource")
|
RequestBodySpec bodySpecUsingUriBuilder = createDefaultPostRequest().uri(
|
||||||
|
uriBuilder -> uriBuilder.pathSegment("resource")
|
||||||
.build());
|
.build());
|
||||||
RequestBodySpec bodySpecusingURI = createDefaultPostRequest().uri(URI.create("http://localhost:" + port + "/resource"));
|
RequestBodySpec bodySpecusingURI = createDefaultPostRequest().uri(
|
||||||
|
URI.create("http://localhost:" + port + "/resource"));
|
||||||
RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource"));
|
RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource"));
|
||||||
RequestBodySpec bodySpecOverridenBaseUri2 = WebClient.builder()
|
RequestBodySpec bodySpecOverridenBaseUri2 = WebClient.builder()
|
||||||
.baseUrl("http://localhost:" + port)
|
.baseUrl("http://localhost:" + port)
|
||||||
@ -140,8 +142,10 @@ public class WebClientIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenDifferentBodySpecifications_whenUsed_thenObtainExpectedResponse() {
|
public void givenDifferentBodySpecifications_whenUsed_thenObtainExpectedResponse() {
|
||||||
// request body specifications
|
// request body specifications
|
||||||
RequestHeadersSpec<?> headersSpecPost1 = createDefaultPostResourceRequest().body(BodyInserters.fromPublisher(Mono.just(BODY_VALUE), String.class));
|
RequestHeadersSpec<?> headersSpecPost1 = createDefaultPostResourceRequest().body(
|
||||||
RequestHeadersSpec<?> headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(BODY_VALUE));
|
BodyInserters.fromPublisher(Mono.just(BODY_VALUE), String.class));
|
||||||
|
RequestHeadersSpec<?> headersSpecPost2 = createDefaultPostResourceRequest().body(
|
||||||
|
BodyInserters.fromValue(BODY_VALUE));
|
||||||
RequestHeadersSpec<?> headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(BODY_VALUE);
|
RequestHeadersSpec<?> headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(BODY_VALUE);
|
||||||
RequestHeadersSpec<?> headersSpecFooPost = createDefaultPostRequest().uri("/resource-foo")
|
RequestHeadersSpec<?> headersSpecFooPost = createDefaultPostRequest().uri("/resource-foo")
|
||||||
.body(Mono.just(new Foo("fooName")), Foo.class);
|
.body(Mono.just(new Foo("fooName")), Foo.class);
|
||||||
@ -152,7 +156,8 @@ public class WebClientIntegrationTest {
|
|||||||
LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||||
map.add("key1", "multipartValue1");
|
map.add("key1", "multipartValue1");
|
||||||
map.add("key2", "multipartValue2");
|
map.add("key2", "multipartValue2");
|
||||||
BodyInserter<MultiValueMap<String, Object>, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(map);
|
BodyInserter<MultiValueMap<String, Object>, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(
|
||||||
|
map);
|
||||||
RequestHeadersSpec<?> headersSpecInserterMultipart = createDefaultPostRequest().uri("/resource-multipart")
|
RequestHeadersSpec<?> headersSpecInserterMultipart = createDefaultPostRequest().uri("/resource-multipart")
|
||||||
.body(inserterMultipart);
|
.body(inserterMultipart);
|
||||||
|
|
||||||
@ -177,7 +182,8 @@ public class WebClientIntegrationTest {
|
|||||||
.expectError(CodecException.class)
|
.expectError(CodecException.class)
|
||||||
.verify();
|
.verify();
|
||||||
// assert response for request with no body
|
// assert response for request with no body
|
||||||
Mono<Map<String, String>> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> {
|
Mono<Map<String, String>> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(
|
||||||
|
responseHandler -> {
|
||||||
assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||||
return responseHandler.bodyToMono(MAP_RESPONSE_REF);
|
return responseHandler.bodyToMono(MAP_RESPONSE_REF);
|
||||||
});
|
});
|
||||||
@ -190,7 +196,8 @@ public class WebClientIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenPostSpecifications_whenHeadersAdded_thenObtainExpectedResponse() {
|
public void givenPostSpecifications_whenHeadersAdded_thenObtainExpectedResponse() {
|
||||||
// request header specification
|
// request header specification
|
||||||
RequestHeadersSpec<?> headersSpecInserterStringWithHeaders = createDefaultPostResourceRequestResponse().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
RequestHeadersSpec<?> headersSpecInserterStringWithHeaders = createDefaultPostResourceRequestResponse().header(
|
||||||
|
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||||
.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
|
.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
|
||||||
.acceptCharset(StandardCharsets.UTF_8)
|
.acceptCharset(StandardCharsets.UTF_8)
|
||||||
.ifNoneMatch("*")
|
.ifNoneMatch("*")
|
||||||
@ -209,8 +216,7 @@ public class WebClientIntegrationTest {
|
|||||||
Mono<String> responsePostString2 = createDefaultPostResourceRequestResponse().exchangeToMono(response -> {
|
Mono<String> responsePostString2 = createDefaultPostResourceRequestResponse().exchangeToMono(response -> {
|
||||||
if (response.statusCode() == HttpStatus.OK) {
|
if (response.statusCode() == HttpStatus.OK) {
|
||||||
return response.bodyToMono(String.class);
|
return response.bodyToMono(String.class);
|
||||||
} else if (response.statusCode()
|
} else if (response.statusCode().is4xxClientError()) {
|
||||||
.is4xxClientError()) {
|
|
||||||
return Mono.just("Error response");
|
return Mono.just("Error response");
|
||||||
} else {
|
} else {
|
||||||
return response.createException()
|
return response.createException()
|
||||||
@ -220,8 +226,7 @@ public class WebClientIntegrationTest {
|
|||||||
Mono<String> responsePostNoBody = createDefaultPostResourceRequest().exchangeToMono(response -> {
|
Mono<String> responsePostNoBody = createDefaultPostResourceRequest().exchangeToMono(response -> {
|
||||||
if (response.statusCode() == HttpStatus.OK) {
|
if (response.statusCode() == HttpStatus.OK) {
|
||||||
return response.bodyToMono(String.class);
|
return response.bodyToMono(String.class);
|
||||||
} else if (response.statusCode()
|
} else if (response.statusCode().is4xxClientError()) {
|
||||||
.is4xxClientError()) {
|
|
||||||
return Mono.just("Error response");
|
return Mono.just("Error response");
|
||||||
} else {
|
} else {
|
||||||
return response.createException()
|
return response.createException()
|
||||||
@ -268,8 +273,8 @@ public class WebClientIntegrationTest {
|
|||||||
|
|
||||||
StepVerifier.create(neverendingMonoBodyRequest.retrieve()
|
StepVerifier.create(neverendingMonoBodyRequest.retrieve()
|
||||||
.bodyToMono(String.class))
|
.bodyToMono(String.class))
|
||||||
.expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ReadTimeoutException.class.isAssignableFrom(ex.getCause()
|
.expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass())
|
||||||
.getClass()))
|
&& ReadTimeoutException.class.isAssignableFrom(ex.getCause().getClass()))
|
||||||
.verify();
|
.verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user