use of feign.codec.Decoder in project feign by OpenFeign.
the class BaseApiTest method resolvesBodyParameter.
@Test
public void resolvesBodyParameter() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder().encoder(new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
assertThat(bodyType).isEqualTo(new TypeToken<Keys<String>>() {
}.getType());
}
}).decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type).isEqualTo(new TypeToken<Entities<String, Long>>() {
}.getType());
return null;
}
}).target(MyApi.class, baseUrl).getAll(new Keys<String>());
}
use of feign.codec.Decoder in project feign by OpenFeign.
the class BaseApiTest method resolvesParameterizedResult.
@Test
public void resolvesParameterizedResult() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder().decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type).isEqualTo(new TypeToken<Entity<String, Long>>() {
}.getType());
return null;
}
}).target(MyApi.class, baseUrl).get("foo");
assertThat(server.takeRequest()).hasPath("/default/api/foo");
}
use of feign.codec.Decoder in project feign by OpenFeign.
the class FeignBuilderTest method testOverrideDecoder.
@Test
public void testOverrideDecoder() throws Exception {
server.enqueue(new MockResponse().setBody("success!"));
String url = "http://localhost:" + server.getPort();
Decoder decoder = new Decoder() {
@Override
public Object decode(Response response, Type type) {
return "fail";
}
};
TestInterface api = Feign.builder().decoder(decoder).target(TestInterface.class, url);
assertEquals("fail", api.decodedPost());
assertEquals(1, server.getRequestCount());
}