|
4 | 4 | import static org.mockito.ArgumentMatchers.anyString; |
5 | 5 |
|
6 | 6 | import com.symphony.bdk.http.api.ApiClient; |
| 7 | +import com.symphony.bdk.http.api.ApiClientBodyPart; |
7 | 8 | import com.symphony.bdk.http.api.ApiException; |
8 | 9 | import com.symphony.bdk.http.api.ApiResponse; |
9 | 10 | import com.symphony.bdk.http.api.Pair; |
|
24 | 25 | import org.mockserver.model.ParameterBody; |
25 | 26 | import org.springframework.http.MediaType; |
26 | 27 |
|
| 28 | +import java.io.ByteArrayInputStream; |
27 | 29 | import java.io.FileOutputStream; |
28 | 30 | import java.io.IOException; |
| 31 | +import java.io.InputStream; |
29 | 32 | import java.nio.charset.StandardCharsets; |
30 | 33 | import java.nio.file.Path; |
31 | 34 | import java.util.ArrayList; |
@@ -286,6 +289,34 @@ void testInvokeApiWithFormValueTest(final BdkMockServer mockServer, @TempDir Pat |
286 | 289 | assertEquals("success", response.getData().getMessage()); |
287 | 290 | } |
288 | 291 |
|
| 292 | + @Test |
| 293 | + void testInvokeApiWithApiClientBodyPart(final BdkMockServer mockServer) throws ApiException { |
| 294 | + mockServer.onRequestModifierWithResponse(200, |
| 295 | + httpRequest -> httpRequest |
| 296 | + .withMethod("POST") |
| 297 | + .withPath("/test-api") |
| 298 | + .withHeader(Header.header("sessionToken", "test-token")) |
| 299 | + .withBody(anyString()) |
| 300 | + .withCookie("cookie", "test-cookie"), |
| 301 | + httpResponse -> httpResponse |
| 302 | + .withBody("{\"code\": 200, \"message\": \"success\"}")); |
| 303 | + Map<String, Object> formParams = new HashMap<>(); |
| 304 | + |
| 305 | + formParams.put("attachment", Collections.singletonList(new ApiClientBodyPart(new ByteArrayInputStream("test".getBytes()), "filename"))); |
| 306 | + |
| 307 | + |
| 308 | + ApiResponse<Response> response = |
| 309 | + this.apiClient.invokeAPI("/test-api", "POST", null, null, |
| 310 | + Collections.singletonMap("sessionToken", "test-token"), |
| 311 | + Collections.singletonMap("cookie", "test-cookie"), formParams, null, MediaType.MULTIPART_FORM_DATA_VALUE, |
| 312 | + new String[] {}, |
| 313 | + new TypeReference<Response>() {}); |
| 314 | + |
| 315 | + |
| 316 | + assertEquals(200, response.getData().getCode()); |
| 317 | + assertEquals("success", response.getData().getMessage()); |
| 318 | + } |
| 319 | + |
289 | 320 | @Test |
290 | 321 | void shouldClearTraceIdIfNotSet(final BdkMockServer mockServer) throws ApiException { |
291 | 322 | mockServer.onRequestModifierWithResponse(200, |
|
0 commit comments