Skip to content

Commit c9d6a9a

Browse files
jonfreedmanAdrian Cole
authored andcommitted
test for OpenFeign#511
1 parent 431b328 commit c9d6a9a

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

httpclient/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
<scope>test</scope>
3535
</dependency>
3636

37+
<dependency>
38+
<groupId>${project.groupId}</groupId>
39+
<artifactId>feign-jaxrs</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
3743
<dependency>
3844
<groupId>com.squareup.okhttp3</groupId>
3945
<artifactId>mockwebserver</artifactId>

httpclient/src/test/java/feign/httpclient/ApacheHttpClientTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818
import feign.Feign;
1919
import feign.Feign.Builder;
2020
import feign.client.AbstractClientTest;
21+
import feign.jaxrs.JAXRSContract;
22+
import okhttp3.mockwebserver.MockResponse;
23+
import okhttp3.mockwebserver.RecordedRequest;
24+
import org.apache.http.client.HttpClient;
25+
import org.apache.http.impl.client.HttpClientBuilder;
26+
import org.junit.Test;
27+
28+
import javax.ws.rs.GET;
29+
import javax.ws.rs.PUT;
30+
import javax.ws.rs.Path;
31+
import javax.ws.rs.QueryParam;
32+
33+
import java.nio.charset.StandardCharsets;
34+
35+
import static org.junit.Assert.assertEquals;
36+
import static org.junit.Assert.assertNull;
2137

2238
/**
2339
* Tests client-specific behavior, such as ensuring Content-Length is sent when specified.
@@ -28,4 +44,37 @@ public class ApacheHttpClientTest extends AbstractClientTest {
2844
public Builder newBuilder() {
2945
return Feign.builder().client(new ApacheHttpClient());
3046
}
47+
48+
@Test
49+
public void queryParamsAreRespectedWhenBodyIsEmpty() throws InterruptedException {
50+
final HttpClient httpClient = HttpClientBuilder.create().build();
51+
final JaxRsTestInterface testInterface = Feign.builder()
52+
.contract(new JAXRSContract())
53+
.client(new ApacheHttpClient(httpClient))
54+
.target(JaxRsTestInterface.class, "http://localhost:" + server.getPort());
55+
56+
server.enqueue(new MockResponse().setBody("foo"));
57+
server.enqueue(new MockResponse().setBody("foo"));
58+
59+
assertEquals("foo", testInterface.withBody("foo", "bar"));
60+
final RecordedRequest request1 = server.takeRequest();
61+
assertEquals("/withBody?foo=foo", request1.getPath());
62+
assertEquals("bar", request1.getBody().readString(StandardCharsets.UTF_8));
63+
64+
assertEquals("foo", testInterface.withoutBody("foo"));
65+
final RecordedRequest request2 = server.takeRequest();
66+
assertEquals("/withoutBody?foo=foo", request2.getPath());
67+
assertEquals("", request2.getBody().readString(StandardCharsets.UTF_8));
68+
}
69+
70+
@Path("/")
71+
public interface JaxRsTestInterface {
72+
@PUT
73+
@Path("/withBody")
74+
public String withBody(@QueryParam("foo") String foo, String bar);
75+
76+
@PUT
77+
@Path("/withoutBody")
78+
public String withoutBody(@QueryParam("foo") String foo);
79+
}
3180
}

0 commit comments

Comments
 (0)