Update after review
See gh-28386
This commit is contained in:
@@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.service.annotation.GetRequest;
|
||||
import org.springframework.web.service.annotation.HttpRequest;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -64,25 +64,25 @@ public class HttpMethodArgumentResolverTests {
|
||||
|
||||
@Nullable
|
||||
private HttpMethod getActualMethod() {
|
||||
return this.clientAdapter.getRequestDefinition().getHttpMethod();
|
||||
return this.clientAdapter.getRequestSpec().getHttpMethod();
|
||||
}
|
||||
|
||||
|
||||
private interface Service {
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(HttpMethod method);
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
void executeGet(HttpMethod method);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(String test);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(HttpMethod firstMethod, HttpMethod secondMethod);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeForNull(@Nullable HttpMethod method);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.service.annotation.GetRequest;
|
||||
import org.springframework.web.service.annotation.HttpRequest;
|
||||
import org.springframework.web.service.annotation.PostRequest;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.http.MediaType.APPLICATION_CBOR_VALUE;
|
||||
@@ -145,7 +145,7 @@ public class HttpServiceMethodTests {
|
||||
|
||||
service.performGet();
|
||||
|
||||
HttpRequestDefinition request = this.clientAdapter.getRequestDefinition();
|
||||
HttpRequestSpec request = this.clientAdapter.getRequestSpec();
|
||||
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.GET);
|
||||
assertThat(request.getUriTemplate()).isNull();
|
||||
assertThat(request.getHeaders().getContentType()).isNull();
|
||||
@@ -153,7 +153,7 @@ public class HttpServiceMethodTests {
|
||||
|
||||
service.performPost();
|
||||
|
||||
request = this.clientAdapter.getRequestDefinition();
|
||||
request = this.clientAdapter.getRequestSpec();
|
||||
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
|
||||
assertThat(request.getUriTemplate()).isEqualTo("/url");
|
||||
assertThat(request.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -167,7 +167,7 @@ public class HttpServiceMethodTests {
|
||||
|
||||
service.performGet();
|
||||
|
||||
HttpRequestDefinition request = this.clientAdapter.getRequestDefinition();
|
||||
HttpRequestSpec request = this.clientAdapter.getRequestSpec();
|
||||
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.GET);
|
||||
assertThat(request.getUriTemplate()).isEqualTo("/base");
|
||||
assertThat(request.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_CBOR);
|
||||
@@ -175,7 +175,7 @@ public class HttpServiceMethodTests {
|
||||
|
||||
service.performPost();
|
||||
|
||||
request = this.clientAdapter.getRequestDefinition();
|
||||
request = this.clientAdapter.getRequestSpec();
|
||||
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
|
||||
assertThat(request.getUriTemplate()).isEqualTo("/base/url");
|
||||
assertThat(request.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
@@ -191,25 +191,25 @@ public class HttpServiceMethodTests {
|
||||
@SuppressWarnings("unused")
|
||||
private interface ReactorService {
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
Mono<Void> execute();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Mono<HttpHeaders> getHeaders();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Mono<String> getBody();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Flux<String> getFluxBody();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Mono<ResponseEntity<Void>> getVoidEntity();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Mono<ResponseEntity<String>> getEntity();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Mono<ResponseEntity<Flux<String>>> getFluxEntity();
|
||||
}
|
||||
|
||||
@@ -217,25 +217,25 @@ public class HttpServiceMethodTests {
|
||||
@SuppressWarnings("unused")
|
||||
private interface RxJavaService {
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
Completable execute();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Single<HttpHeaders> getHeaders();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Single<String> getBody();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Flowable<String> getFlowableBody();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Single<ResponseEntity<Void>> getVoidEntity();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Single<ResponseEntity<String>> getEntity();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
Single<ResponseEntity<Flowable<String>>> getFlowableEntity();
|
||||
}
|
||||
|
||||
@@ -243,19 +243,19 @@ public class HttpServiceMethodTests {
|
||||
@SuppressWarnings("unused")
|
||||
private interface BlockingService {
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
HttpHeaders getHeaders();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
String getBody();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
ResponseEntity<Void> getVoidEntity();
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
ResponseEntity<String> getEntity();
|
||||
}
|
||||
|
||||
@@ -263,17 +263,17 @@ public class HttpServiceMethodTests {
|
||||
@SuppressWarnings("unused")
|
||||
private interface MethodAnnotatedService {
|
||||
|
||||
@GetRequest
|
||||
@GetExchange
|
||||
void performGet();
|
||||
|
||||
@PostRequest(url = "/url", contentType = APPLICATION_JSON_VALUE, accept = APPLICATION_JSON_VALUE)
|
||||
@PostExchange(url = "/url", contentType = APPLICATION_JSON_VALUE, accept = APPLICATION_JSON_VALUE)
|
||||
void performPost();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@HttpRequest(url = "/base", contentType = APPLICATION_CBOR_VALUE, accept = APPLICATION_CBOR_VALUE)
|
||||
@HttpExchange(url = "/base", contentType = APPLICATION_CBOR_VALUE, accept = APPLICATION_CBOR_VALUE)
|
||||
private interface TypeAndMethodAnnotatedService extends MethodAnnotatedService {
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.service.annotation.HttpRequest;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
@@ -143,44 +143,44 @@ class PathVariableArgumentResolverTests {
|
||||
}
|
||||
|
||||
private Map<String, String> getActualUriVariables() {
|
||||
return this.clientAdapter.getRequestDefinition().getUriVariables();
|
||||
return this.clientAdapter.getRequestSpec().getUriVariables();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
private interface Service {
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(@PathVariable String id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeNotRequired(@Nullable @PathVariable(required = false) String id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeOptional(@PathVariable Optional<Boolean> id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeOptionalNotRequired(@PathVariable(required = false) Optional<String> id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeNamedWithValue(@Nullable @PathVariable(name = "test", value = "id") String employeeId);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeNamed(@PathVariable(name = "id") String employeeId);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeValueNamed(@PathVariable("id") String employeeId);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(@PathVariable Object id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void execute(@PathVariable Boolean id);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeValueMap(@Nullable @PathVariable Map<String, String> map);
|
||||
|
||||
@HttpRequest
|
||||
@HttpExchange
|
||||
void executeOptionalValueMap(@PathVariable Map<String, Optional<String>> map);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class TestHttpClientAdapter implements HttpClientAdapter {
|
||||
private String invokedMethodName;
|
||||
|
||||
@Nullable
|
||||
private HttpRequestDefinition requestDefinition;
|
||||
private HttpRequestSpec requestSpec;
|
||||
|
||||
@Nullable
|
||||
private ParameterizedTypeReference<?> bodyType;
|
||||
@@ -53,12 +53,12 @@ class TestHttpClientAdapter implements HttpClientAdapter {
|
||||
/**
|
||||
* Create the proxy for the give service type.
|
||||
*/
|
||||
public <S> S createService(Class<S> serviceType, HttpServiceMethodArgumentResolver... resolvers) {
|
||||
public <S> S createService(Class<S> serviceType, HttpServiceArgumentResolver... resolvers) {
|
||||
|
||||
HttpServiceProxyFactory factory = new HttpServiceProxyFactory(
|
||||
Arrays.asList(resolvers), this, ReactiveAdapterRegistry.getSharedInstance(), Duration.ofSeconds(5));
|
||||
|
||||
return factory.createService(serviceType);
|
||||
return factory.createClient(serviceType);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ class TestHttpClientAdapter implements HttpClientAdapter {
|
||||
return this.invokedMethodName;
|
||||
}
|
||||
|
||||
public HttpRequestDefinition getRequestDefinition() {
|
||||
assertThat(this.requestDefinition).isNotNull();
|
||||
return this.requestDefinition;
|
||||
public HttpRequestSpec getRequestSpec() {
|
||||
assertThat(this.requestSpec).isNotNull();
|
||||
return this.requestSpec;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -81,56 +81,56 @@ class TestHttpClientAdapter implements HttpClientAdapter {
|
||||
// HttpClientAdapter implementation
|
||||
|
||||
@Override
|
||||
public Mono<Void> requestToVoid(HttpRequestDefinition definition) {
|
||||
saveInput("requestToVoid", definition, null);
|
||||
public Mono<Void> requestToVoid(HttpRequestSpec requestSpec) {
|
||||
saveInput("requestToVoid", requestSpec, null);
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<HttpHeaders> requestToHeaders(HttpRequestDefinition definition) {
|
||||
saveInput("requestToHeaders", definition, null);
|
||||
public Mono<HttpHeaders> requestToHeaders(HttpRequestSpec requestSpec) {
|
||||
saveInput("requestToHeaders", requestSpec, null);
|
||||
return Mono.just(new HttpHeaders());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> requestToBody(HttpRequestDefinition definition, ParameterizedTypeReference<T> bodyType) {
|
||||
saveInput("requestToBody", definition, bodyType);
|
||||
public <T> Mono<T> requestToBody(HttpRequestSpec requestSpec, ParameterizedTypeReference<T> bodyType) {
|
||||
saveInput("requestToBody", requestSpec, bodyType);
|
||||
return (Mono<T>) Mono.just(getInvokedMethodName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> requestToBodyFlux(HttpRequestDefinition definition, ParameterizedTypeReference<T> bodyType) {
|
||||
saveInput("requestToBodyFlux", definition, bodyType);
|
||||
public <T> Flux<T> requestToBodyFlux(HttpRequestSpec requestSpec, ParameterizedTypeReference<T> bodyType) {
|
||||
saveInput("requestToBodyFlux", requestSpec, bodyType);
|
||||
return (Flux<T>) Flux.just("request", "To", "Body", "Flux");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ResponseEntity<Void>> requestToBodilessEntity(HttpRequestDefinition definition) {
|
||||
saveInput("requestToBodilessEntity", definition, null);
|
||||
public Mono<ResponseEntity<Void>> requestToBodilessEntity(HttpRequestSpec requestSpec) {
|
||||
saveInput("requestToBodilessEntity", requestSpec, null);
|
||||
return Mono.just(ResponseEntity.ok().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<T>> requestToEntity(
|
||||
HttpRequestDefinition definition, ParameterizedTypeReference<T> type) {
|
||||
HttpRequestSpec requestSpec, ParameterizedTypeReference<T> type) {
|
||||
|
||||
saveInput("requestToEntity", definition, type);
|
||||
saveInput("requestToEntity", requestSpec, type);
|
||||
return Mono.just((ResponseEntity<T>) ResponseEntity.ok("requestToEntity"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<Flux<T>>> requestToEntityFlux(
|
||||
HttpRequestDefinition definition, ParameterizedTypeReference<T> bodyType) {
|
||||
HttpRequestSpec requestSpec, ParameterizedTypeReference<T> bodyType) {
|
||||
|
||||
saveInput("requestToEntityFlux", definition, bodyType);
|
||||
saveInput("requestToEntityFlux", requestSpec, bodyType);
|
||||
return Mono.just(ResponseEntity.ok((Flux<T>) Flux.just("request", "To", "Entity", "Flux")));
|
||||
}
|
||||
|
||||
private <T> void saveInput(
|
||||
String methodName, HttpRequestDefinition definition, @Nullable ParameterizedTypeReference<T> bodyType) {
|
||||
String methodName, HttpRequestSpec requestSpec, @Nullable ParameterizedTypeReference<T> bodyType) {
|
||||
|
||||
this.invokedMethodName = methodName;
|
||||
this.requestDefinition = definition;
|
||||
this.requestSpec = requestSpec;
|
||||
this.bodyType = bodyType;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user