Skip to content

Commit

Permalink
Add an outcome tag to RestTemplate metrics similar to that provided f…
Browse files Browse the repository at this point in the history
…or WebMVC and WebFlux spring-projects#15420
  • Loading branch information
nishantraut committed Dec 31, 2018
1 parent c0fbaa9 commit 7b91df6
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public class RestTemplateExchangeTagsTests {

private MockClientHttpResponse response;

@Test
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
Tag tag = RestTemplateExchangeTags.outcome(null);
Expand All @@ -39,41 +41,39 @@ public void outcomeTagIsUnknownWhenResponseStatusIsNull() {

@Test
public void outcomeTagIsInformationalWhenResponseIs1xx() {
MockClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(),
HttpStatus.CONTINUE);
Tag tag = RestTemplateExchangeTags.outcome(response);
this.response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.CONTINUE);
Tag tag = RestTemplateExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("INFORMATIONAL");
}

@Test
public void outcomeTagIsSuccessWhenResponseIs2xx() {
MockClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(),
HttpStatus.OK);
Tag tag = RestTemplateExchangeTags.outcome(response);
this.response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.OK);
Tag tag = RestTemplateExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("SUCCESS");
}

@Test
public void outcomeTagIsRedirectionWhenResponseIs3xx() {
MockClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(),
this.response = new MockClientHttpResponse("foo".getBytes(),
HttpStatus.MOVED_PERMANENTLY);
Tag tag = RestTemplateExchangeTags.outcome(response);
Tag tag = RestTemplateExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("REDIRECTION");
}

@Test
public void outcomeTagIsClientErrorWhenResponseIs4xx() {
MockClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(),
this.response = new MockClientHttpResponse("foo".getBytes(),
HttpStatus.BAD_REQUEST);
Tag tag = RestTemplateExchangeTags.outcome(response);
Tag tag = RestTemplateExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}

@Test
public void outcomeTagIsServerErrorWhenResponseIs5xx() {
MockClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(),
this.response = new MockClientHttpResponse("foo".getBytes(),
HttpStatus.BAD_GATEWAY);
Tag tag = RestTemplateExchangeTags.outcome(response);
Tag tag = RestTemplateExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
}

Expand Down

0 comments on commit 7b91df6

Please sign in to comment.