Skip to content

Commit 63724f1

Browse files
committed
refactor(tests): improve notification assertions in WebFluxSseIntegrationTests
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 c88ac93 commit 63724f1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/WebFluxSseIntegrationTests.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.concurrent.ConcurrentHashMap;
1111
import java.util.concurrent.atomic.AtomicReference;
1212
import java.util.function.Function;
13+
import java.util.stream.Collectors;
1314

1415
import com.fasterxml.jackson.databind.ObjectMapper;
1516
import io.modelcontextprotocol.client.McpClient;
@@ -596,20 +597,24 @@ void testLoggingNotification(String clientType) {
596597
// Should have received 3 notifications (1 NOTICE and 2 ERROR)
597598
assertThat(receivedNotifications).hasSize(3);
598599

600+
Map<String, McpSchema.LoggingMessageNotification> notificationMap = receivedNotifications.stream()
601+
.collect(Collectors.toMap(n -> n.data(), n -> n));
602+
599603
// 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");
603607

604608
// 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");
608612

609613
// 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");
613618
});
614619
}
615620
mcpServer.close();

0 commit comments

Comments
 (0)