|
|
|
@ -15,11 +15,12 @@
@@ -15,11 +15,12 @@
|
|
|
|
|
*/ |
|
|
|
|
package feign.codec; |
|
|
|
|
|
|
|
|
|
import feign.FeignException; |
|
|
|
|
import feign.Response; |
|
|
|
|
import feign.Util; |
|
|
|
|
import org.testng.annotations.Test; |
|
|
|
|
import org.w3c.dom.Document; |
|
|
|
|
|
|
|
|
|
import java.io.StringReader; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -38,19 +39,19 @@ public class DefaultDecoderTest {
@@ -38,19 +39,19 @@ public class DefaultDecoderTest {
|
|
|
|
|
@Test public void testDecodesToResponse() throws Exception { |
|
|
|
|
Response response = knownResponse(); |
|
|
|
|
Object decodedObject = decoder.decode(response, Response.class); |
|
|
|
|
assertEquals(decodedObject.getClass(), Response.class, ""); |
|
|
|
|
assertEquals(decodedObject.getClass(), Response.class); |
|
|
|
|
Response decodedResponse = (Response) decodedObject; |
|
|
|
|
assertEquals(decodedResponse.status(), response.status()); |
|
|
|
|
assertEquals(decodedResponse.reason(), response.reason()); |
|
|
|
|
assertEquals(decodedResponse.headers(), response.headers()); |
|
|
|
|
assertEquals(decodedResponse.body().toString(), response.body().toString()); |
|
|
|
|
assertEquals(Util.toString(decodedResponse.body().asReader()), "response body"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test public void testDecodesToString() throws Exception { |
|
|
|
|
Response response = knownResponse(); |
|
|
|
|
Object decodedObject = decoder.decode(response, String.class); |
|
|
|
|
assertEquals(decodedObject.getClass(), String.class); |
|
|
|
|
assertEquals(decodedObject.toString(), response.body().toString()); |
|
|
|
|
assertEquals(decodedObject.toString(), "response body"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test public void testDecodesNullBodyToNull() throws Exception { |
|
|
|
@ -63,9 +64,11 @@ public class DefaultDecoderTest {
@@ -63,9 +64,11 @@ public class DefaultDecoderTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Response knownResponse() { |
|
|
|
|
String content = "response body"; |
|
|
|
|
StringReader reader = new StringReader(content); |
|
|
|
|
Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>(); |
|
|
|
|
headers.put("Content-Type", Collections.singleton("text/plain")); |
|
|
|
|
return Response.create(200, "OK", headers, "response body"); |
|
|
|
|
return Response.create(200, "OK", headers, reader, content.length()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Response nullBodyResponse() { |
|
|
|
|