Search in sources :

Example 46 with Response

use of feign.Response in project feign by OpenFeign.

the class JsonDecoderTest method decodesArray.

@Test
public void decodesArray() throws IOException {
    String json = "[{\"a\":\"b\",\"c\":1},123]";
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(json, UTF_8).request(request).build();
    assertTrue(jsonArray.similar(new JsonDecoder().decode(response, JSONArray.class)));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 47 with Response

use of feign.Response in project feign by OpenFeign.

the class JsonDecoderTest method decodesObject.

@Test
public void decodesObject() throws IOException {
    String json = "{\"a\":\"b\",\"c\":1}";
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(json, UTF_8).request(request).build();
    assertTrue(jsonObject.similar(new JsonDecoder().decode(response, JSONObject.class)));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 48 with Response

use of feign.Response in project feign by OpenFeign.

the class JsonDecoderTest method causedByIOException.

@Test
public void causedByIOException() throws IOException {
    Response.Body body = mock(Response.Body.class);
    when(body.asReader(any())).thenThrow(new JSONException("test exception", new IOException("test cause exception")));
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(body).request(request).build();
    Exception exception = assertThrows(IOException.class, () -> new JsonDecoder().decode(response, JSONArray.class));
    assertEquals("test cause exception", exception.getMessage());
}
Also used : Response(feign.Response) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) IOException(java.io.IOException) JSONException(org.json.JSONException) DecodeException(feign.codec.DecodeException) Test(org.junit.Test)

Example 49 with Response

use of feign.Response in project feign by OpenFeign.

the class JsonDecoderTest method decodeExtendedObject.

@Test
public void decodeExtendedObject() throws IOException {
    String json = "{\"a\":\"b\",\"c\":1}";
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(json, UTF_8).request(request).build();
    assertTrue(jsonObject.similar(new JsonDecoder().decode(response, ExtendedJSONObject.class)));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 50 with Response

use of feign.Response in project feign by OpenFeign.

the class JsonDecoderTest method decodesExtendedArray.

@Test
public void decodesExtendedArray() throws IOException {
    String json = "[{\"a\":\"b\",\"c\":1},123]";
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(json, UTF_8).request(request).build();
    assertTrue(jsonArray.similar(new JsonDecoder().decode(response, ExtendedJSONArray.class)));
}
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