@@ -60,29 +60,11 @@ void testSuccessfulInitialization() {
6060 // Verify client is not initialized initially
6161 assertThat (asyncMcpClient .isInitialized ()).isFalse ();
6262
63- // Create mock server response
64- McpSchema .ServerCapabilities mockServerCapabilities = McpSchema .ServerCapabilities .builder ()
65- .tools (true )
66- .resources (true , true ) // Enable both resources and resource templates
67- .build ();
68- McpSchema .Implementation mockServerInfo = new McpSchema .Implementation ("test-server" , "1.0.0" );
69- McpSchema .InitializeResult mockInitResult = new McpSchema .InitializeResult (McpSchema .LATEST_PROTOCOL_VERSION ,
70- mockServerCapabilities , mockServerInfo , "Test instructions" );
71-
7263 // Start initialization with reactive handling
73- InitializeResult result = asyncMcpClient .initialize ().doOnSubscribe (subscription -> {
74- // Run in a separate reactive context to avoid blocking the main subscription
75- Mono .fromRunnable (() -> {
76- McpSchema .JSONRPCRequest initRequest = transport .getLastSentMessageAsRequest ();
77- assertThat (initRequest .method ()).isEqualTo (McpSchema .METHOD_INITIALIZE );
64+ InitializeResult result = initialization (asyncMcpClient , transport );
7865
79- // Send mock server response
80- McpSchema .JSONRPCResponse initResponse = new McpSchema .JSONRPCResponse (McpSchema .JSONRPC_VERSION ,
81- initRequest .id (), mockInitResult , null );
82- transport .simulateIncomingMessage (initResponse );
83- // latch.countDown();
84- }).subscribeOn (reactor .core .scheduler .Schedulers .boundedElastic ()).subscribe ();
85- }).block ();
66+ // Verify client state after initialization
67+ assertThat (asyncMcpClient .isInitialized ()).isTrue ();
8668
8769 // Verify initialized notification was sent
8870 McpSchema .JSONRPCMessage notificationMessage = transport .getLastSentMessage ();
@@ -93,15 +75,10 @@ void testSuccessfulInitialization() {
9375 // Verify initialization result
9476 assertThat (result ).isNotNull ();
9577 assertThat (result .protocolVersion ()).isEqualTo (McpSchema .LATEST_PROTOCOL_VERSION );
96- assertThat (result .capabilities ()).isEqualTo (mockServerCapabilities );
97- assertThat (result .serverInfo ()).isEqualTo (mockServerInfo );
78+ assertThat (result .capabilities ()).isEqualTo (asyncMcpClient . getServerCapabilities () );
79+ assertThat (result .serverInfo ()).isEqualTo (asyncMcpClient . getServerInfo () );
9880 assertThat (result .instructions ()).isEqualTo ("Test instructions" );
9981
100- // Verify client state after initialization
101- assertThat (asyncMcpClient .isInitialized ()).isTrue ();
102- assertThat (asyncMcpClient .getServerCapabilities ()).isEqualTo (mockServerCapabilities );
103- assertThat (asyncMcpClient .getServerInfo ()).isEqualTo (mockServerInfo );
104-
10582 asyncMcpClient .closeGracefully ();
10683 }
10784
0 commit comments