55
66import io .clientcore .annotation .processor .test .implementation .TestInterfaceClientImpl ;
77import io .clientcore .annotation .processor .test .implementation .models .Foo ;
8+ import io .clientcore .annotation .processor .test .implementation .models .HttpBinJSON ;
89import io .clientcore .core .http .client .HttpClient ;
910import io .clientcore .core .http .models .Response ;
1011import io .clientcore .core .http .pipeline .HttpPipeline ;
2122import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
2223import static org .junit .jupiter .api .Assertions .assertEquals ;
2324import static org .junit .jupiter .api .Assertions .assertNotNull ;
25+ import static org .junit .jupiter .api .Assertions .fail ;
2426
2527public class TestInterfaceGenerationTests {
2628 private static LocalTestServer server ;
@@ -115,6 +117,148 @@ public void getRequestWithNoReturn() {
115117 assertDoesNotThrow (() -> testInterface .getNothing (getServerUri (false )));
116118 }
117119
120+ @ Test
121+ public void getRequestWithAnything () {
122+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
123+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
124+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
125+ final HttpBinJSON json = testInterface .getAnything (getServerUri (false ));
126+
127+ assertNotNull (json );
128+ assertMatchWithHttpOrHttps ("localhost/anything" , json .uri ());
129+ }
130+
131+ @ Test
132+ public void getRequestWithAnythingWithPlus () {
133+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
134+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
135+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
136+ final HttpBinJSON json = testInterface .getAnythingWithPlus (getServerUri (false ));
137+
138+ assertNotNull (json );
139+ assertMatchWithHttpOrHttps ("localhost/anything/with+plus" , json .uri ());
140+ }
141+
142+ @ Test
143+ public void getRequestWithAnythingWithPathParam () {
144+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
145+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
146+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
147+ final HttpBinJSON json
148+ = testInterface .getAnythingWithPathParam (getServerUri (false ), "withpathparam" );
149+
150+ assertNotNull (json );
151+ assertMatchWithHttpOrHttps ("localhost/anything/withpathparam" , json .uri ());
152+ }
153+
154+ @ Test
155+ public void getRequestWithAnythingWithPathParamWithSpace () {
156+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
157+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
158+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
159+ final HttpBinJSON json
160+ = testInterface .getAnythingWithPathParam (getServerUri (false ), "with path param" );
161+
162+ assertNotNull (json );
163+ assertMatchWithHttpOrHttps ("localhost/anything/with path param" , json .uri ());
164+ }
165+
166+ @ Test
167+ public void getRequestWithAnythingWithPathParamWithPlus () {
168+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
169+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
170+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
171+ final HttpBinJSON json
172+ = testInterface .getAnythingWithPathParam (getServerUri (false ), "with+path+param" );
173+
174+ assertNotNull (json );
175+ assertMatchWithHttpOrHttps ("localhost/anything/with+path+param" , json .uri ());
176+ }
177+
178+ @ Test
179+ public void getRequestWithAnythingWithEncodedPathParam () {
180+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
181+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
182+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
183+ final HttpBinJSON json
184+ = testInterface .getAnythingWithEncodedPathParam (getServerUri (false ), "withpathparam" );
185+
186+ assertNotNull (json );
187+ assertMatchWithHttpOrHttps ("localhost/anything/withpathparam" , json .uri ());
188+ }
189+
190+ @ Test
191+ public void getRequestWithAnythingWithEncodedPathParamWithPercent20 () {
192+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
193+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
194+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
195+ final HttpBinJSON json
196+ = testInterface .getAnythingWithEncodedPathParam (getServerUri (false ), "with%20path%20param" );
197+
198+ assertNotNull (json );
199+ assertMatchWithHttpOrHttps ("localhost/anything/with path param" , json .uri ());
200+ }
201+
202+ @ Test
203+ public void getRequestWithAnythingWithEncodedPathParamWithPlus () {
204+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
205+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
206+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
207+ final HttpBinJSON json
208+ = testInterface .getAnythingWithEncodedPathParam (getServerUri (false ), "with+path+param" );
209+
210+ assertNotNull (json );
211+ assertMatchWithHttpOrHttps ("localhost/anything/with+path+param" , json .uri ());
212+ }
213+
214+ @ Test
215+ public void getRequestWithQueryParametersAndAnything () {
216+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
217+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
218+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
219+ final HttpBinJSON json
220+ = testInterface .getAnything (getServerUri (false ), "A" , 15 );
221+
222+ assertNotNull (json );
223+ assertMatchWithHttpOrHttps ("localhost/anything?a=A&b=15" , json .uri ());
224+ }
225+
226+ @ Test
227+ public void getRequestWithQueryParametersAndAnythingWithPercent20 () {
228+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
229+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
230+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
231+ final HttpBinJSON json
232+ = testInterface .getAnything (getServerUri (false ), "A%20Z" , 15 );
233+
234+ assertNotNull (json );
235+ assertMatchWithHttpOrHttps ("localhost/anything?a=A%2520Z&b=15" , json .uri ());
236+ }
237+
238+ @ Test
239+ public void getRequestWithQueryParametersAndAnythingWithEncodedWithPercent20 () {
240+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
241+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
242+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
243+ final HttpBinJSON json
244+ = testInterface .getAnythingWithEncoded (getServerUri (false ), "x%20y" , 15 );
245+
246+ assertNotNull (json );
247+ assertMatchWithHttpOrHttps ("localhost/anything?a=x y&b=15" , json .uri ());
248+ }
249+
250+ @ Test
251+ public void getRequestWithNullQueryParameter () {
252+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
253+ TestInterfaceClientImpl .TestInterfaceClientService testInterface =
254+ TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline );
255+ final HttpBinJSON json
256+ = testInterface .getAnything (getServerUri (false ), null , 15 );
257+
258+ assertNotNull (json );
259+ assertMatchWithHttpOrHttps ("localhost/anything?b=15" , json .uri ());
260+ }
261+
118262 private HttpClient getHttpClient () {
119263 return new OkHttpHttpClientProvider ().getSharedInstance ();
120264 }
@@ -123,4 +267,20 @@ private String getServerUri(boolean secure) {
123267 return secure ? server .getHttpsUri () : server .getHttpUri ();
124268 }
125269
270+ private static void assertMatchWithHttpOrHttps (String uri1 , String uri2 ) {
271+ final String s1 = "http://" + uri1 ;
272+
273+ if (s1 .equalsIgnoreCase (uri2 )) {
274+ return ;
275+ }
276+
277+ final String s2 = "https://" + uri1 ;
278+
279+ if (s2 .equalsIgnoreCase (uri2 )) {
280+ return ;
281+ }
282+
283+ fail ("'" + uri2 + "' does not match with '" + s1 + "' or '" + s2 + "'." );
284+ }
285+
126286}
0 commit comments