优化
This commit is contained in:
+25
@@ -11,6 +11,31 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class EventDeliveryFeignConfigurationTest {
|
||||
interface Endpoint { @RequestLine("POST /events") String send(); }
|
||||
interface TypedEndpoint { @RequestLine("POST /events") com.baiyue.common.core.api.ApiResponse<Map<String, Object>> send(); }
|
||||
|
||||
@Test void wireCodeMustBeAStringAndAmbiguousJsonCannotBeAcknowledged() {
|
||||
for (String body : List.of("{\"code\":200}", "{\"code\":true}", "{\"code\":\"200\",\"code\":\"500\"}", "{\"code\":\"200\"} {}", "{}")) {
|
||||
var decoded = new AtomicInteger();
|
||||
TypedEndpoint endpoint = Feign.builder()
|
||||
.decoder((response, type) -> { decoded.incrementAndGet(); return com.baiyue.common.core.api.ApiResponse.success(Map.of()); })
|
||||
.addCapability(new EventDeliveryFeignConfiguration().eventDeliveryCapability(3000, 15000, 60))
|
||||
.client((request, options) -> Response.builder().request(request).status(200).reason("OK").headers(Map.of()).body(body, StandardCharsets.UTF_8).build())
|
||||
.target(TypedEndpoint.class, "http://event-consumer.invalid");
|
||||
assertThatThrownBy(endpoint::send).isInstanceOf(feign.codec.DecodeException.class);
|
||||
assertThat(decoded.get()).isZero();
|
||||
}
|
||||
}
|
||||
|
||||
@Test void validStringCodePreservesBodyForTheConfiguredDecoder() {
|
||||
String body = "{\"code\":\"200\",\"data\":{\"outcome\":\"APPLIED\"}}";
|
||||
TypedEndpoint endpoint = Feign.builder().decoder((response, type) -> {
|
||||
assertThat(new String(response.body().asInputStream().readAllBytes(), StandardCharsets.UTF_8)).isEqualTo(body);
|
||||
return com.baiyue.common.core.api.ApiResponse.success(Map.of("outcome", "APPLIED"));
|
||||
}).addCapability(new EventDeliveryFeignConfiguration().eventDeliveryCapability(3000, 15000, 60))
|
||||
.client((request, options) -> Response.builder().request(request).status(200).reason("OK").headers(Map.of()).body(body, StandardCharsets.UTF_8).build())
|
||||
.target(TypedEndpoint.class, "http://event-consumer.invalid");
|
||||
assertThat(endpoint.send().data()).containsEntry("outcome", "APPLIED");
|
||||
}
|
||||
|
||||
@Test void builtClientOverridesLegacyTimeoutAndRedirectSettings() {
|
||||
var capability = new EventDeliveryFeignConfiguration().eventDeliveryCapability(3000, 15000, 60);
|
||||
|
||||
Reference in New Issue
Block a user