33import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
44import static com .github .tomakehurst .wiremock .client .WireMock .get ;
55import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
6+ import static com .github .tomakehurst .wiremock .client .WireMock .post ;
7+ import static com .github .tomakehurst .wiremock .client .WireMock .postRequestedFor ;
68import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
79import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
810import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
@@ -30,6 +32,7 @@ class ApacheApiClientResponseHandlingTest
3032{
3133 private static final String TEST_PATH = "/test" ;
3234 private static final String TEST_RESPONSE_BODY = "{\" message\" : \" success\" }" ;
35+ private static final String TEST_POST_PATH = "/test-post" ;
3336
3437 @ Test
3538 void testResponseMetadataListener ( final WireMockRuntimeInfo wmInfo )
@@ -84,6 +87,22 @@ void testCaseInsensitiveHeaderLookup( final WireMockRuntimeInfo wmInfo )
8487 assertThat (headers .get ("X-CUSTOM-HEADER" )).contains ("some-value" );
8588 }
8689
90+ @ Test
91+ void testGzipEncodedPayload ( final WireMockRuntimeInfo wmInfo )
92+ {
93+ stubFor (post (urlEqualTo (TEST_POST_PATH )).willReturn (aResponse ().withStatus (200 ).withBody (TEST_RESPONSE_BODY )));
94+
95+ final ApiClient apiClient = ApiClient .create ().withBasePath (wmInfo .getHttpBaseUrl ());
96+
97+ final TestPostApi api = new TestPostApi (apiClient );
98+ final TestResponse result = api .executeGzipRequest ();
99+
100+ assertThat (result ).isNotNull ();
101+ assertThat (result .getMessage ()).isEqualTo ("success" );
102+
103+ verify (1 , postRequestedFor (urlEqualTo (TEST_POST_PATH )));
104+ }
105+
87106 private static class TestApi extends BaseApi
88107 {
89108 private final String path ;
@@ -104,7 +123,7 @@ TestResponse executeRequest()
104123 {
105124 final List <Pair > localVarQueryParams = new ArrayList <>();
106125 final List <Pair > localVarCollectionQueryParams = new ArrayList <>();
107- final Map <String , String > localVarHeaderParams = new HashMap <>( );
126+ final Map <String , String > localVarHeaderParams = Map . of ( "Content-Encoding" , "gzip" );
108127 final Map <String , Object > localVarFormParams = new HashMap <>();
109128
110129 final String [] localVarAccepts = { "application/json" };
@@ -113,7 +132,7 @@ TestResponse executeRequest()
113132 final String [] localVarContentTypes = {};
114133 final String localVarContentType = ApiClient .selectHeaderContentType (localVarContentTypes );
115134
116- final TypeReference <TestResponse > localVarReturnType = new TypeReference <TestResponse >()
135+ final TypeReference <TestResponse > localVarReturnType = new TypeReference <>()
117136 {
118137 };
119138
@@ -133,6 +152,59 @@ TestResponse executeRequest()
133152 }
134153 }
135154
155+ private static class TestPostApi extends BaseApi
156+ {
157+ private final String path ;
158+
159+ TestPostApi ( final ApiClient apiClient )
160+ {
161+ this (apiClient , TEST_POST_PATH );
162+ }
163+
164+ TestPostApi ( final ApiClient apiClient , final String path )
165+ {
166+ super (apiClient );
167+ this .path = path ;
168+ }
169+
170+ TestResponse executeGzipRequest ()
171+ throws OpenApiRequestException
172+ {
173+ final TestResponse requestBody = new TestResponse ();
174+ requestBody .setMessage ("test payload" );
175+
176+ final List <Pair > localVarQueryParams = new ArrayList <>();
177+ final List <Pair > localVarCollectionQueryParams = new ArrayList <>();
178+ final Map <String , String > localVarHeaderParams = new HashMap <>();
179+ localVarHeaderParams .put ("Content-Encoding" , "gzip" );
180+ final Map <String , Object > localVarFormParams = new HashMap <>();
181+
182+ final String [] localVarAccepts = { "application/json" };
183+ final String localVarAccept = ApiClient .selectHeaderAccept (localVarAccepts );
184+
185+ final String [] localVarContentTypes = { "application/json" };
186+ final String localVarContentType = ApiClient .selectHeaderContentType (localVarContentTypes );
187+
188+ final TypeReference <TestResponse > localVarReturnType = new TypeReference <>()
189+ {
190+ };
191+
192+ return apiClient
193+ .invokeAPI (
194+ path ,
195+ "POST" ,
196+ localVarQueryParams ,
197+ localVarCollectionQueryParams ,
198+ null ,
199+ requestBody ,
200+ localVarHeaderParams ,
201+ localVarFormParams ,
202+ localVarAccept ,
203+ localVarContentType ,
204+ localVarReturnType );
205+ }
206+ }
207+
136208 @ Data
137209 private static class TestResponse
138210 {
0 commit comments