Search in sources :

Example 56 with Response

use of feign.Response in project feign by OpenFeign.

the class Http2ClientAsyncTest method responseCoercesToStringBody.

@Test
public void responseCoercesToStringBody() throws Throwable {
    server.enqueue(new MockResponse().setBody("foo"));
    final TestInterfaceAsync api = newAsyncBuilder().target("http://localhost:" + server.getPort());
    final Response response = unwrap(api.response());
    assertTrue(response.body().isRepeatable());
    assertEquals("foo", Util.toString(response.body().asReader(StandardCharsets.UTF_8)));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 57 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonIteratorTest method responseIsClosedAfterIteration.

@Test
public void responseIsClosedAfterIteration() throws IOException {
    final AtomicBoolean closed = new AtomicBoolean();
    byte[] jsonBytes = "[false, true]".getBytes(UTF_8);
    InputStream inputStream = new ByteArrayInputStream(jsonBytes) {

        @Override
        public void close() throws IOException {
            closed.set(true);
            super.close();
        }
    };
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(inputStream, jsonBytes.length).build();
    assertThat(iterator(Boolean.class, response)).toIterable().hasSize(2);
    assertThat(closed.get()).isTrue();
}
Also used : Response(feign.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 58 with Response

use of feign.Response in project feign by OpenFeign.

the class JAXBCodecTest method doesntDecodeParameterizedTypes.

@Test
public void doesntDecodeParameterizedTypes() throws Exception {
    thrown.expect(feign.codec.DecodeException.class);
    thrown.expectMessage("java.util.Map is an interface, and JAXB can't handle interfaces.\n" + "\tthis problem is related to the following location:\n" + "\t\tat java.util.Map");
    class ParameterizedHolder {

        Map<String, ?> field;
    }
    Type parameterized = ParameterizedHolder.class.getDeclaredField("field").getGenericType();
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.<String, Collection<String>>emptyMap()).body("<foo/>", UTF_8).build();
    new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, parameterized);
}
Also used : Response(feign.Response) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) Type(java.lang.reflect.Type) Map(java.util.Map) Test(org.junit.Test)

Example 59 with Response

use of feign.Response in project feign by OpenFeign.

the class JAXBCodecTest method decodesXml.

@Test
public void decodesXml() throws Exception {
    MockObject mock = new MockObject();
    mock.value = "Test";
    String mockXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><mockObject>" + "<value>Test</value></mockObject>";
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(mockXml, UTF_8).build();
    JAXBDecoder decoder = new JAXBDecoder(new JAXBContextFactory.Builder().build());
    assertEquals(mock, decoder.decode(response, MockObject.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 60 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonJaxbCodecTest method decodeTest.

@Test
public void decodeTest() throws Exception {
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body("{\"value\":\"Test\"}", UTF_8).build();
    JacksonJaxbJsonDecoder decoder = new JacksonJaxbJsonDecoder();
    assertThat(decoder.decode(response, MockObject.class)).isEqualTo(new MockObject("Test"));
}
Also used : Response(feign.Response) 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