Skip to content

Commit 9087ec3

Browse files
committed
fix tests
1 parent 288beb4 commit 9087ec3

3 files changed

Lines changed: 149 additions & 17 deletions

File tree

pom.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<!--
2+
Copyright 2026 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
117
<project xmlns="http://maven.apache.org/POM/4.0.0"
218
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
319
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -106,9 +122,6 @@
106122
<groupId>com.spotify.fmt</groupId>
107123
<artifactId>fmt-maven-plugin</artifactId>
108124
<version>2.29</version>
109-
<configuration>
110-
<skip>true</skip>
111-
</configuration>
112125
<executions>
113126
<execution>
114127
<goals>

src/test/java/com/google/cloud/mcp/e2e/McpToolboxClientE2ETest.java

Lines changed: 133 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.google.cloud.mcp.ToolResult;
2828
import java.util.Map;
2929
import java.util.concurrent.CompletableFuture;
30-
import java.util.concurrent.ExecutionException;
3130
import org.junit.jupiter.api.BeforeEach;
3231
import org.junit.jupiter.api.Test;
3332
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -61,6 +60,13 @@ void testLoadToolsetSpecific() {
6160
void testLoadToolsetDefault() {
6261
Map<String, ToolDefinition> tools = client.loadToolset().join();
6362
assertEquals(7, tools.size());
63+
assertTrue(tools.containsKey("get-row-by-content-auth"));
64+
assertTrue(tools.containsKey("get-row-by-email-auth"));
65+
assertTrue(tools.containsKey("get-row-by-id-auth"));
66+
assertTrue(tools.containsKey("get-row-by-id"));
67+
assertTrue(tools.containsKey("get-n-rows"));
68+
assertTrue(tools.containsKey("search-rows"));
69+
assertTrue(tools.containsKey("process-data"));
6470
}
6571

6672
@Test
@@ -78,13 +84,17 @@ void testRunTool() {
7884
@Test
7985
void testRunToolMissingParams() {
8086
Tool tool = client.loadTool("get-n-rows").join();
81-
assertThrows(IllegalArgumentException.class, () -> tool.execute(Map.of()));
87+
IllegalArgumentException ex =
88+
assertThrows(IllegalArgumentException.class, () -> tool.execute(Map.of()));
89+
assertTrue(ex.getMessage().contains("Missing required parameter"));
8290
}
8391

8492
@Test
8593
void testRunToolWrongParamType() {
8694
Tool tool = client.loadTool("get-n-rows").join();
87-
assertThrows(IllegalArgumentException.class, () -> tool.execute(Map.of("num_rows", 2)));
95+
IllegalArgumentException ex =
96+
assertThrows(IllegalArgumentException.class, () -> tool.execute(Map.of("num_rows", 2)));
97+
assertTrue(ex.getMessage().contains("expected type"));
8898
}
8999

90100
// --- TestBindParams ---
@@ -126,6 +136,7 @@ void testRunToolAuth() {
126136
"my-test-auth", () -> CompletableFuture.completedFuture(server.getAuthToken1()));
127137

128138
ToolResult result = tool.execute(Map.of("id", "2")).join();
139+
assertFalse(result.isError());
129140
String output = result.content().get(0).text();
130141
assertTrue(output.contains("row2"));
131142
}
@@ -134,8 +145,9 @@ void testRunToolAuth() {
134145
void testRunToolNoAuth() {
135146
Tool tool = client.loadTool("get-row-by-id-auth").join();
136147

137-
ExecutionException ex =
138-
assertThrows(ExecutionException.class, () -> tool.execute(Map.of("id", "2")).join());
148+
ToolResult result = tool.execute(Map.of("id", "2")).join();
149+
assertTrue(result.isError());
150+
assertTrue(result.content().get(0).text().contains("permission error"));
139151
}
140152

141153
@Test
@@ -145,8 +157,43 @@ void testRunToolWrongAuth() {
145157
tool.addAuthTokenGetter(
146158
"my-test-auth", () -> CompletableFuture.completedFuture(server.getAuthToken2()));
147159

148-
ExecutionException ex =
149-
assertThrows(ExecutionException.class, () -> tool.execute(Map.of("id", "2")).join());
160+
ToolResult result = tool.execute(Map.of("id", "2")).join();
161+
assertTrue(result.isError());
162+
assertTrue(result.content().get(0).text().contains("not authorized"));
163+
}
164+
165+
@Test
166+
void testRunToolParamAuth() {
167+
Tool tool = client.loadTool("get-row-by-email-auth").join();
168+
tool.addAuthTokenGetter(
169+
"my-test-auth", () -> CompletableFuture.completedFuture(server.getAuthToken1()));
170+
171+
ToolResult result = tool.execute(Map.of()).join();
172+
assertFalse(result.isError());
173+
String output = result.content().get(0).text();
174+
assertTrue(output.contains("row4"));
175+
assertTrue(output.contains("row5"));
176+
assertTrue(output.contains("row6"));
177+
}
178+
179+
@Test
180+
void testRunToolParamAuthNoAuth() {
181+
Tool tool = client.loadTool("get-row-by-email-auth").join();
182+
183+
ToolResult result = tool.execute(Map.of()).join();
184+
assertTrue(result.isError());
185+
assertTrue(result.content().get(0).text().contains("permission error"));
186+
}
187+
188+
@Test
189+
void testRunToolParamAuthNoField() {
190+
Tool tool = client.loadTool("get-row-by-content-auth").join();
191+
tool.addAuthTokenGetter(
192+
"my-test-auth", () -> CompletableFuture.completedFuture(server.getAuthToken1()));
193+
194+
ToolResult result = tool.execute(Map.of()).join();
195+
assertTrue(result.isError());
196+
assertTrue(result.content().get(0).text().contains("no field named row_data"));
150197
}
151198

152199
// --- TestOptionalParams ---
@@ -155,18 +202,59 @@ void testRunToolWrongAuth() {
155202
void testRunToolWithOptionalParamsOmitted() {
156203
Tool tool = client.loadTool("search-rows").join();
157204
ToolResult result = tool.execute(Map.of("email", "twishabansal@google.com")).join();
205+
assertFalse(result.isError());
158206
String output = result.content().get(0).text();
159-
assertTrue(output.contains("twishabansal@google.com"));
207+
assertTrue(output.contains("\"email\":\"twishabansal@google.com\""));
160208
assertTrue(output.contains("row2"));
209+
assertFalse(output.contains("row3"));
161210
}
162211

163212
@Test
164-
void testRunToolWithOptionalDataProvided() {
213+
void testRunToolWithOptionalParamsExplicitNull() {
214+
Tool tool = client.loadTool("search-rows").join();
215+
java.util.HashMap<String, Object> params = new java.util.HashMap<>();
216+
params.put("email", "twishabansal@google.com");
217+
params.put("data", null);
218+
params.put("id", null);
219+
220+
ToolResult result = tool.execute(params).join();
221+
assertFalse(result.isError());
222+
String output = result.content().get(0).text();
223+
assertTrue(output.contains("\"email\":\"twishabansal@google.com\""));
224+
assertTrue(output.contains("row2"));
225+
assertFalse(output.contains("row3"));
226+
}
227+
228+
@Test
229+
void testRunToolWithAllParamsProvided() {
165230
Tool tool = client.loadTool("search-rows").join();
166231
ToolResult result =
167-
tool.execute(Map.of("email", "twishabansal@google.com", "data", "row3")).join();
232+
tool.execute(Map.of("email", "twishabansal@google.com", "data", "row3", "id", 3)).join();
233+
assertFalse(result.isError());
168234
String output = result.content().get(0).text();
235+
assertTrue(output.contains("\"email\":\"twishabansal@google.com\""));
236+
assertTrue(output.contains("\"id\":3"));
169237
assertTrue(output.contains("row3"));
238+
assertFalse(output.contains("row2"));
239+
}
240+
241+
@Test
242+
void testRunToolMissingRequiredParam() {
243+
Tool tool = client.loadTool("search-rows").join();
244+
IllegalArgumentException ex =
245+
assertThrows(
246+
IllegalArgumentException.class, () -> tool.execute(Map.of("data", "row5", "id", 5)));
247+
assertTrue(ex.getMessage().contains("Missing required parameter"));
248+
}
249+
250+
@Test
251+
void testRunToolWrongTypeForInteger() {
252+
Tool tool = client.loadTool("search-rows").join();
253+
IllegalArgumentException ex =
254+
assertThrows(
255+
IllegalArgumentException.class,
256+
() -> tool.execute(Map.of("email", "foo", "id", "not-an-integer")));
257+
assertTrue(ex.getMessage().contains("expected type"));
170258
}
171259

172260
// --- TestMapParams ---
@@ -182,9 +270,41 @@ void testRunToolWithMapParams() {
182270
"feature_flags", Map.of("new_feature", true)))
183271
.join();
184272

273+
assertFalse(result.isError());
274+
String output = result.content().get(0).text();
275+
assertTrue(
276+
output.contains("\"execution_context\":{\"env\":\"prod\",\"id\":1234,\"user\":1234.5}"));
277+
assertTrue(output.contains("\"user_scores\":{\"user1\":100,\"user2\":200}"));
278+
assertTrue(output.contains("\"feature_flags\":{\"new_feature\":true}"));
279+
}
280+
281+
@Test
282+
void testRunToolOmittingOptionalMap() {
283+
Tool tool = client.loadTool("process-data").join();
284+
ToolResult result =
285+
tool.execute(
286+
Map.of(
287+
"execution_context", Map.of("env", "dev"),
288+
"user_scores", Map.of("user3", 300)))
289+
.join();
290+
291+
assertFalse(result.isError());
185292
String output = result.content().get(0).text();
186-
assertTrue(output.contains("\"env\":\"prod\""));
187-
assertTrue(output.contains("\"user1\":100"));
188-
assertTrue(output.contains("\"new_feature\":true"));
293+
assertTrue(output.contains("\"execution_context\":{\"env\":\"dev\"}"));
294+
assertTrue(output.contains("\"user_scores\":{\"user3\":300}"));
295+
assertTrue(output.contains("\"feature_flags\":null"));
296+
}
297+
298+
@Test
299+
void testRunToolWithWrongMapValueType() {
300+
Tool tool = client.loadTool("process-data").join();
301+
ToolResult result =
302+
tool.execute(
303+
Map.of(
304+
"execution_context", Map.of("env", "staging"),
305+
"user_scores", Map.of("user4", "not-an-integer")))
306+
.join();
307+
assertTrue(result.isError());
308+
assertTrue(result.content().get(0).text().contains("expects an integer"));
189309
}
190310
}

src/test/java/com/google/cloud/mcp/e2e/ToolboxE2ESetup.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.file.Files;
2727
import java.nio.file.Path;
2828
import java.nio.file.Paths;
29-
import java.nio.file.StandardCopyOption;
3029
import java.util.Locale;
3130
import java.util.concurrent.TimeUnit;
3231
import java.util.logging.Logger;

0 commit comments

Comments
 (0)