AsyncFeign extends Feign { public static <C> AsyncBuilder<C> asyncBuilder() { return new AsyncBuilder<>(); } protected  AsyncFeign(AsyncBuilder<C> asyncBuilder); static AsyncBuilder<C> asyncBuilder(); @Override T newInstance(Target<T> target); T newInstance(Target<T> target, C context);  }
@Test public void testLowerWildReturnType() { thrown.expect(IllegalArgumentException.class); AsyncFeign.asyncBuilder().target(LowerWildApi.class, "http: }
@Test public void testUpperWildReturnType() { thrown.expect(IllegalArgumentException.class); AsyncFeign.asyncBuilder().target(UpperWildApi.class, "http: }
@Test public void testrWildReturnType() { thrown.expect(IllegalArgumentException.class); AsyncFeign.asyncBuilder().target(WildApi.class, "http: }
@Test public void throwsFeignExceptionIncludingBody() throws Throwable { server.enqueue(new MockResponse().setBody("success!")); TestInterfaceAsync api = AsyncFeign.asyncBuilder().decoder((response, type) -> { throw new IOException("timeout"); }).target(TestInterfaceAsync.class, "http: CompletableFuture<?> cf = api.body("Request body"); server.takeRequest(); try { unwrap(cf); } catch (FeignException e) { assertThat(e.getMessage()) .isEqualTo("timeout reading POST http: assertThat(e.contentUTF8()).isEqualTo("Request body"); return; } fail(); }
@Test public void throwsFeignExceptionWithoutBody() { server.enqueue(new MockResponse().setBody("success!")); TestInterfaceAsync api = AsyncFeign.asyncBuilder().decoder((response, type) -> { throw new IOException("timeout"); }).target(TestInterfaceAsync.class, "http: try { api.noContent(); } catch (FeignException e) { assertThat(e.getMessage()) .isEqualTo("timeout reading POST http: assertThat(e.contentUTF8()).isEqualTo(""); } }
@SuppressWarnings("deprecation") @Test public void whenReturnTypeIsResponseNoErrorHandling() throws Throwable { Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>(); headers.put("Location", Arrays.asList("http: final Response response = Response.builder().status(302).reason("Found").headers(headers) .request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8)) .body(new byte[0]).build(); ExecutorService execs = Executors.newSingleThreadExecutor(); TestInterfaceAsync api = AsyncFeign.<Void>asyncBuilder() .client(new AsyncClient.Default<>((request, options) -> response, execs)) .target(TestInterfaceAsync.class, "http: assertEquals(Collections.singletonList("http: unwrap(api.response()).headers().get("Location")); execs.shutdown(); }
@Test public void equalsHashCodeAndToStringWork() { Target<TestInterfaceAsync> t1 = new HardCodedTarget<TestInterfaceAsync>(TestInterfaceAsync.class, "http: Target<TestInterfaceAsync> t2 = new HardCodedTarget<TestInterfaceAsync>(TestInterfaceAsync.class, "http: Target<OtherTestInterfaceAsync> t3 = new HardCodedTarget<OtherTestInterfaceAsync>(OtherTestInterfaceAsync.class, "http: TestInterfaceAsync i1 = AsyncFeign.asyncBuilder().target(t1); TestInterfaceAsync i2 = AsyncFeign.asyncBuilder().target(t1); TestInterfaceAsync i3 = AsyncFeign.asyncBuilder().target(t2); OtherTestInterfaceAsync i4 = AsyncFeign.asyncBuilder().target(t3); assertThat(i1).isEqualTo(i2).isNotEqualTo(i3).isNotEqualTo(i4); assertThat(i1.hashCode()).isEqualTo(i2.hashCode()).isNotEqualTo(i3.hashCode()) .isNotEqualTo(i4.hashCode()); assertThat(i1.toString()).isEqualTo(i2.toString()).isNotEqualTo(i3.toString()) .isNotEqualTo(i4.toString()); assertThat(t1).isNotEqualTo(i1); assertThat(t1.hashCode()).isEqualTo(i1.hashCode()); assertThat(t1.toString()).isEqualTo(i1.toString()); }
@SuppressWarnings("resource") @Test public void decodeLogicSupportsByteArray() throws Throwable { byte[] expectedResponse = {12, 34, 56}; server.enqueue(new MockResponse().setBody(new Buffer().write(expectedResponse))); OtherTestInterfaceAsync api = AsyncFeign.asyncBuilder().target(OtherTestInterfaceAsync.class, "http: assertThat(unwrap(api.binaryResponseBody())).containsExactly(expectedResponse); }
@Test public void encodeLogicSupportsByteArray() throws Exception { byte[] expectedRequest = {12, 34, 56}; server.enqueue(new MockResponse()); OtherTestInterfaceAsync api = AsyncFeign.asyncBuilder().target(OtherTestInterfaceAsync.class, "http: CompletableFuture<?> cf = api.binaryRequestBody(expectedRequest); assertThat(server.takeRequest()).hasBody(expectedRequest); checkCFCompletedSoon(cf); }
@Test public void mapAndDecodeExecutesMapFunction() throws Throwable { server.enqueue(new MockResponse().setBody("response!")); TestInterfaceAsync api = AsyncFeign.asyncBuilder().mapAndDecode(upperCaseResponseMapper(), new StringDecoder()) .target(TestInterfaceAsync.class, "http: assertEquals("RESPONSE!", unwrap(api.post())); }
@Test public void testNonInterface() { thrown.expect(IllegalArgumentException.class); AsyncFeign.asyncBuilder().target(NonInterface.class, "http: }
@Test public void testExtendedCFReturnType() { thrown.expect(IllegalArgumentException.class); AsyncFeign.asyncBuilder().target(ExtendedCFApi.class, "http: }