Skip to content

Commit 775c2fa

Browse files
committed
refactor: use builder pattern for CreateMessageRequest in integration tests
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent c50d3b3 commit 775c2fa

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest;
2525
import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult;
2626
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
27+
import io.modelcontextprotocol.spec.McpSchema.ModelPreferences;
2728
import io.modelcontextprotocol.spec.McpSchema.Role;
2829
import io.modelcontextprotocol.spec.McpSchema.Root;
2930
import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities;
@@ -45,6 +46,7 @@
4546

4647
import static org.assertj.core.api.Assertions.assertThat;
4748
import static org.awaitility.Awaitility.await;
49+
import static org.junit.Assert.assertThat;
4850
import static org.mockito.Mockito.mock;
4951

5052
public class WebFluxSseIntegrationTests {
@@ -142,13 +144,16 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
142144
McpServerFeatures.AsyncToolSpecification tool = new McpServerFeatures.AsyncToolSpecification(
143145
new McpSchema.Tool("tool1", "tool1 description", emptyJsonSchema), (exchange, request) -> {
144146

145-
var messages = List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
146-
new McpSchema.TextContent("Test message")));
147-
var modelPrefs = new McpSchema.ModelPreferences(List.of(), 1.0, 1.0, 1.0);
148-
149-
var craeteMessageRequest = new McpSchema.CreateMessageRequest(messages, modelPrefs, null,
150-
McpSchema.CreateMessageRequest.ContextInclusionStrategy.NONE, null, 100, List.of(),
151-
Map.of());
147+
var craeteMessageRequest = McpSchema.CreateMessageRequest.builder()
148+
.messages(List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
149+
new McpSchema.TextContent("Test message"))))
150+
.modelPreferences(ModelPreferences.builder()
151+
.hints(List.of())
152+
.costPriority(1.0)
153+
.speedPriority(1.0)
154+
.intelligencePriority(1.0)
155+
.build())
156+
.build();
152157

153158
StepVerifier.create(exchange.createMessage(craeteMessageRequest)).consumeNextWith(result -> {
154159
assertThat(result).isNotNull();

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcSseIntegrationTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest;
2121
import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult;
2222
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
23+
import io.modelcontextprotocol.spec.McpSchema.ModelPreferences;
2324
import io.modelcontextprotocol.spec.McpSchema.Role;
2425
import io.modelcontextprotocol.spec.McpSchema.Root;
2526
import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities;
@@ -45,6 +46,7 @@
4546

4647
import static org.assertj.core.api.Assertions.assertThat;
4748
import static org.awaitility.Awaitility.await;
49+
import static org.junit.Assert.assertThat;
4850
import static org.mockito.Mockito.mock;
4951

5052
public class WebMvcSseIntegrationTests {
@@ -199,13 +201,16 @@ void testCreateMessageSuccess() throws InterruptedException {
199201
McpServerFeatures.AsyncToolSpecification tool = new McpServerFeatures.AsyncToolSpecification(
200202
new McpSchema.Tool("tool1", "tool1 description", emptyJsonSchema), (exchange, request) -> {
201203

202-
var messages = List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
203-
new McpSchema.TextContent("Test message")));
204-
var modelPrefs = new McpSchema.ModelPreferences(List.of(), 1.0, 1.0, 1.0);
205-
206-
var craeteMessageRequest = new McpSchema.CreateMessageRequest(messages, modelPrefs, null,
207-
McpSchema.CreateMessageRequest.ContextInclusionStrategy.NONE, null, 100, List.of(),
208-
Map.of());
204+
var craeteMessageRequest = McpSchema.CreateMessageRequest.builder()
205+
.messages(List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
206+
new McpSchema.TextContent("Test message"))))
207+
.modelPreferences(ModelPreferences.builder()
208+
.hints(List.of())
209+
.costPriority(1.0)
210+
.speedPriority(1.0)
211+
.intelligencePriority(1.0)
212+
.build())
213+
.build();
209214

210215
StepVerifier.create(exchange.createMessage(craeteMessageRequest)).consumeNextWith(result -> {
211216
assertThat(result).isNotNull();

mcp/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProviderIntegrationTests.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest;
2222
import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult;
2323
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
24+
import io.modelcontextprotocol.spec.McpSchema.ModelPreferences;
2425
import io.modelcontextprotocol.spec.McpSchema.Role;
2526
import io.modelcontextprotocol.spec.McpSchema.Root;
2627
import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities;
@@ -162,13 +163,16 @@ void testCreateMessageSuccess() throws InterruptedException {
162163
McpServerFeatures.AsyncToolSpecification tool = new McpServerFeatures.AsyncToolSpecification(
163164
new McpSchema.Tool("tool1", "tool1 description", emptyJsonSchema), (exchange, request) -> {
164165

165-
var messages = List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
166-
new McpSchema.TextContent("Test message")));
167-
var modelPrefs = new McpSchema.ModelPreferences(List.of(), 1.0, 1.0, 1.0);
168-
169-
var craeteMessageRequest = new McpSchema.CreateMessageRequest(messages, modelPrefs, null,
170-
McpSchema.CreateMessageRequest.ContextInclusionStrategy.NONE, null, 100, List.of(),
171-
Map.of());
166+
var craeteMessageRequest = McpSchema.CreateMessageRequest.builder()
167+
.messages(List.of(new McpSchema.SamplingMessage(McpSchema.Role.USER,
168+
new McpSchema.TextContent("Test message"))))
169+
.modelPreferences(ModelPreferences.builder()
170+
.hints(List.of())
171+
.costPriority(1.0)
172+
.speedPriority(1.0)
173+
.intelligencePriority(1.0)
174+
.build())
175+
.build();
172176

173177
StepVerifier.create(exchange.createMessage(craeteMessageRequest)).consumeNextWith(result -> {
174178
assertThat(result).isNotNull();

0 commit comments

Comments
 (0)