Skip to content

Commit 23accdf

Browse files
committed
Change @ParameterizedTest -> @test in HttpServletStatelessServerTransport
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
1 parent 088017c commit 23accdf

1 file changed

Lines changed: 33 additions & 78 deletions

File tree

mcp-test/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java

Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.time.Duration;
88
import java.util.List;
99
import java.util.Map;
10-
import java.util.concurrent.ConcurrentHashMap;
1110
import java.util.concurrent.atomic.AtomicReference;
1211
import java.util.function.BiFunction;
1312

@@ -42,8 +41,6 @@
4241
import org.junit.jupiter.api.BeforeEach;
4342
import org.junit.jupiter.api.Test;
4443
import org.junit.jupiter.api.Timeout;
45-
import org.junit.jupiter.params.ParameterizedTest;
46-
import org.junit.jupiter.params.provider.ValueSource;
4744

4845
import org.springframework.mock.web.MockHttpServletRequest;
4946
import org.springframework.mock.web.MockHttpServletResponse;
@@ -69,7 +66,12 @@ class HttpServletStatelessIntegrationTests {
6966

7067
private HttpServletStatelessServerTransport mcpStatelessServerTransport;
7168

72-
ConcurrentHashMap<String, McpClient.SyncSpec> clientBuilders = new ConcurrentHashMap<>();
69+
private final McpClient.SyncSpec clientBuilder = McpClient
70+
.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
71+
.endpoint(CUSTOM_MESSAGE_ENDPOINT)
72+
.build())
73+
.initializationTimeout(Duration.ofHours(10))
74+
.requestTimeout(Duration.ofHours(10));
7375

7476
private Tomcat tomcat;
7577

@@ -87,12 +89,6 @@ public void before() {
8789
catch (Exception e) {
8890
throw new RuntimeException("Failed to start Tomcat", e);
8991
}
90-
91-
clientBuilders
92-
.put("httpclient",
93-
McpClient.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
94-
.endpoint(CUSTOM_MESSAGE_ENDPOINT)
95-
.build()).initializationTimeout(Duration.ofHours(10)).requestTimeout(Duration.ofHours(10)));
9692
}
9793

