3535import org .junit .jupiter .api .BeforeEach ;
3636import org .junit .jupiter .params .ParameterizedTest ;
3737import org .junit .jupiter .params .provider .ValueSource ;
38- import reactor .core .publisher .Mono ;
3938import reactor .netty .DisposableServer ;
4039import reactor .netty .http .server .HttpServer ;
41- import reactor .test .StepVerifier ;
4240
4341import org .springframework .http .server .reactive .HttpHandler ;
4442import org .springframework .http .server .reactive .ReactorHttpHandlerAdapter ;
4745import org .springframework .web .reactive .function .server .RouterFunctions ;
4846
4947import static org .assertj .core .api .Assertions .assertThat ;
48+ import static org .assertj .core .api .Assertions .assertWith ;
5049import static org .awaitility .Awaitility .await ;
5150import static org .mockito .Mockito .mock ;
5251
@@ -106,12 +105,9 @@ void testCreateMessageWithoutSamplingCapabilities(String clientType) {
106105 var clientBuilder = clientBuilders .get (clientType );
107106
108107 McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
109- new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ), (exchange , request ) -> {
110-
111- exchange .createMessage (mock (McpSchema .CreateMessageRequest .class )).block ();
112-
113- return Mono .just (mock (CallToolResult .class ));
114- });
108+ new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ),
109+ (exchange , request ) -> exchange .createMessage (mock (CreateMessageRequest .class ))
110+ .thenReturn (mock (CallToolResult .class )));
115111
116112 var server = McpServer .async (mcpServerTransportProvider ).serverInfo ("test-server" , "1.0.0" ).tools (tool ).build ();
117113
@@ -148,6 +144,8 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
148144 CallToolResult callResponse = new McpSchema .CallToolResult (List .of (new McpSchema .TextContent ("CALL RESPONSE" )),
149145 null );
150146
147+ AtomicReference <CreateMessageResult > samplingResult = new AtomicReference <>();
148+
151149 McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
152150 new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ), (exchange , request ) -> {
153151
@@ -162,16 +160,9 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
162160 .build ())
163161 .build ();
164162
165- StepVerifier .create (exchange .createMessage (craeteMessageRequest )).consumeNextWith (result -> {
166- assertThat (result ).isNotNull ();
167- assertThat (result .role ()).isEqualTo (Role .USER );
168- assertThat (result .content ()).isInstanceOf (McpSchema .TextContent .class );
169- assertThat (((McpSchema .TextContent ) result .content ()).text ()).isEqualTo ("Test message" );
170- assertThat (result .model ()).isEqualTo ("MockModelName" );
171- assertThat (result .stopReason ()).isEqualTo (CreateMessageResult .StopReason .STOP_SEQUENCE );
172- }).verifyComplete ();
173-
174- return Mono .just (callResponse );
163+ return exchange .createMessage (craeteMessageRequest )
164+ .doOnNext (samplingResult ::set )
165+ .thenReturn (callResponse );
175166 });
176167
177168 var mcpServer = McpServer .async (mcpServerTransportProvider )
@@ -191,8 +182,17 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
191182
192183 assertThat (response ).isNotNull ();
193184 assertThat (response ).isEqualTo (callResponse );
185+
186+ assertWith (samplingResult .get (), result -> {
187+ assertThat (result ).isNotNull ();
188+ assertThat (result .role ()).isEqualTo (Role .USER );
189+ assertThat (result .content ()).isInstanceOf (McpSchema .TextContent .class );
190+ assertThat (((McpSchema .TextContent ) result .content ()).text ()).isEqualTo ("Test message" );
191+ assertThat (result .model ()).isEqualTo ("MockModelName" );
192+ assertThat (result .stopReason ()).isEqualTo (CreateMessageResult .StopReason .STOP_SEQUENCE );
193+ });
194194 }
195- mcpServer .close ();
195+ mcpServer .closeGracefully (). block ();
196196 }
197197
198198 // ---------------------------------------
0 commit comments