Search in sources :

Example 76 with Response

use of feign.Response in project feign by OpenFeign.

the class SOAPCodecTest method decodesSoapWithSchemaOnEnvelope.

@Test
public void decodesSoapWithSchemaOnEnvelope() throws Exception {
    GetPrice mock = new GetPrice();
    mock.item = new Item();
    mock.item.value = "Apples";
    String mockSoapEnvelop = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://apihost/schema.xsd\" " + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<SOAP-ENV:Header/>" + "<SOAP-ENV:Body>" + "<GetPrice>" + "<Item xsi:type=\"xsd:string\">Apples</Item>" + "</GetPrice>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(mockSoapEnvelop, UTF_8).build();
    SOAPDecoder decoder = new SOAPDecoder.Builder().withJAXBContextFactory(new JAXBContextFactory.Builder().build()).useFirstChild().build();
    assertEquals(mock, decoder.decode(response, GetPrice.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 77 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method decodesMapObjectNumericalValuesAsInteger.

@Test
public void decodesMapObjectNumericalValuesAsInteger() throws Exception {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("foo", 1);
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body("{\"foo\": 1}", UTF_8).build();
    assertEquals(new GsonDecoder().decode(response, new TypeToken<Map<String, Object>>() {
    }.getType()), map);
}
Also used : Response(feign.Response) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 78 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method emptyBodyDecodesToNull.

@Test
public void emptyBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).body(new byte[0]).build();
    assertNull(new GsonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 79 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method nullBodyDecodesToNull.

@Test
public void nullBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).build();
    assertNull(new GsonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 80 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultDecoderTest method testDecodesToByteArray.

@Test
public void testDecodesToByteArray() throws Exception {
    Response response = knownResponse();
    Object decodedObject = decoder.decode(response, byte[].class);
    assertEquals(byte[].class, decodedObject.getClass());
    assertEquals("response body", new String((byte[]) decodedObject, UTF_8));
}
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