Polish
This commit is contained in:
parent
b5c9afc055
commit
9f6c5e4e39
|
@ -131,43 +131,36 @@ public final class RestTemplateExchangeTags {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code outcome} {@code Tag} derived from the
|
* Creates an {@code outcome} {@code Tag} derived from the
|
||||||
* {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}.
|
* {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}.
|
||||||
* @param response the response
|
* @param response the response
|
||||||
* @return the outcome tag
|
* @return the outcome tag
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
public static Tag outcome(ClientHttpResponse response) {
|
public static Tag outcome(ClientHttpResponse response) {
|
||||||
HttpStatus status = extractStatus(response);
|
try {
|
||||||
if (status != null) {
|
if (response != null) {
|
||||||
if (status.is1xxInformational()) {
|
HttpStatus statusCode = response.getStatusCode();
|
||||||
|
if (statusCode.is1xxInformational()) {
|
||||||
return OUTCOME_INFORMATIONAL;
|
return OUTCOME_INFORMATIONAL;
|
||||||
}
|
}
|
||||||
if (status.is2xxSuccessful()) {
|
if (statusCode.is2xxSuccessful()) {
|
||||||
return OUTCOME_SUCCESS;
|
return OUTCOME_SUCCESS;
|
||||||
}
|
}
|
||||||
if (status.is3xxRedirection()) {
|
if (statusCode.is3xxRedirection()) {
|
||||||
return OUTCOME_REDIRECTION;
|
return OUTCOME_REDIRECTION;
|
||||||
}
|
}
|
||||||
if (status.is4xxClientError()) {
|
if (statusCode.is4xxClientError()) {
|
||||||
return OUTCOME_CLIENT_ERROR;
|
return OUTCOME_CLIENT_ERROR;
|
||||||
}
|
}
|
||||||
if (status.is5xxServerError()) {
|
if (statusCode.is5xxServerError()) {
|
||||||
return OUTCOME_SERVER_ERROR;
|
return OUTCOME_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OUTCOME_UNKNOWN;
|
return OUTCOME_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
catch (IOException | IllegalArgumentException ex) {
|
||||||
private static HttpStatus extractStatus(ClientHttpResponse response) {
|
return OUTCOME_UNKNOWN;
|
||||||
try {
|
|
||||||
if (response != null) {
|
|
||||||
return response.getStatusCode();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
catch (IOException | IllegalArgumentException exc) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public final class WebClientExchangeTags {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code outcome} {@code Tag} derived from the
|
* Creates an {@code outcome} {@code Tag} derived from the
|
||||||
* {@link ClientResponse#statusCode() status} of the given {@code response}.
|
* {@link ClientResponse#statusCode() status} of the given {@code response}.
|
||||||
* @param response the response
|
* @param response the response
|
||||||
* @return the outcome tag
|
* @return the outcome tag
|
||||||
|
|
|
@ -34,12 +34,11 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Nishant Raut
|
* @author Nishant Raut
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Brian Clozel
|
|
||||||
*/
|
*/
|
||||||
public class RestTemplateExchangeTagsTests {
|
public class RestTemplateExchangeTagsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
|
public void outcomeTagIsUnknownWhenResponseIsNull() {
|
||||||
Tag tag = RestTemplateExchangeTags.outcome(null);
|
Tag tag = RestTemplateExchangeTags.outcome(null);
|
||||||
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebClientExchangeTags}
|
* Tests for {@link WebClientExchangeTags}.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Nishant Raut
|
* @author Nishant Raut
|
||||||
|
@ -115,7 +115,7 @@ public class WebClientExchangeTagsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
|
public void outcomeTagIsUnknownWhenResponseIsNull() {
|
||||||
Tag tag = WebClientExchangeTags.outcome(null);
|
Tag tag = WebClientExchangeTags.outcome(null);
|
||||||
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class WebClientExchangeTagsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outcomeTagIsUknownWhenResponseStatusIsUknown() {
|
public void outcomeTagIsUnknownWhenResponseStatusIsUnknown() {
|
||||||
given(this.response.statusCode()).willThrow(IllegalArgumentException.class);
|
given(this.response.statusCode()).willThrow(IllegalArgumentException.class);
|
||||||
Tag tag = WebClientExchangeTags.outcome(this.response);
|
Tag tag = WebClientExchangeTags.outcome(this.response);
|
||||||
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
||||||
|
|
Loading…
Reference in New Issue