Skip to content

Commit

Permalink
Fallback on underlying server default when determining outcome tag
Browse files Browse the repository at this point in the history
This commit also changed the default outcome to SUCCESS

Fixes gh-19367
  • Loading branch information
mbhave committed Jan 10, 2020
1 parent a017b89 commit 7f0573d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,17 @@ public static Tag exception(Throwable exception) {
*/
public static Tag outcome(ServerWebExchange exchange) {
Integer statusCode = extractStatusCode(exchange);
Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.UNKNOWN;
Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.SUCCESS;
return outcome.asTag();
}

private static Integer extractStatusCode(ServerWebExchange exchange) {
ServerHttpResponse response = exchange.getResponse();
if (response instanceof AbstractServerHttpResponse) {
return ((AbstractServerHttpResponse) response).getStatusCodeValue();
Integer statusCode = ((AbstractServerHttpResponse) response).getStatusCodeValue();
if (statusCode != null) {
return statusCode;
}
}
HttpStatus status = response.getStatusCode();
return (status != null) ? status.value() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;

import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
Expand All @@ -37,6 +38,7 @@
*
* @author Brian Clozel
* @author Michael McFadyen
* @author Madhura Bhave
*/
class WebFluxTagsTests {

Expand Down Expand Up @@ -114,7 +116,20 @@ void methodTagToleratesNonStandardHttpMethods() {
void outcomeTagIsUnknownWhenResponseStatusIsNull() {
this.exchange.getResponse().setStatusCode(null);
Tag tag = WebFluxTags.outcome(this.exchange);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
assertThat(tag.getValue()).isEqualTo("SUCCESS");
}

@Test
void outcomeTagIsSuccessWhenResponseStatusIsAvailableFromUnderlyingServer() {
ServerWebExchange exchange = mock(ServerWebExchange.class);
ServerHttpRequest request = mock(ServerHttpRequest.class);
AbstractServerHttpResponse response = mock(AbstractServerHttpResponse.class);
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getStatusCodeValue()).willReturn(null);
given(exchange.getRequest()).willReturn(request);
given(exchange.getResponse()).willReturn(response);
Tag tag = WebFluxTags.outcome(exchange);
assertThat(tag.getValue()).isEqualTo("SUCCESS");
}

@Test
Expand Down

0 comments on commit 7f0573d

Please sign in to comment.