@Test public void reasonPhraseIsOptional() throws IOException, InterruptedException { server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200)); TestInterface api = Feign.builder().target(TestInterface.class, "http://localhost:" + server.getPort()); Response response = api.post("foo"); assertThat(response.status()).isEqualTo(200); assertThat(response.reason()).isNull(); }
@Test public void canOverrideHostnameVerifier() throws IOException, InterruptedException { server.useHttps(TrustingSSLSocketFactory.get("bad.example.com"), false); server.enqueue(new MockResponse()); TestInterface api = Feign.builder() .client(disableHostnameVerification) .target(TestInterface.class, "https://localhost:" + server.getPort()); api.post("foo"); }
@Test public void canOverrideSSLSocketFactory() throws IOException, InterruptedException { server.useHttps(TrustingSSLSocketFactory.get("localhost"), false); server.enqueue(new MockResponse()); TestInterface api = Feign.builder() .client(trustSSLSockets) .target(TestInterface.class, "https://localhost:" + server.getPort()); api.post("foo"); }
@Test public void retriesFailedHandshake() throws IOException, InterruptedException { server.useHttps(TrustingSSLSocketFactory.get("localhost"), false); server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE)); server.enqueue(new MockResponse()); TestInterface api = Feign.builder() .client(trustSSLSockets) .target(TestInterface.class, "https://localhost:" + server.getPort()); api.post("foo"); assertEquals(2, server.getRequestCount()); }
/** This shows that is a no-op or otherwise doesn't cause an NPE when there's no content. */ @Test public void safeRebuffering_noContent() throws IOException, InterruptedException { server.enqueue(new MockResponse().setResponseCode(204)); TestInterface api = Feign.builder() .logger( new Logger() { @Override protected void log(String configKey, String format, Object... args) {} }) .logLevel(Logger.Level.FULL) // rebuffers the body .target(TestInterface.class, "http://localhost:" + server.getPort()); api.post("foo"); }
@Test public void testHTTPSViaRibbon() { Client trustSSLSockets = new Client.Default(TrustingSSLSocketFactory.get(), null); server1.get().useHttps(TrustingSSLSocketFactory.get("localhost"), false); server1.enqueue(new MockResponse().setBody("success!")); getConfigInstance().setProperty(serverListKey(), hostAndPort(server1.getUrl(""))); TestInterface api = Feign.builder() .client(RibbonClient.builder().delegate(trustSSLSockets).build()) .target(TestInterface.class, "https://" + client()); api.post(); assertEquals(1, server1.getRequestCount()); }
@Test public void ioExceptionRetry() throws IOException, InterruptedException { server1.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START)); server1.enqueue(new MockResponse().setBody("success!")); getConfigInstance().setProperty(serverListKey(), hostAndPort(server1.getUrl(""))); TestInterface api = Feign.builder() .client(RibbonClient.create()) .target(TestInterface.class, "http://" + client()); api.post(); assertEquals(2, server1.getRequestCount()); // TODO: verify ribbon stats match // assertEquals(target.lb().getLoadBalancerStats().getSingleServerStat()) }
@Test public void parsesRequestAndResponse() throws IOException, InterruptedException { server.enqueue(new MockResponse().setBody("foo").addHeader("Foo: Bar")); TestInterface api = Feign.builder().target(TestInterface.class, "http://localhost:" + server.getPort()); Response response = api.post("foo"); assertThat(response.status()).isEqualTo(200); assertThat(response.reason()).isEqualTo("OK"); assertThat(response.headers()) .containsEntry("Content-Length", asList("3")) .containsEntry("Foo", asList("Bar")); assertThat(response.body().asInputStream()) .hasContentEqualTo(new ByteArrayInputStream("foo".getBytes(UTF_8))); assertThat(server.takeRequest()) .hasMethod("POST") .hasPath("/?foo=bar&foo=baz&qux=") .hasHeaders("Foo: Bar", "Foo: Baz", "Qux: ", "Accept: */*", "Content-Length: 3") .hasBody("foo"); }