|
10 | 10 | import java.util.concurrent.ConcurrentHashMap;
|
11 | 11 | import java.util.concurrent.atomic.AtomicReference;
|
12 | 12 | import java.util.function.Function;
|
| 13 | +import java.util.stream.Collectors; |
13 | 14 |
|
14 | 15 | import com.fasterxml.jackson.databind.ObjectMapper;
|
15 | 16 | import io.modelcontextprotocol.client.McpClient;
|
@@ -596,20 +597,24 @@ void testLoggingNotification(String clientType) {
|
596 | 597 | // Should have received 3 notifications (1 NOTICE and 2 ERROR)
|
597 | 598 | assertThat(receivedNotifications).hasSize(3);
|
598 | 599 |
|
| 600 | + Map<String, McpSchema.LoggingMessageNotification> notificationMap = receivedNotifications.stream() |
| 601 | + .collect(Collectors.toMap(n -> n.data(), n -> n)); |
| 602 | + |
599 | 603 | // First notification should be NOTICE level
|
600 |
| - assertThat(receivedNotifications.get(0).level()).isEqualTo(McpSchema.LoggingLevel.NOTICE); |
601 |
| - assertThat(receivedNotifications.get(0).logger()).isEqualTo("test-logger"); |
602 |
| - assertThat(receivedNotifications.get(0).data()).isEqualTo("Notice message"); |
| 604 | + assertThat(notificationMap.get("Notice message").level()).isEqualTo(McpSchema.LoggingLevel.NOTICE); |
| 605 | + assertThat(notificationMap.get("Notice message").logger()).isEqualTo("test-logger"); |
| 606 | + assertThat(notificationMap.get("Notice message").data()).isEqualTo("Notice message"); |
603 | 607 |
|
604 | 608 | // Second notification should be ERROR level
|
605 |
| - assertThat(receivedNotifications.get(1).level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
606 |
| - assertThat(receivedNotifications.get(1).logger()).isEqualTo("test-logger"); |
607 |
| - assertThat(receivedNotifications.get(1).data()).isEqualTo("Error message"); |
| 609 | + assertThat(notificationMap.get("Error message").level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
| 610 | + assertThat(notificationMap.get("Error message").logger()).isEqualTo("test-logger"); |
| 611 | + assertThat(notificationMap.get("Error message").data()).isEqualTo("Error message"); |
608 | 612 |
|
609 | 613 | // Third notification should be ERROR level
|
610 |
| - assertThat(receivedNotifications.get(2).level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
611 |
| - assertThat(receivedNotifications.get(2).logger()).isEqualTo("test-logger"); |
612 |
| - assertThat(receivedNotifications.get(2).data()).isEqualTo("Another error message"); |
| 614 | + assertThat(notificationMap.get("Another error message").level()) |
| 615 | + .isEqualTo(McpSchema.LoggingLevel.ERROR); |
| 616 | + assertThat(notificationMap.get("Another error message").logger()).isEqualTo("test-logger"); |
| 617 | + assertThat(notificationMap.get("Another error message").data()).isEqualTo("Another error message"); |
613 | 618 | });
|
614 | 619 | }
|
615 | 620 | mcpServer.close();
|
|
0 commit comments