Search in sources :

Example 81 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultErrorDecoderHttpErrorTest method testExceptionIsHttpSpecific.

@Test
public void testExceptionIsHttpSpecific() throws Throwable {
    Response response = Response.builder().status(httpStatus).reason("anything").request(Request.create(HttpMethod.GET, "http://example.com/api", Collections.emptyMap(), null, Util.UTF_8)).headers(headers).body("response body", Util.UTF_8).build();
    Exception exception = errorDecoder.decode("Service#foo()", response);
    assertThat(exception).isInstanceOf(expectedExceptionClass);
    assertThat(((FeignException) exception).status()).isEqualTo(httpStatus);
    assertThat(exception.getMessage()).isEqualTo(expectedMessage);
}
Also used : Response(feign.Response) FeignException(feign.FeignException) FeignException(feign.FeignException) Test(org.junit.Test)

Example 82 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method testContentTypeWithoutCharset.

@Test
public void testContentTypeWithoutCharset() throws Exception {
    server.enqueue(new MockResponse().setBody("AAAAAAAA"));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.postWithContentType("foo", "text/plain");
    // Response length should not be null
    assertEquals("AAAAAAAA", Util.toString(response.body().asReader(UTF_8)));
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 83 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method testAlternativeCollectionFormat.

@Test
public void testAlternativeCollectionFormat() throws Exception {
    server.enqueue(new MockResponse().setBody("body"));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.getCSV(Arrays.asList("bar", "baz"));
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isEqualTo("OK");
    // Some HTTP libraries percent-encode commas in query parameters and others don't.
    MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET").hasOneOfPath("/?foo=bar,baz", "/?foo=bar%2Cbaz");
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 84 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method testDefaultCollectionFormat.

@Test
public void testDefaultCollectionFormat() throws Exception {
    server.enqueue(new MockResponse().setBody("body"));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.get(Arrays.asList("bar", "baz"));
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isEqualTo("OK");
    MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET").hasPath("/?foo=bar&foo=baz");
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 85 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method reasonPhraseIsOptional.

@Test
public void reasonPhraseIsOptional() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.post("foo");
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isNullOrEmpty();
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

Response (feign.Response)169 Test (org.junit.Test)118 IOException (java.io.IOException)32 MockResponse (okhttp3.mockwebserver.MockResponse)26 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)22 Test (org.testng.annotations.Test)20 Collection (java.util.Collection)19 HashMap (java.util.HashMap)16 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)16 ArrayList (java.util.ArrayList)15 Gson (com.google.gson.Gson)13 FeignException (feign.FeignException)13 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)13 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)13 Request (feign.Request)11 RetryableException (feign.RetryableException)11 DecodeException (feign.codec.DecodeException)10 Map (java.util.Map)10 ExpectedException (org.junit.rules.ExpectedException)10 Type (java.lang.reflect.Type)9