1818import feign .Feign ;
1919import feign .Feign .Builder ;
2020import 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