Skip to content

Commit 8ac7eae

Browse files
authored
refactor: standardize test parameterization and fix package naming (#556)
- Replace @valuesource with @MethodSource for parameterized tests - Add clientsForTesting() methods to provide test arguments consistently - Remove hardcoded Spring-related labels from framework-agnostic mcp-test module - Move mcp-test's utility classes from io.modelcontextprotocol.utils to io.modelcontextprotocol.util Signed-off-by: Christian Tzolov <[email protected]>
1 parent 1499df2 commit 8ac7eae

19 files changed

+134
-76
lines changed

mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import io.modelcontextprotocol.util.Utils;
4747
import net.javacrumbs.jsonunit.core.Option;
4848
import org.junit.jupiter.params.ParameterizedTest;
49+
import org.junit.jupiter.params.provider.MethodSource;
4950
import org.junit.jupiter.params.provider.ValueSource;
5051
import reactor.core.publisher.Mono;
5152
import reactor.test.StepVerifier;
@@ -70,15 +71,14 @@ public abstract class AbstractMcpClientServerIntegrationTests {
7071
abstract protected McpServer.SyncSpecification<?> prepareSyncServerBuilder();
7172

7273
@ParameterizedTest(name = "{0} : {displayName} ")
73-
@ValueSource(strings = { "httpclient" })
74+
@MethodSource("clientsForTesting")
7475
void simple(String clientType) {
7576

7677
var clientBuilder = clientBuilders.get(clientType);
7778

7879
var server = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0")
7980
.requestTimeout(Duration.ofSeconds(1000))
8081
.build();
81-
8282
try (
8383
// Create client without sampling capabilities
8484
var client = clientBuilder.clientInfo(new McpSchema.Implementation("Sample " + "client", "0.0.0"))
@@ -97,7 +97,7 @@ void simple(String clientType) {
9797
// Sampling Tests
9898
// ---------------------------------------
9999
@ParameterizedTest(name = "{0} : {displayName} ")
100-
@ValueSource(strings = { "httpclient" })
100+
@MethodSource("clientsForTesting")
101101
void testCreateMessageWithoutSamplingCapabilities(String clientType) {
102102

103103
var clientBuilder = clientBuilders.get(clientType);
@@ -133,7 +133,7 @@ void testCreateMessageWithoutSamplingCapabilities(String clientType) {
133133
}
134134

135135
@ParameterizedTest(name = "{0} : {displayName} ")
136-
@ValueSource(strings = { "httpclient" })
136+
@MethodSource("clientsForTesting")
137137
void testCreateMessageSuccess(String clientType) {
138138

139139
var clientBuilder = clientBuilders.get(clientType);
@@ -202,7 +202,7 @@ void testCreateMessageSuccess(String clientType) {
202202
}
203203

204204
@ParameterizedTest(name = "{0} : {displayName} ")
205-
@ValueSource(strings = { "httpclient" })
205+
@MethodSource("clientsForTesting")
206206
void testCreateMessageWithRequestTimeoutSuccess(String clientType) throws InterruptedException {
207207

208208
// Client
@@ -282,7 +282,7 @@ void testCreateMessageWithRequestTimeoutSuccess(String clientType) throws Interr
282282
}
283283

284284
@ParameterizedTest(name = "{0} : {displayName} ")
285-
@ValueSource(strings = { "httpclient" })
285+
@MethodSource("clientsForTesting")
286286
void testCreateMessageWithRequestTimeoutFail(String clientType) throws InterruptedException {
287287

288288
var clientBuilder = clientBuilders.get(clientType);
@@ -348,7 +348,7 @@ void testCreateMessageWithRequestTimeoutFail(String clientType) throws Interrupt
348348
// Elicitation Tests
349349
// ---------------------------------------
350350
@ParameterizedTest(name = "{0} : {displayName} ")
351-
@ValueSource(strings = { "httpclient" })
351+
@MethodSource("clientsForTesting")
352352
void testCreateElicitationWithoutElicitationCapabilities(String clientType) {
353353

354354
var clientBuilder = clientBuilders.get(clientType);
@@ -380,7 +380,7 @@ void testCreateElicitationWithoutElicitationCapabilities(String clientType) {
380380
}
381381

382382
@ParameterizedTest(name = "{0} : {displayName} ")
383-
@ValueSource(strings = { "httpclient" })
383+
@MethodSource("clientsForTesting")
384384
void testCreateElicitationSuccess(String clientType) {
385385

386386
var clientBuilder = clientBuilders.get(clientType);
@@ -437,7 +437,7 @@ void testCreateElicitationSuccess(String clientType) {
437437
}
438438

439439
@ParameterizedTest(name = "{0} : {displayName} ")
440-
@ValueSource(strings = { "httpclient" })
440+
@MethodSource("clientsForTesting")
441441
void testCreateElicitationWithRequestTimeoutSuccess(String clientType) {
442442

443443
var clientBuilder = clientBuilders.get(clientType);
@@ -498,7 +498,7 @@ void testCreateElicitationWithRequestTimeoutSuccess(String clientType) {
498498
}
499499

500500
@ParameterizedTest(name = "{0} : {displayName} ")
501-
@ValueSource(strings = { "httpclient" })
501+
@MethodSource("clientsForTesting")
502502
void testCreateElicitationWithRequestTimeoutFail(String clientType) {
503503

504504
var latch = new CountDownLatch(1);
@@ -569,7 +569,7 @@ void testCreateElicitationWithRequestTimeoutFail(String clientType) {
569569
// Roots Tests
570570
// ---------------------------------------
571571
@ParameterizedTest(name = "{0} : {displayName} ")
572-
@ValueSource(strings = { "httpclient" })
572+
@MethodSource("clientsForTesting")
573573
void testRootsSuccess(String clientType) {
574574
var clientBuilder = clientBuilders.get(clientType);
575575

@@ -617,7 +617,7 @@ void testRootsSuccess(String clientType) {
617617
}
618618

619619
@ParameterizedTest(name = "{0} : {displayName} ")
620-
@ValueSource(strings = { "httpclient" })
620+
@MethodSource("clientsForTesting")
621621
void testRootsWithoutCapability(String clientType) {
622622

623623
var clientBuilder = clientBuilders.get(clientType);
@@ -656,7 +656,7 @@ void testRootsWithoutCapability(String clientType) {
656656
}
657657

658658
@ParameterizedTest(name = "{0} : {displayName} ")
659-
@ValueSource(strings = { "httpclient" })
659+
@MethodSource("clientsForTesting")
660660
void testRootsNotificationWithEmptyRootsList(String clientType) {
661661

662662
var clientBuilder = clientBuilders.get(clientType);
@@ -686,7 +686,7 @@ void testRootsNotificationWithEmptyRootsList(String clientType) {
686686
}
687687

688688
@ParameterizedTest(name = "{0} : {displayName} ")
689-
@ValueSource(strings = { "httpclient" })
689+
@MethodSource("clientsForTesting")
690690
void testRootsWithMultipleHandlers(String clientType) {
691691

692692
var clientBuilder = clientBuilders.get(clientType);
@@ -720,7 +720,7 @@ void testRootsWithMultipleHandlers(String clientType) {
720720
}
721721

722722
@ParameterizedTest(name = "{0} : {displayName} ")
723-
@ValueSource(strings = { "httpclient" })
723+
@MethodSource("clientsForTesting")
724724
void testRootsServerCloseWithActiveSubscription(String clientType) {
725725

726726
var clientBuilder = clientBuilders.get(clientType);
@@ -755,7 +755,7 @@ void testRootsServerCloseWithActiveSubscription(String clientType) {
755755
// Tools Tests
756756
// ---------------------------------------
757757
@ParameterizedTest(name = "{0} : {displayName} ")
758-
@ValueSource(strings = { "httpclient" })
758+
@MethodSource("clientsForTesting")
759759
void testToolCallSuccess(String clientType) {
760760

761761
var clientBuilder = clientBuilders.get(clientType);
@@ -806,7 +806,7 @@ void testToolCallSuccess(String clientType) {
806806
}
807807

808808
@ParameterizedTest(name = "{0} : {displayName} ")
809-
@ValueSource(strings = { "httpclient" })
809+
@MethodSource("clientsForTesting")
810810
void testThrowingToolCallIsCaughtBeforeTimeout(String clientType) {
811811

812812
var clientBuilder = clientBuilders.get(clientType);
@@ -844,7 +844,7 @@ void testThrowingToolCallIsCaughtBeforeTimeout(String clientType) {
844844
}
845845

846846
@ParameterizedTest(name = "{0} : {displayName} ")
847-
@ValueSource(strings = { "httpclient" })
847+
@MethodSource("clientsForTesting")
848848
void testToolCallSuccessWithTranportContextExtraction(String clientType) {
849849

850850
var clientBuilder = clientBuilders.get(clientType);
@@ -901,7 +901,7 @@ void testToolCallSuccessWithTranportContextExtraction(String clientType) {
901901
}
902902

903903
@ParameterizedTest(name = "{0} : {displayName} ")
904-
@ValueSource(strings = { "httpclient" })
904+
@MethodSource("clientsForTesting")
905905
void testToolListChangeHandlingSuccess(String clientType) {
906906

907907
var clientBuilder = clientBuilders.get(clientType);
@@ -994,7 +994,7 @@ void testToolListChangeHandlingSuccess(String clientType) {
994994
}
995995

996996
@ParameterizedTest(name = "{0} : {displayName} ")
997-
@ValueSource(strings = { "httpclient" })
997+
@MethodSource("clientsForTesting")
998998
void testInitialize(String clientType) {
999999

10001000
var clientBuilder = clientBuilders.get(clientType);
@@ -1015,7 +1015,7 @@ void testInitialize(String clientType) {
10151015
// Logging Tests
10161016
// ---------------------------------------
10171017
@ParameterizedTest(name = "{0} : {displayName} ")
1018-
@ValueSource(strings = { "httpclient" })
1018+
@MethodSource("clientsForTesting")
10191019
void testLoggingNotification(String clientType) throws InterruptedException {
10201020
int expectedNotificationsCount = 3;
10211021
CountDownLatch latch = new CountDownLatch(expectedNotificationsCount);
@@ -1128,7 +1128,7 @@ void testLoggingNotification(String clientType) throws InterruptedException {
11281128
// Progress Tests
11291129
// ---------------------------------------
11301130
@ParameterizedTest(name = "{0} : {displayName} ")
1131-
@ValueSource(strings = { "httpclient" })
1131+
@MethodSource("clientsForTesting")
11321132
void testProgressNotification(String clientType) throws InterruptedException {
11331133
int expectedNotificationsCount = 4; // 3 notifications + 1 for another progress
11341134
// token
@@ -1234,7 +1234,7 @@ void testProgressNotification(String clientType) throws InterruptedException {
12341234
// Completion Tests
12351235
// ---------------------------------------
12361236
@ParameterizedTest(name = "{0} : Completion call")
1237-
@ValueSource(strings = { "httpclient" })
1237+
@MethodSource("clientsForTesting")
12381238
void testCompletionShouldReturnExpectedSuggestions(String clientType) {
12391239
var clientBuilder = clientBuilders.get(clientType);
12401240

@@ -1256,7 +1256,7 @@ void testCompletionShouldReturnExpectedSuggestions(String clientType) {
12561256
List.of(new PromptArgument("language", "Language", "string", false))),
12571257
(mcpSyncServerExchange, getPromptRequest) -> null))
12581258
.completions(new McpServerFeatures.SyncCompletionSpecification(
1259-
new PromptReference("ref/prompt", "code_review", "Code review"), completionHandler))
1259+
new McpSchema.PromptReference("ref/prompt", "code_review", "Code review"), completionHandler))
12601260
.build();
12611261

12621262
try (var mcpClient = clientBuilder.build()) {
@@ -1285,7 +1285,7 @@ void testCompletionShouldReturnExpectedSuggestions(String clientType) {
12851285
// Ping Tests
12861286
// ---------------------------------------
12871287
@ParameterizedTest(name = "{0} : {displayName} ")
1288-
@ValueSource(strings = { "httpclient" })
1288+
@MethodSource("clientsForTesting")
12891289
void testPingSuccess(String clientType) {
12901290

12911291
var clientBuilder = clientBuilders.get(clientType);
@@ -1348,7 +1348,7 @@ void testPingSuccess(String clientType) {
13481348
// Tool Structured Output Schema Tests
13491349
// ---------------------------------------
13501350
@ParameterizedTest(name = "{0} : {displayName} ")
1351-
@ValueSource(strings = { "httpclient" })
1351+
@MethodSource("clientsForTesting")
13521352
void testStructuredOutputValidationSuccess(String clientType) {
13531353
var clientBuilder = clientBuilders.get(clientType);
13541354

@@ -1593,7 +1593,7 @@ void testStructuredOutputValidationFailure(String clientType) {
15931593
}
15941594

15951595
@ParameterizedTest(name = "{0} : {displayName} ")
1596-
@ValueSource(strings = { "httpclient" })
1596+
@MethodSource("clientsForTesting")
15971597
void testStructuredOutputMissingStructuredContent(String clientType) {
15981598

15991599
var clientBuilder = clientBuilders.get(clientType);
@@ -1644,7 +1644,7 @@ void testStructuredOutputMissingStructuredContent(String clientType) {
16441644
}
16451645

16461646
@ParameterizedTest(name = "{0} : {displayName} ")
1647-
@ValueSource(strings = { "httpclient" })
1647+
@MethodSource("clientsForTesting")
16481648
void testStructuredOutputRuntimeToolAddition(String clientType) {
16491649

16501650
var clientBuilder = clientBuilders.get(clientType);

mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.time.Duration;
88
import java.util.Map;
9+
import java.util.stream.Stream;
910

1011
import io.modelcontextprotocol.client.McpClient;
1112
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
@@ -21,6 +22,7 @@
2122
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Timeout;
25+
import org.junit.jupiter.params.provider.Arguments;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

@@ -37,6 +39,10 @@ class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationT
3739

3840
private Tomcat tomcat;
3941

42+
static Stream<Arguments> clientsForTesting() {
43+
return Stream.of(Arguments.of("httpclient"));
44+
}
45+
4046
@BeforeEach
4147
public void before() {
4248
// Create and configure the transport provider

mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.time.Duration;
88
import java.util.Map;
9+
import java.util.stream.Stream;
910

1011
import io.modelcontextprotocol.client.McpClient;
1112
import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport;
@@ -21,6 +22,7 @@
2122
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Timeout;
25+
import org.junit.jupiter.params.provider.Arguments;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

@@ -35,6 +37,10 @@ class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerInteg
3537

3638
private Tomcat tomcat;
3739

40+
static Stream<Arguments> clientsForTesting() {
41+
return Stream.of(Arguments.of("httpclient"));
42+
}
43+
3844
@BeforeEach
3945
public void before() {
4046
// Create and configure the transport provider

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
import java.time.Duration;
88
import java.util.Map;
9+
import java.util.stream.Stream;
910

1011
import org.junit.jupiter.api.AfterEach;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Timeout;
14+
import org.junit.jupiter.params.provider.Arguments;
15+
1316
import org.springframework.http.server.reactive.HttpHandler;
1417
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
1518
import org.springframework.web.reactive.function.client.WebClient;
@@ -45,6 +48,10 @@ class WebFluxSseIntegrationTests extends AbstractMcpClientServerIntegrationTests
4548
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
4649
.create(Map.of("important", "value"));
4750

51+
static Stream<Arguments> clientsForTesting() {
52+
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
53+
}
54+
4855
@Override
4956
protected void prepareClients(int port, String mcpEndpoint) {
5057

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
package io.modelcontextprotocol;
66

77
import java.time.Duration;
8+
import java.util.stream.Stream;
89

910
import org.junit.jupiter.api.AfterEach;
1011
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.Timeout;
13+
import org.junit.jupiter.params.provider.Arguments;
14+
1215
import org.springframework.http.server.reactive.HttpHandler;
1316
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
1417
import org.springframework.web.reactive.function.client.WebClient;
@@ -35,6 +38,10 @@ class WebFluxStatelessIntegrationTests extends AbstractStatelessIntegrationTests
3538

3639
private WebFluxStatelessServerTransport mcpStreamableServerTransport;
3740

41+
static Stream<Arguments> clientsForTesting() {
42+
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
43+
}
44+
3845
@Override
3946
protected void prepareClients(int port, String mcpEndpoint) {
4047
clientBuilders

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
import java.time.Duration;
88
import java.util.Map;
9+
import java.util.stream.Stream;
910

1011
import org.junit.jupiter.api.AfterEach;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Timeout;
14+
import org.junit.jupiter.params.provider.Arguments;
15+
1316
import org.springframework.http.server.reactive.HttpHandler;
1417
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
1518
import org.springframework.web.reactive.function.client.WebClient;
@@ -43,6 +46,10 @@ class WebFluxStreamableIntegrationTests extends AbstractMcpClientServerIntegrati
4346
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
4447
.create(Map.of("important", "value"));
4548

49+
static Stream<Arguments> clientsForTesting() {
50+
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
51+
}
52+
4653
@Override
4754
protected void prepareClients(int port, String mcpEndpoint) {
4855

mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransportTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.http.codec.ServerSentEvent;
3232
import org.springframework.web.reactive.function.client.WebClient;
3333

34-
import static io.modelcontextprotocol.utils.McpJsonMapperUtils.JSON_MAPPER;
34+
import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER;
3535
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.assertj.core.api.Assertions.assertThatCode;
3737
import static org.assertj.core.api.Assertions.assertThatThrownBy;

0 commit comments

Comments
 (0)