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 <christian.tzolov@broadcom.com>
This commit is contained in:
parent
1499df22c7
commit
8ac7eae47c
9 changed files with 134 additions and 76 deletions
|
|
@ -6,10 +6,13 @@ package io.modelcontextprotocol;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -45,6 +48,10 @@ class WebFluxSseIntegrationTests extends AbstractMcpClientServerIntegrationTests
|
|||
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
||||
.create(Map.of("important", "value"));
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareClients(int port, String mcpEndpoint) {
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@
|
|||
package io.modelcontextprotocol;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -35,6 +38,10 @@ class WebFluxStatelessIntegrationTests extends AbstractStatelessIntegrationTests
|
|||
|
||||
private WebFluxStatelessServerTransport mcpStreamableServerTransport;
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareClients(int port, String mcpEndpoint) {
|
||||
clientBuilders
|
||||
|
|
|
|||
|
|
@ -6,10 +6,13 @@ package io.modelcontextprotocol;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -43,6 +46,10 @@ class WebFluxStreamableIntegrationTests extends AbstractMcpClientServerIntegrati
|
|||
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
||||
.create(Map.of("important", "value"));
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareClients(int port, String mcpEndpoint) {
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import reactor.test.StepVerifier;
|
|||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static io.modelcontextprotocol.utils.McpJsonMapperUtils.JSON_MAPPER;
|
||||
import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.apache.catalina.Context;
|
|||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
|
@ -21,7 +22,7 @@ import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
|
|||
import reactor.netty.DisposableServer;
|
||||
|
||||
/**
|
||||
* Tests for {@link McpAsyncServer} using {@link WebFluxSseServerTransportProvider}.
|
||||
* Tests for {@link McpAsyncServer} using {@link WebMvcSseServerTransportProvider}.
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
|
|||
import reactor.netty.DisposableServer;
|
||||
|
||||
/**
|
||||
* Tests for {@link McpAsyncServer} using {@link WebFluxSseServerTransportProvider}.
|
||||
* Tests for {@link McpAsyncServer} using {@link WebMvcSseServerTransportProvider}.
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -7,12 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.LifecycleState;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -43,6 +46,10 @@ class WebMvcSseIntegrationTests extends AbstractMcpClientServerIntegrationTests
|
|||
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = r -> McpTransportContext
|
||||
.create(Map.of("important", "value"));
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareClients(int port, String mcpEndpoint) {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ package io.modelcontextprotocol.server;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.LifecycleState;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -37,6 +40,10 @@ class WebMvcStatelessIntegrationTests extends AbstractStatelessIntegrationTests
|
|||
|
||||
private WebMvcStatelessServerTransport mcpServerTransport;
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
static class TestConfig {
|
||||
|
|
|
|||
|
|
@ -7,12 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.LifecycleState;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -43,6 +46,10 @@ class WebMvcStreamableIntegrationTests extends AbstractMcpClientServerIntegratio
|
|||
static McpTransportContextExtractor<ServerRequest> TEST_CONTEXT_EXTRACTOR = r -> McpTransportContext
|
||||
.create(Map.of("important", "value"));
|
||||
|
||||
static Stream<Arguments> clientsForTesting() {
|
||||
return Stream.of(Arguments.of("httpclient"), Arguments.of("webflux"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
static class TestConfig {
|
||||
|
|
|
|||
Loading…
Reference in a new issue