MCPcopy Index your code
hub / github.com/OpenFeign/feign / AbstractClientTest

Class AbstractClientTest

core/src/test/java/feign/client/AbstractClientTest.java:55–622  ·  view source on GitHub ↗

AbstractClientTest can be extended to run a set of tests against any Client implementation.

Source from the content-addressed store, hash-verified

53 * implementation.
54 */
55public abstract class AbstractClientTest {
56 public final MockWebServer server = new MockWebServer();
57
58 /** Create a Feign {@link Builder} with a client configured */
59 public abstract Builder newBuilder();
60
61 /**
62 * Some client implementation tests should override this test if the PATCH operation is
63 * unsupported.
64 */
65 @Test
66 public void patch() throws Exception {
67 server.enqueue(new MockResponse().setBody("foo"));
68 server.enqueue(new MockResponse());
69
70 TestInterface api =
71 newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
72
73 assertThat(api.patch("")).isEqualTo("foo");
74
75 MockWebServerAssertions.assertThat(server.takeRequest())
76 .hasHeaders(
77 entry("Accept", Collections.singletonList("text/plain")),
78 entry("Content-Length", Collections.singletonList("0")))
79 .hasNoHeaderNamed("Content-Type")
80 .hasMethod("PATCH");
81 }
82
83 @Test
84 public void parsesRequestAndResponse() throws IOException, InterruptedException {
85 server.enqueue(new MockResponse().setBody("foo").addHeader("Foo: Bar"));
86
87 TestInterface api =
88 newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
89
90 Response response = api.post("foo");
91
92 assertThat(response.status()).isEqualTo(200);
93 assertThat(response.reason()).isEqualTo("OK");
94 assertThat(response.headers())
95 .hasEntrySatisfying(
96 "Content-Length",
97 value -> {
98 assertThat(value).contains("3");
99 })
100 .hasEntrySatisfying(
101 "Foo",
102 value -> {
103 assertThat(value).contains("Bar");
104 });
105 assertThat(response.body().asInputStream())
106 .hasSameContentAs(new ByteArrayInputStream("foo".getBytes(UTF_8)));
107
108 RecordedRequest recordedRequest = server.takeRequest();
109 assertThat(recordedRequest.getMethod()).isEqualToIgnoringCase("POST");
110 assertThat(recordedRequest.getHeader("Foo")).isEqualToIgnoringCase("Bar, Baz");
111 assertThat(recordedRequest.getHeader("Accept")).isEqualToIgnoringCase("*/*");
112 assertThat(recordedRequest.getHeader("Content-Length")).isEqualToIgnoringCase("3");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected