Search in sources :

Example 86 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.

the class RestTemplateExchangeTagsTests method outcomeTagIsSuccessWhenResponseIs2xx.

@Test
void outcomeTagIsSuccessWhenResponseIs2xx() {
    ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.OK);
    Tag tag = RestTemplateExchangeTags.outcome(response);
    assertThat(tag.getValue()).isEqualTo("SUCCESS");
}
Also used : Tag(io.micrometer.core.instrument.Tag) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 87 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.

the class RestTemplateExchangeTagsTests method outcomeTagIsRedirectionWhenResponseIs3xx.

@Test
void outcomeTagIsRedirectionWhenResponseIs3xx() {
    ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.MOVED_PERMANENTLY);
    Tag tag = RestTemplateExchangeTags.outcome(response);
    assertThat(tag.getValue()).isEqualTo("REDIRECTION");
}
Also used : Tag(io.micrometer.core.instrument.Tag) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 88 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.

the class RestTemplateExchangeTagsTests method outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries.

@Test
void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() throws IOException {
    ClientHttpResponse response = mock(ClientHttpResponse.class);
    given(response.getRawStatusCode()).willReturn(490);
    Tag tag = RestTemplateExchangeTags.outcome(response);
    assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
Also used : Tag(io.micrometer.core.instrument.Tag) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 89 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.

the class HttpHeaderInterceptorTests method intercept.

@Test
void intercept() throws IOException {
    given(this.execution.execute(this.request, this.body)).willReturn(this.response);
    ClientHttpResponse result = this.interceptor.intercept(this.request, this.body, this.execution);
    assertThat(this.request.getHeaders().getFirst(this.name)).isEqualTo(this.value);
    assertThat(result).isEqualTo(this.response);
}
Also used : ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 90 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.

the class DelayedLiveReloadTrigger method isUp.

private boolean isUp() {
    try {
        ClientHttpRequest request = createRequest();
        ClientHttpResponse response = request.execute();
        return response.getStatusCode() == HttpStatus.OK;
    } catch (Exception ex) {
        return false;
    }
}
Also used : ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)142 IOException (java.io.IOException)38 Test (org.junit.Test)38 HttpHeaders (org.springframework.http.HttpHeaders)35 ByteArrayInputStream (java.io.ByteArrayInputStream)23 URI (java.net.URI)23 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)23 Test (org.junit.jupiter.api.Test)21 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)20 RestTemplate (org.springframework.web.client.RestTemplate)20 DefaultResponseErrorHandler (org.springframework.web.client.DefaultResponseErrorHandler)18 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MockClientHttpResponse (org.springframework.mock.http.client.MockClientHttpResponse)9 ResponseExtractor (org.springframework.web.client.ResponseExtractor)9 Tag (io.micrometer.core.instrument.Tag)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Invocation (org.apache.servicecomb.core.Invocation)6