Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.modelcontextprotocol.client;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.springframework.web.reactive.function.client.WebClient;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -19,7 +21,7 @@ public class WebClientStreamableHttpAsyncClientTests extends AbstractMcpAsyncCli

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js streamableHttp")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand All @@ -30,15 +32,15 @@ protected McpClientTransport createMcpTransport() {
return WebClientStreamableHttpTransport.builder(WebClient.builder().baseUrl(host)).build();
}

@Override
protected void onStart() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@Override
public void onClose() {
@AfterAll
static void stopContainer() {
container.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.modelcontextprotocol.client;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.springframework.web.reactive.function.client.WebClient;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -19,7 +21,7 @@ public class WebClientStreamableHttpSyncClientTests extends AbstractMcpSyncClien

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js streamableHttp")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand All @@ -30,15 +32,15 @@ protected McpClientTransport createMcpTransport() {
return WebClientStreamableHttpTransport.builder(WebClient.builder().baseUrl(host)).build();
}

@Override
protected void onStart() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@Override
public void onClose() {
@AfterAll
static void stopContainer() {
container.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.time.Duration;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.springframework.web.reactive.function.client.WebClient;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -26,7 +28,7 @@ class WebFluxSseMcpAsyncClientTests extends AbstractMcpAsyncClientTests {

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js sse")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand All @@ -37,15 +39,15 @@ protected McpClientTransport createMcpTransport() {
return WebFluxSseClientTransport.builder(WebClient.builder().baseUrl(host)).build();
}

@Override
protected void onStart() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@Override
public void onClose() {
@AfterAll
static void stopContainer() {
container.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;
import io.modelcontextprotocol.spec.McpClientTransport;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand All @@ -26,7 +28,7 @@ class WebFluxSseMcpSyncClientTests extends AbstractMcpSyncClientTests {

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js sse")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand All @@ -37,15 +39,15 @@ protected McpClientTransport createMcpTransport() {
return WebFluxSseClientTransport.builder(WebClient.builder().baseUrl(host)).build();
}

@Override
protected void onStart() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@Override
protected void onClose() {
@AfterAll
static void stopContainer() {
container.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -42,7 +44,7 @@ class WebFluxSseClientTransportTests {
static String host = "http://localhost:3001";

@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js sse")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand Down Expand Up @@ -95,15 +97,20 @@ public void simulateMessageEvent(String jsonMessage) {

}

void startContainer() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@AfterAll
static void cleanup() {
container.stop();
}

@BeforeEach
void setUp() {
startContainer();
webClientBuilder = WebClient.builder().baseUrl(host);
objectMapper = new ObjectMapper();
transport = new TestSseClientTransport(webClientBuilder, objectMapper);
Expand All @@ -115,11 +122,6 @@ void afterEach() {
if (transport != null) {
assertThatCode(() -> transport.closeGracefully().block(Duration.ofSeconds(10))).doesNotThrowAnyException();
}
cleanup();
}

void cleanup() {
container.stop();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public abstract class AbstractMcpAsyncClientTests {

abstract protected McpClientTransport createMcpTransport();

protected void onStart() {
}

protected void onClose() {
}

protected Duration getRequestTimeout() {
return Duration.ofSeconds(14);
}
Expand Down Expand Up @@ -117,16 +111,6 @@ void withClient(McpClientTransport transport, Function<McpClient.AsyncSpec, McpC
}
}

@BeforeEach
void setUp() {
onStart();
}

@AfterEach
void tearDown() {
onClose();
}

<T> void verifyNotificationSucceedsWithImplicitInitialization(Function<McpAsyncClient, Mono<T>> operation,
String action) {
withClient(createMcpTransport(), mcpAsyncClient -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ public abstract class AbstractMcpSyncClientTests {

abstract protected McpClientTransport createMcpTransport();

protected void onStart() {
}

protected void onClose() {
}

protected Duration getRequestTimeout() {
return Duration.ofSeconds(14);
}
Expand Down Expand Up @@ -114,17 +108,6 @@ void withClient(McpClientTransport transport, Function<McpClient.SyncSpec, McpCl
}
}

@BeforeEach
void setUp() {
onStart();

}

@AfterEach
void tearDown() {
onClose();
}

static final Object DUMMY_RETURN_VALUE = new Object();

<T> void verifyNotificationSucceedsWithImplicitInitialization(Consumer<McpSyncClient> operation, String action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ public abstract class AbstractMcpAsyncClientTests {

abstract protected McpClientTransport createMcpTransport();

protected void onStart() {
}

protected void onClose() {
}

protected Duration getRequestTimeout() {
return Duration.ofSeconds(14);
}
Expand Down Expand Up @@ -118,16 +112,6 @@ void withClient(McpClientTransport transport, Function<McpClient.AsyncSpec, McpC
}
}

@BeforeEach
void setUp() {
onStart();
}

@AfterEach
void tearDown() {
onClose();
}

<T> void verifyNotificationSucceedsWithImplicitInitialization(Function<McpAsyncClient, Mono<T>> operation,
String action) {
withClient(createMcpTransport(), mcpAsyncClient -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public abstract class AbstractMcpSyncClientTests {

abstract protected McpClientTransport createMcpTransport();

protected void onStart() {
}

protected void onClose() {
}

protected Duration getRequestTimeout() {
return Duration.ofSeconds(14);
}
Expand Down Expand Up @@ -115,17 +109,6 @@ void withClient(McpClientTransport transport, Function<McpClient.SyncSpec, McpCl
}
}

@BeforeEach
void setUp() {
onStart();

}

@AfterEach
void tearDown() {
onClose();
}

static final Object DUMMY_RETURN_VALUE = new Object();

<T> void verifyNotificationSucceedsWithImplicitInitialization(Consumer<McpSyncClient> operation, String action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.modelcontextprotocol.client;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand All @@ -14,11 +16,11 @@
@Timeout(15)
public class HttpClientStreamableHttpAsyncClientTests extends AbstractMcpAsyncClientTests {

private String host = "http://localhost:3001";
private static String host = "http://localhost:3001";

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v2")
.withCommand("node dist/index.js streamableHttp")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
Expand All @@ -30,15 +32,15 @@ protected McpClientTransport createMcpTransport() {
return HttpClientStreamableHttpTransport.builder(host).build();
}

@Override
protected void onStart() {
@BeforeAll
static void startContainer() {
container.start();
int port = container.getMappedPort(3001);
host = "http://" + container.getHost() + ":" + port;
}

@Override
public void onClose() {
@AfterAll
static void stopContainer() {
container.stop();
}

Expand Down
Loading