Skip to content

Commit 42b172e

Browse files
Add unit tests
1 parent 0352627 commit 42b172e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

symphony-bdk-http/symphony-bdk-http-webclient/src/test/java/com/symphony/bdk/http/webclient/ApiClientWebClientTest.java

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.mockito.ArgumentMatchers.anyString;
55

66
import com.symphony.bdk.http.api.ApiClient;
7+
import com.symphony.bdk.http.api.ApiClientBodyPart;
78
import com.symphony.bdk.http.api.ApiException;
89
import com.symphony.bdk.http.api.ApiResponse;
910
import com.symphony.bdk.http.api.Pair;
@@ -24,8 +25,10 @@
2425
import org.mockserver.model.ParameterBody;
2526
import org.springframework.http.MediaType;
2627

28+
import java.io.ByteArrayInputStream;
2729
import java.io.FileOutputStream;
2830
import java.io.IOException;
31+
import java.io.InputStream;
2932
import java.nio.charset.StandardCharsets;
3033
import java.nio.file.Path;
3134
import java.util.ArrayList;
@@ -286,6 +289,34 @@ void testInvokeApiWithFormValueTest(final BdkMockServer mockServer, @TempDir Pat
286289
assertEquals("success", response.getData().getMessage());
287290
}
288291

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+
289320
@Test
290321
void shouldClearTraceIdIfNotSet(final BdkMockServer mockServer) throws ApiException {
291322
mockServer.onRequestModifierWithResponse(200,

0 commit comments

Comments
 (0)