@@ -64,6 +64,8 @@ class HttpClientTransportTests {
64
64
65
65
private static final String APPLICATION_JSON = "application/json" ;
66
66
67
+ private static final String APPLICATION_X_TAR = "application/x-tar" ;
68
+
67
69
@ Mock
68
70
private CloseableHttpClient client ;
69
71
@@ -155,44 +157,90 @@ void postWithEmptyRegistryAuthShouldExecuteHttpPostWithoutHeader() throws Except
155
157
}
156
158
157
159
@ Test
158
- void postWithContentShouldExecuteHttpPost () throws Exception {
160
+ void postWithJsonContentShouldExecuteHttpPost () throws Exception {
161
+ String content = "test" ;
159
162
givenClientWillReturnResponse ();
160
163
given (this .entity .getContent ()).willReturn (this .content );
161
164
given (this .statusLine .getStatusCode ()).willReturn (200 );
162
165
Response response = this .http .post (this .uri , APPLICATION_JSON ,
163
- (out ) -> StreamUtils .copy ("test" , StandardCharsets .UTF_8 , out ));
166
+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
167
+ verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
168
+ HttpUriRequest request = this .requestCaptor .getValue ();
169
+ HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
170
+ assertThat (request ).isInstanceOf (HttpPost .class );
171
+ assertThat (request .getURI ()).isEqualTo (this .uri );
172
+ assertThat (entity .isRepeatable ()).isFalse ();
173
+ assertThat (entity .getContentLength ()).isEqualTo (content .length ());
174
+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_JSON );
175
+ assertThat (entity .isStreaming ()).isTrue ();
176
+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
177
+ assertThat (writeToString (entity )).isEqualTo (content );
178
+ assertThat (response .getContent ()).isSameAs (this .content );
179
+ }
180
+
181
+ @ Test
182
+ void postWithArchiveContentShouldExecuteHttpPost () throws Exception {
183
+ String content = "test" ;
184
+ givenClientWillReturnResponse ();
185
+ given (this .entity .getContent ()).willReturn (this .content );
186
+ given (this .statusLine .getStatusCode ()).willReturn (200 );
187
+ Response response = this .http .post (this .uri , APPLICATION_X_TAR ,
188
+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
164
189
verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
165
190
HttpUriRequest request = this .requestCaptor .getValue ();
166
191
HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
167
192
assertThat (request ).isInstanceOf (HttpPost .class );
168
193
assertThat (request .getURI ()).isEqualTo (this .uri );
169
- assertThat (request .getFirstHeader (HttpHeaders .CONTENT_TYPE ).getValue ()).isEqualTo (APPLICATION_JSON );
170
194
assertThat (entity .isRepeatable ()).isFalse ();
171
195
assertThat (entity .getContentLength ()).isEqualTo (-1 );
196
+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_X_TAR );
172
197
assertThat (entity .isStreaming ()).isTrue ();
173
198
assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
174
- assertThat (writeToString (entity )).isEqualTo ("test" );
199
+ assertThat (writeToString (entity )).isEqualTo (content );
175
200
assertThat (response .getContent ()).isSameAs (this .content );
176
201
}
177
202
178
203
@ Test
179
- void putWithContentShouldExecuteHttpPut () throws Exception {
204
+ void putWithJsonContentShouldExecuteHttpPut () throws Exception {
205
+ String content = "test" ;
180
206
givenClientWillReturnResponse ();
181
207
given (this .entity .getContent ()).willReturn (this .content );
182
208
given (this .statusLine .getStatusCode ()).willReturn (200 );
183
209
Response response = this .http .put (this .uri , APPLICATION_JSON ,
184
- (out ) -> StreamUtils .copy ("test" , StandardCharsets .UTF_8 , out ));
210
+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
211
+ verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
212
+ HttpUriRequest request = this .requestCaptor .getValue ();
213
+ HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
214
+ assertThat (request ).isInstanceOf (HttpPut .class );
215
+ assertThat (request .getURI ()).isEqualTo (this .uri );
216
+ assertThat (entity .isRepeatable ()).isFalse ();
217
+ assertThat (entity .getContentLength ()).isEqualTo (content .length ());
218
+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_JSON );
219
+ assertThat (entity .isStreaming ()).isTrue ();
220
+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
221
+ assertThat (writeToString (entity )).isEqualTo (content );
222
+ assertThat (response .getContent ()).isSameAs (this .content );
223
+ }
224
+
225
+ @ Test
226
+ void putWithArchiveContentShouldExecuteHttpPut () throws Exception {
227
+ String content = "test" ;
228
+ givenClientWillReturnResponse ();
229
+ given (this .entity .getContent ()).willReturn (this .content );
230
+ given (this .statusLine .getStatusCode ()).willReturn (200 );
231
+ Response response = this .http .put (this .uri , APPLICATION_X_TAR ,
232
+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
185
233
verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
186
234
HttpUriRequest request = this .requestCaptor .getValue ();
187
235
HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
188
236
assertThat (request ).isInstanceOf (HttpPut .class );
189
237
assertThat (request .getURI ()).isEqualTo (this .uri );
190
- assertThat (request .getFirstHeader (HttpHeaders .CONTENT_TYPE ).getValue ()).isEqualTo (APPLICATION_JSON );
191
238
assertThat (entity .isRepeatable ()).isFalse ();
192
239
assertThat (entity .getContentLength ()).isEqualTo (-1 );
240
+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_X_TAR );
193
241
assertThat (entity .isStreaming ()).isTrue ();
194
242
assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
195
- assertThat (writeToString (entity )).isEqualTo ("test" );
243
+ assertThat (writeToString (entity )).isEqualTo (content );
196
244
assertThat (response .getContent ()).isSameAs (this .content );
197
245
}
198
246
0 commit comments