Merge branch '2.2.x'

Closes gh-19600
pull/19602/head
Madhura Bhave 5 years ago
commit abe95fa8a7

@ -136,14 +136,17 @@ public final class WebFluxTags {
*/
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;

@ -21,6 +21,7 @@ import org.junit.jupiter.api.BeforeEach;
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;
@ -37,6 +38,7 @@ import static org.mockito.Mockito.mock;
*
* @author Brian Clozel
* @author Michael McFadyen
* @author Madhura Bhave
*/
class WebFluxTagsTests {
@ -114,7 +116,20 @@ class WebFluxTagsTests {
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

Loading…
Cancel
Save