|
9 | 9 | import java.util.Map; |
10 | 10 | import java.util.concurrent.atomic.AtomicReference; |
11 | 11 | import java.util.function.Function; |
| 12 | +import java.util.stream.Collectors; |
12 | 13 |
|
13 | 14 | import com.fasterxml.jackson.databind.ObjectMapper; |
14 | 15 | import io.modelcontextprotocol.client.McpClient; |
@@ -575,20 +576,24 @@ void testLoggingNotification() { |
575 | 576 | // Should have received 3 notifications (1 NOTICE and 2 ERROR) |
576 | 577 | assertThat(receivedNotifications).hasSize(3); |
577 | 578 |
|
| 579 | + Map<String, McpSchema.LoggingMessageNotification> notificationMap = receivedNotifications.stream() |
| 580 | + .collect(Collectors.toMap(n -> n.data(), n -> n)); |
| 581 | + |
578 | 582 | // First notification should be NOTICE level |
579 | | - assertThat(receivedNotifications.get(0).level()).isEqualTo(McpSchema.LoggingLevel.NOTICE); |
580 | | - assertThat(receivedNotifications.get(0).logger()).isEqualTo("test-logger"); |
581 | | - assertThat(receivedNotifications.get(0).data()).isEqualTo("Notice message"); |
| 583 | + assertThat(notificationMap.get("Notice message").level()).isEqualTo(McpSchema.LoggingLevel.NOTICE); |
| 584 | + assertThat(notificationMap.get("Notice message").logger()).isEqualTo("test-logger"); |
| 585 | + assertThat(notificationMap.get("Notice message").data()).isEqualTo("Notice message"); |
582 | 586 |
|
583 | 587 | // Second notification should be ERROR level |
584 | | - assertThat(receivedNotifications.get(1).level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
585 | | - assertThat(receivedNotifications.get(1).logger()).isEqualTo("test-logger"); |
586 | | - assertThat(receivedNotifications.get(1).data()).isEqualTo("Error message"); |
| 588 | + assertThat(notificationMap.get("Error message").level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
| 589 | + assertThat(notificationMap.get("Error message").logger()).isEqualTo("test-logger"); |
| 590 | + assertThat(notificationMap.get("Error message").data()).isEqualTo("Error message"); |
587 | 591 |
|
588 | 592 | // Third notification should be ERROR level |
589 | | - assertThat(receivedNotifications.get(2).level()).isEqualTo(McpSchema.LoggingLevel.ERROR); |
590 | | - assertThat(receivedNotifications.get(2).logger()).isEqualTo("test-logger"); |
591 | | - assertThat(receivedNotifications.get(2).data()).isEqualTo("Another error message"); |
| 593 | + assertThat(notificationMap.get("Another error message").level()) |
| 594 | + .isEqualTo(McpSchema.LoggingLevel.ERROR); |
| 595 | + assertThat(notificationMap.get("Another error message").logger()).isEqualTo("test-logger"); |
| 596 | + assertThat(notificationMap.get("Another error message").data()).isEqualTo("Another error message"); |
592 | 597 | }); |
593 | 598 | } |
594 | 599 | mcpServer.close(); |
|
0 commit comments