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 ;
98import io .clientcore .core .http .client .HttpClient ;
10- import io .clientcore .core .http .models .RequestOptions ;
119import io .clientcore .core .http .models .Response ;
12- import io .clientcore .core .http .models .ResponseBodyMode ;
1310import io .clientcore .core .http .pipeline .HttpPipeline ;
1411import io .clientcore .core .http .pipeline .HttpPipelineBuilder ;
1512import io .clientcore .core .models .binarydata .BinaryData ;
2118import org .junit .jupiter .api .Disabled ;
2219import org .junit .jupiter .api .Test ;
2320
24- import java .io .IOException ;
25-
26- import static io .clientcore .core .http .models .ResponseBodyMode .BUFFER ;
27- import static io .clientcore .core .http .models .ResponseBodyMode .DESERIALIZE ;
28- import static io .clientcore .core .http .models .ResponseBodyMode .IGNORE ;
29- import static io .clientcore .core .http .models .ResponseBodyMode .STREAM ;
3021import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
3122import static org .junit .jupiter .api .Assertions .assertEquals ;
3223import static org .junit .jupiter .api .Assertions .assertNotNull ;
33- import static org .junit .jupiter .api .Assertions .assertNull ;
3424
3525public class TestInterfaceGenerationTests {
3626 private static LocalTestServer server ;
@@ -64,12 +54,8 @@ public void testGetFoo() {
6454 =
6555 "{\" bar\" :\" hello.world\" ,\" baz\" :[\" hello\" ,\" hello.world\" ],\" qux\" :{\" a.b\" :\" c.d\" ,\" bar.a\" :\" ttyy\" ,\" bar.b\" :\" uuzz\" ,\" hello\" :\" world\" },\" additionalProperties\" :{\" bar\" :\" baz\" ,\" a.b\" :\" c.d\" ,\" properties.bar\" :\" barbar\" }}" ;
6656
67- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient ((request ) -> {
68- // what is the default response body mode?
69- request .setRequestOptions (new RequestOptions ().setResponseBodyMode (ResponseBodyMode .DESERIALIZE ));
70- return new MockHttpResponse (request , 200 ,
71- BinaryData .fromString (wireValue ));
72- }).build ();
57+ HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (request ->
58+ new MockHttpResponse (request , 200 , BinaryData .fromString (wireValue ))).build ();
7359
7460 TestInterfaceClientImpl .TestInterfaceClientService testInterface =
7561 TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
@@ -90,88 +76,6 @@ public void testGetFoo() {
9076 assertEquals ("barbar" , foo .additionalProperties ().get ("properties.bar" ));
9177 }
9278
93- @ Test
94- public void bodyIsEmptyWhenIgnoreBodyIsSet () throws IOException {
95- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
96-
97- TestInterfaceClientImpl .TestInterfaceClientService testInterface =
98- TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
99- assertNotNull (testInterface );
100- RequestOptions requestOptions = new RequestOptions ().setResponseBodyMode (IGNORE );
101- HttpBinJSON httpBinJSON = testInterface .putConvenience (getServerUri (false ), 42 , requestOptions );
102-
103- assertNull (httpBinJSON );
104-
105- try (Response <HttpBinJSON > response = testInterface .putResponse (getServerUri (false ), 42 , requestOptions )) {
106- assertNull (response .getValue ());
107- }
108- }
109-
110- @ Test
111- public void bodyIsEmptyWhenIgnoreBodyIsSetForStreamResponse () throws IOException {
112- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
113- TestInterfaceClientImpl .TestInterfaceClientService testInterface =
114- TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
115- assertNotNull (testInterface );
116- RequestOptions requestOptions = new RequestOptions ().setResponseBodyMode (IGNORE );
117- HttpBinJSON httpBinJSON = testInterface .postStreamConvenience (getServerUri (false ), 42 , requestOptions );
118-
119- assertNull (httpBinJSON );
120-
121- try (
122- Response <HttpBinJSON > response = testInterface .postStreamResponse (getServerUri (false ), 42 , requestOptions )) {
123- assertNull (response .getValue ());
124- }
125- }
126-
127- // TODO (alzimmer): How do we handle streaming?
128- @ Test
129- public void bodyIsStreamedWhenResponseBodyModeIndicatesIt () throws IOException {
130- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
131- TestInterfaceClientImpl .TestInterfaceClientService testInterface =
132- TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
133- assertNotNull (testInterface );
134- RequestOptions requestOptions = new RequestOptions ().setResponseBodyMode (STREAM );
135-
136- try (
137- Response <HttpBinJSON > response = testInterface .postStreamResponse (getServerUri (false ), 42 , requestOptions )) {
138- assertNotNull (response .getValue ());
139- }
140- }
141-
142- @ Test
143- public void bodyIsBufferedWhenResponseBodyModeIndicatesIt () throws IOException {
144- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
145- TestInterfaceClientImpl .TestInterfaceClientService testInterface =
146- TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
147- assertNotNull (testInterface );
148- RequestOptions requestOptions = new RequestOptions ().setResponseBodyMode (BUFFER );
149- HttpBinJSON httpBinJSON = testInterface .postStreamConvenience (getServerUri (false ), 42 , requestOptions );
150-
151- assertNotNull (httpBinJSON );
152-
153- try (
154- Response <HttpBinJSON > response = testInterface .postStreamResponse (getServerUri (false ), 42 , requestOptions )) {
155- assertNotNull (response .getValue ());
156- }
157- }
158-
159- @ Test
160- public void bodyIsDeserializedWhenResponseBodyModeIndicatesIt () throws IOException {
161- HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
162- TestInterfaceClientImpl .TestInterfaceClientService testInterface =
163- TestInterfaceClientImpl .TestInterfaceClientService .getNewInstance (pipeline , null );
164- assertNotNull (testInterface );
165- RequestOptions requestOptions = new RequestOptions ().setResponseBodyMode (DESERIALIZE );
166- HttpBinJSON httpBinJSON = testInterface .postStreamConvenience (getServerUri (false ), 42 , requestOptions );
167-
168- assertNotNull (httpBinJSON );
169-
170- try (Response <HttpBinJSON > response = testInterface .postStreamResponse (getServerUri (false ), 42 , requestOptions )) {
171- assertNotNull (response .getValue ());
172- }
173- }
174-
17579 @ Test
17680 public void requestWithByteArrayReturnType () {
17781 HttpPipeline pipeline = new HttpPipelineBuilder ().httpClient (getHttpClient ()).build ();
0 commit comments