@@ -62,6 +62,8 @@ class HttpClientTransportTests {
6262
6363 private static final String APPLICATION_JSON = "application/json" ;
6464
65+ private static final String APPLICATION_X_TAR = "application/x-tar" ;
66+
6567 @ Mock
6668 private CloseableHttpClient client ;
6769
@@ -124,42 +126,86 @@ void postShouldExecuteHttpPost() throws Exception {
124126 }
125127
126128 @ Test
127- void postWithContentShouldExecuteHttpPost () throws Exception {
129+ void postWithJsonContentShouldExecuteHttpPost () throws Exception {
130+ String content = "test" ;
128131 given (this .entity .getContent ()).willReturn (this .content );
129132 given (this .statusLine .getStatusCode ()).willReturn (200 );
130133 Response response = this .http .post (this .uri , APPLICATION_JSON ,
131- (out ) -> StreamUtils .copy ("test" , StandardCharsets .UTF_8 , out ));
134+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
135+ verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
136+ HttpUriRequest request = this .requestCaptor .getValue ();
137+ HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
138+ assertThat (request ).isInstanceOf (HttpPost .class );
139+ assertThat (request .getURI ()).isEqualTo (this .uri );
140+ assertThat (entity .isRepeatable ()).isFalse ();
141+ assertThat (entity .getContentLength ()).isEqualTo (content .length ());
142+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_JSON );
143+ assertThat (entity .isStreaming ()).isTrue ();
144+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
145+ assertThat (writeToString (entity )).isEqualTo (content );
146+ assertThat (response .getContent ()).isSameAs (this .content );
147+ }
148+
149+ @ Test
150+ void postWithArchiveContentShouldExecuteHttpPost () throws Exception {
151+ String content = "test" ;
152+ given (this .entity .getContent ()).willReturn (this .content );
153+ given (this .statusLine .getStatusCode ()).willReturn (200 );
154+ Response response = this .http .post (this .uri , APPLICATION_X_TAR ,
155+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
132156 verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
133157 HttpUriRequest request = this .requestCaptor .getValue ();
134158 HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
135159 assertThat (request ).isInstanceOf (HttpPost .class );
136160 assertThat (request .getURI ()).isEqualTo (this .uri );
137- assertThat (request .getFirstHeader (HttpHeaders .CONTENT_TYPE ).getValue ()).isEqualTo (APPLICATION_JSON );
138161 assertThat (entity .isRepeatable ()).isFalse ();
139162 assertThat (entity .getContentLength ()).isEqualTo (-1 );
163+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_X_TAR );
140164 assertThat (entity .isStreaming ()).isTrue ();
141165 assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
142- assertThat (writeToString (entity )).isEqualTo ("test" );
166+ assertThat (writeToString (entity )).isEqualTo (content );
143167 assertThat (response .getContent ()).isSameAs (this .content );
144168 }
145169
146170 @ Test
147- void putWithContentShouldExecuteHttpPut () throws Exception {
171+ void putWithJsonContentShouldExecuteHttpPut () throws Exception {
172+ String content = "test" ;
148173 given (this .entity .getContent ()).willReturn (this .content );
149174 given (this .statusLine .getStatusCode ()).willReturn (200 );
150175 Response response = this .http .put (this .uri , APPLICATION_JSON ,
151- (out ) -> StreamUtils .copy ("test" , StandardCharsets .UTF_8 , out ));
176+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
177+ verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
178+ HttpUriRequest request = this .requestCaptor .getValue ();
179+ HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
180+ assertThat (request ).isInstanceOf (HttpPut .class );
181+ assertThat (request .getURI ()).isEqualTo (this .uri );
182+ assertThat (entity .isRepeatable ()).isFalse ();
183+ assertThat (entity .getContentLength ()).isEqualTo (content .length ());
184+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_JSON );
185+ assertThat (entity .isStreaming ()).isTrue ();
186+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
187+ assertThat (writeToString (entity )).isEqualTo (content );
188+ assertThat (response .getContent ()).isSameAs (this .content );
189+ }
190+
191+ @ Test
192+ void putWithArchiveContentShouldExecuteHttpPut () throws Exception {
193+ String content = "test" ;
194+ given (this .entity .getContent ()).willReturn (this .content );
195+ given (this .statusLine .getStatusCode ()).willReturn (200 );
196+ Response response = this .http .put (this .uri , APPLICATION_X_TAR ,
197+ (out ) -> StreamUtils .copy (content , StandardCharsets .UTF_8 , out ));
152198 verify (this .client ).execute (this .hostCaptor .capture (), this .requestCaptor .capture ());
153199 HttpUriRequest request = this .requestCaptor .getValue ();
154200 HttpEntity entity = ((HttpEntityEnclosingRequest ) request ).getEntity ();
155201 assertThat (request ).isInstanceOf (HttpPut .class );
156202 assertThat (request .getURI ()).isEqualTo (this .uri );
157- assertThat (request .getFirstHeader (HttpHeaders .CONTENT_TYPE ).getValue ()).isEqualTo (APPLICATION_JSON );
158203 assertThat (entity .isRepeatable ()).isFalse ();
159204 assertThat (entity .getContentLength ()).isEqualTo (-1 );
205+ assertThat (entity .getContentType ().getValue ()).isEqualTo (APPLICATION_X_TAR );
160206 assertThat (entity .isStreaming ()).isTrue ();
161207 assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (entity ::getContent );
162- assertThat (writeToString (entity )).isEqualTo ("test" );
208+ assertThat (writeToString (entity )).isEqualTo (content );
163209 assertThat (response .getContent ()).isSameAs (this .content );
164210 }
165211
0 commit comments