9894
@AfterEach
@@ -114,12 +110,8 @@ public void after() {
114110
// ---------------------------------------
115111
// Tools Tests
116112
// ---------------------------------------
117-
@ParameterizedTest(name = "{0} : {displayName} ")
118-
@ValueSource(strings = { "httpclient" })
119-
void testToolCallSuccess(String clientType) {
120-
121-
var clientBuilder = clientBuilders.get(clientType);
122-
113+
@Test
114+
void testToolCallSuccess() {
123115
var callResponse = CallToolResult.builder()
124116
.content(List.of(McpSchema.TextContent.builder("CALL RESPONSE").build()))
125117
.isError(false)
@@ -160,12 +152,8 @@ void testToolCallSuccess(String clientType) {
160152
}
161153
}
162154

163-
@ParameterizedTest(name = "{0} : {displayName} ")
164-
@ValueSource(strings = { "httpclient" })
165-
void testInitialize(String clientType) {
166-
167-
var clientBuilder = clientBuilders.get(clientType);
168-
155+
@Test
156+
void testInitialize() {
169157
var mcpServer = McpServer.sync(mcpStatelessServerTransport).build();
170158

171159
try (var mcpClient = clientBuilder.build()) {
@@ -180,11 +168,8 @@ void testInitialize(String clientType) {
180168
// ---------------------------------------
181169
// Completion Tests
182170
// ---------------------------------------
183-
@ParameterizedTest(name = "{0} : Completion call")
184-
@ValueSource(strings = { "httpclient" })
185-
void testCompletionShouldReturnExpectedSuggestions(String clientType) {
186-
var clientBuilder = clientBuilders.get(clientType);
187-
171+
@Test
172+
void testCompletionShouldReturnExpectedSuggestions() {
188173
var expectedValues = List.of("python", "pytorch", "pyside");
189174
var completionResponse = new CompleteResult(new CompleteResult.CompleteCompletion(expectedValues, 10, // total
190175
true // hasMore
@@ -235,11 +220,8 @@ void testCompletionShouldReturnExpectedSuggestions(String clientType) {
235220
}
236221
}
237222

238-
@ParameterizedTest(name = "{0} : Completion call without matching handler")
239-
@ValueSource(strings = { "httpclient" })
240-
void testCompletionWithoutMatchingHandlerReturnsEmptyResult(String clientType) {
241-
var clientBuilder = clientBuilders.get(clientType);
242-
223+
@Test
224+
void testCompletionWithoutMatchingHandlerReturnsEmptyResult() {
243225
BiFunction<McpTransportContext, CompleteRequest, CompleteResult> completionHandler = (transportContext,
244226
request) -> new CompleteResult(new CompleteResult.CompleteCompletion(List.of("java"), 1, false));
245227

@@ -288,11 +270,8 @@ void testCompletionWithoutMatchingHandlerReturnsEmptyResult(String clientType) {
288270
}
289271
}
290272

291-
@ParameterizedTest(name = "{0} : Resource template completion call without matching handler")
292-
@ValueSource(strings = { "httpclient" })
293-
void testResourceTemplateCompletionWithoutMatchingHandlerReturnsEmptyResult(String clientType) {
294-
var clientBuilder = clientBuilders.get(clientType);
295-
273+
@Test
274+
void testResourceTemplateCompletionWithoutMatchingHandlerReturnsEmptyResult() {
296275
BiFunction<McpTransportContext, CompleteRequest, CompleteResult> completionHandler = (transportContext,
297276
request) -> new CompleteResult(new CompleteResult.CompleteCompletion(List.of("java"), 1, false));
298277

@@ -339,11 +318,8 @@ void testResourceTemplateCompletionWithoutMatchingHandlerReturnsEmptyResult(Stri
339318
}
340319
}
341320

342-
@ParameterizedTest(name = "{0} : Completion call for non-existent prompt")
343-
@ValueSource(strings = { "httpclient" })
344-
void testCompletionForNonExistentPromptReturnsInvalidParams(String clientType) {
345-
var clientBuilder = clientBuilders.get(clientType);
346-
321+
@Test
322+
void testCompletionForNonExistentPromptReturnsInvalidParams() {
347323
var mcpServer = McpServer.sync(mcpStatelessServerTransport)
348324
.capabilities(ServerCapabilities.builder().completions().build())
349325
.build();
@@ -360,18 +336,15 @@ void testCompletionForNonExistentPromptReturnsInvalidParams(String clientType) {
360336
.asInstanceOf(type(McpError.class))
361337
.extracting(McpError::getJsonRpcError)
362338
.extracting(McpSchema.JSONRPCResponse.JSONRPCError::code)
363-
.isEqualTo(McpSchema.ErrorCodes.RESOURCE_NOT_FOUND);
339+
.isEqualTo(ErrorCodes.INVALID_PARAMS);
364340
}
365341
finally {
366342
mcpServer.close();
367343
}
368344
}
369345

370-
@ParameterizedTest(name = "{0} : Completion call for non-existent resource")
371-
@ValueSource(strings = { "httpclient" })
372-
void testCompletionForNonExistentResourceReturnsResourceNotFound(String clientType) {
373-
var clientBuilder = clientBuilders.get(clientType);
374-
346+
@Test
347+
void testCompletionForNonExistentResourceReturnsResourceNotFound() {
375348
var mcpServer = McpServer.sync(mcpStatelessServerTransport)
376349
.capabilities(ServerCapabilities.builder().completions().build())
377350
.build();
@@ -399,11 +372,8 @@ void testCompletionForNonExistentResourceReturnsResourceNotFound(String clientTy
399372
// ---------------------------------------
400373
// Tool Structured Output Schema Tests
401374
// ---------------------------------------
402-
@ParameterizedTest(name = "{0} : {displayName} ")
403-
@ValueSource(strings = { "httpclient" })
404-
void testStructuredOutputValidationSuccess(String clientType) {
405-
var clientBuilder = clientBuilders.get(clientType);
406-
375+
@Test
376+
void testStructuredOutputValidationSuccess() {
407377
// Create a tool with output schema
408378
Map<String, Object> outputSchema = Map.of(
409379
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
@@ -468,11 +438,8 @@ void testStructuredOutputValidationSuccess(String clientType) {
468438
}
469439
}
470440

471-
@ParameterizedTest(name = "{0} : {displayName} ")
472-
@ValueSource(strings = { "httpclient" })
473-
void testStructuredOutputOfObjectArrayValidationSuccess(String clientType) {
474-
var clientBuilder = clientBuilders.get(clientType);
475-
441+
@Test
442+
void testStructuredOutputOfObjectArrayValidationSuccess() {
476443
// Create a tool with output schema that returns an array of objects
477444
Map<String, Object> outputSchema = Map
478445
.of( // @formatter:off
@@ -529,11 +496,8 @@ void testStructuredOutputOfObjectArrayValidationSuccess(String clientType) {
529496
}
530497
}
531498

532-
@ParameterizedTest(name = "{0} : {displayName} ")
533-
@ValueSource(strings = { "httpclient" })
534-
void testStructuredOutputWithInHandlerError(String clientType) {
535-
var clientBuilder = clientBuilders.get(clientType);
536-
499+
@Test
500+
void testStructuredOutputWithInHandlerError() {
537501
// Create a tool with output schema
538502
Map<String, Object> outputSchema = Map.of(
539503
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
@@ -587,11 +551,8 @@ void testStructuredOutputWithInHandlerError(String clientType) {
587551
}
588552
}
589553

590-
@ParameterizedTest(name = "{0} : {displayName} ")
591-
@ValueSource(strings = { "httpclient" })
592-
void testStructuredOutputValidationFailure(String clientType) {
593-
var clientBuilder = clientBuilders.get(clientType);
594-
554+
@Test
555+
void testStructuredOutputValidationFailure() {
595556
// Create a tool with output schema
596557
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
597558
Map.of("result", Map.of("type", "number"), "operation", Map.of("type", "string")), "required",
@@ -639,11 +600,8 @@ void testStructuredOutputValidationFailure(String clientType) {
639600
}
640601
}
641602

642-
@ParameterizedTest(name = "{0} : {displayName} ")
643-
@ValueSource(strings = { "httpclient" })
644-
void testStructuredOutputMissingStructuredContent(String clientType) {
645-
var clientBuilder = clientBuilders.get(clientType);
646-
603+
@Test
604+
void testStructuredOutputMissingStructuredContent() {
647605
// Create a tool with output schema
648606
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
649607
Map.of("result", Map.of("type", "number")), "required", List.of("result"));
@@ -688,11 +646,8 @@ void testStructuredOutputMissingStructuredContent(String clientType) {
688646
}
689647
}
690648

691-
@ParameterizedTest(name = "{0} : {displayName} ")
692-
@ValueSource(strings = { "httpclient" })
693-
void testStructuredOutputRuntimeToolAddition(String clientType) {
694-
var clientBuilder = clientBuilders.get(clientType);
695-
649+
@Test
650+
void testStructuredOutputRuntimeToolAddition() {
696651
// Start server without tools
697652
var mcpServer = McpServer.sync(mcpStatelessServerTransport)
698653
.serverInfo("test-server", "1.0.0")

0 commit comments

Comments
 (0)