|
25 | 25 | import java.util.Optional; |
26 | 26 | import java.util.concurrent.ConcurrentHashMap; |
27 | 27 | import java.util.concurrent.ConcurrentMap; |
| 28 | +import okhttp3.MediaType; |
| 29 | +import okhttp3.ResponseBody; |
28 | 30 | import org.junit.Before; |
29 | 31 | import org.junit.Test; |
30 | 32 | import org.junit.runner.RunWith; |
|
37 | 39 | public class VertexAiSessionServiceTest { |
38 | 40 |
|
39 | 41 | private static final ObjectMapper mapper = JsonBaseModel.getMapper(); |
| 42 | + private static final MediaType JSON_MEDIA_TYPE = |
| 43 | + MediaType.parse("application/json; charset=utf-8"); |
| 44 | + |
| 45 | + private static ApiResponse apiResponseJson(String json) { |
| 46 | + return new ApiResponse() { |
| 47 | + @Override |
| 48 | + public ResponseBody getResponseBody() { |
| 49 | + return ResponseBody.create(JSON_MEDIA_TYPE, json); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void close() {} |
| 54 | + }; |
| 55 | + } |
40 | 56 |
|
41 | 57 | private static final String MOCK_SESSION_STRING_1 = |
42 | 58 | """ |
@@ -319,6 +335,24 @@ public void listSessions_empty() { |
319 | 335 | .isEmpty(); |
320 | 336 | } |
321 | 337 |
|
| 338 | + @Test |
| 339 | + public void listSessions_missingSessionsField_returnsEmpty() { |
| 340 | + when(mockApiClient.request("GET", "reasoningEngines/123/sessions?filter=user_id=userX", "")) |
| 341 | + .thenReturn(apiResponseJson("{}")); |
| 342 | + |
| 343 | + assertThat(vertexAiSessionService.listSessions("123", "userX").blockingGet().sessions()) |
| 344 | + .isEmpty(); |
| 345 | + } |
| 346 | + |
| 347 | + @Test |
| 348 | + public void listSessions_nullSessionsField_returnsEmpty() { |
| 349 | + when(mockApiClient.request("GET", "reasoningEngines/123/sessions?filter=user_id=userY", "")) |
| 350 | + .thenReturn(apiResponseJson("{\"sessions\": null}")); |
| 351 | + |
| 352 | + assertThat(vertexAiSessionService.listSessions("123", "userY").blockingGet().sessions()) |
| 353 | + .isEmpty(); |
| 354 | + } |
| 355 | + |
322 | 356 | @Test |
323 | 357 | public void listEvents_empty() { |
324 | 358 | assertThat(vertexAiSessionService.listEvents("789", "user1", "3").blockingGet().events()) |
|
0 commit comments