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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations