Skip to content

Commit 2e953c8

Browse files
committed
refactor(tests): improve notification assertions in HttpServletSseServerTransportProviderIntegrationTests
Replace index-based assertions with content-based lookups using a notification map. This change makes the tests more resilient by removing the dependency on notification order, which is important for asynchronous messaging tests. Signed-off-by: Christian Tzolov <[email protected]>
1 parent 63724f1 commit 2e953c8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

mcp/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProviderIntegrationTests.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010
import java.util.concurrent.atomic.AtomicReference;
1111
import java.util.function.Function;
12+
import java.util.stream.Collectors;
1213

1314
import com.fasterxml.jackson.databind.ObjectMapper;
1415
import io.modelcontextprotocol.client.McpClient;
@@ -575,20 +576,24 @@ void testLoggingNotification() {
575576
// Should have received 3 notifications (1 NOTICE and 2 ERROR)
576577
assertThat(receivedNotifications).hasSize(3);
577578

579+
Map<String, McpSchema.LoggingMessageNotification> notificationMap = receivedNotifications.stream()
580+
.collect(Collectors.toMap(n -> n.data(), n -> n));
581+
578582
// 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");
582586

583587
// 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");
587591

588592
// 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");
592597
});
593598
}
594599
mcpServer.close();

0 commit comments

Comments
 (0)