Skip to content

Commit eae81ad

Browse files
committed
Add additional tests for MCP Server command
1 parent 7139b56 commit eae81ad

File tree

13 files changed

+225
-13
lines changed

13 files changed

+225
-13
lines changed

schemacrawler-ai-core/src/main/java/schemacrawler/tools/ai/chat/ChatAssistantRegistry.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public Collection<PropertyName> getRegisteredPlugins() {
5959
}
6060

6161
public ChatAssistant newChatAssistant(
62-
final ChatOptions commandOptions,
63-
final Catalog catalog,
64-
final Connection connection) {
62+
final ChatOptions commandOptions, final Catalog catalog, final Connection connection) {
6563

6664
if (chatAssistantClasses.isEmpty()) {
6765
throw new SchemaCrawlerException("No chat assistant implementation found");
@@ -71,8 +69,7 @@ public ChatAssistant newChatAssistant(
7169
try {
7270
// Initialize the assistant with our parameters
7371
final java.lang.reflect.Constructor<?> constructor =
74-
chatAssistantClass.getConstructor(
75-
ChatOptions.class, Catalog.class, Connection.class);
72+
chatAssistantClass.getConstructor(ChatOptions.class, Catalog.class, Connection.class);
7673
return (ChatAssistant) constructor.newInstance(commandOptions, catalog, connection);
7774
} catch (final Exception e) {
7875
LOGGER.log(

schemacrawler-ai-langchain4j/src/main/java/schemacrawler/tools/command/aichat/langchain4j/AiModelFactoryUtility.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ interface AiModelFactory {
3131
EmbeddingModel newEmbeddingModel();
3232
}
3333

34-
public static AiModelFactory chooseAiModelFactory(
35-
final ChatOptions aiChatCommandOptions) {
34+
public static AiModelFactory chooseAiModelFactory(final ChatOptions aiChatCommandOptions) {
3635
requireNonNull(aiChatCommandOptions, "No AI Chat options provided");
3736
final AiModelFactory[] modelFactories = {
3837
new OpenAIModelFactory(aiChatCommandOptions),

schemacrawler-ai-langchain4j/src/main/java/schemacrawler/tools/command/aichat/langchain4j/Langchain4JChatAssistant.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public class Langchain4JChatAssistant implements ChatAssistant {
5959
private boolean shouldExit;
6060

6161
public Langchain4JChatAssistant(
62-
final ChatOptions aiChatOptions,
63-
final Catalog catalog,
64-
final Connection connection) {
62+
final ChatOptions aiChatOptions, final Catalog catalog, final Connection connection) {
6563

6664
requireNonNull(aiChatOptions, "AI chat options not provided");
6765
requireNonNull(catalog, "No catalog provided");

schemacrawler-ai-mcpserver/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@
7575
<artifactId>schemacrawler-testdb</artifactId>
7676
<scope>test</scope>
7777
</dependency>
78+
<dependency>
79+
<groupId>us.fatehi</groupId>
80+
<artifactId>schemacrawler-api</artifactId>
81+
<type>test-jar</type>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>us.fatehi</groupId>
86+
<artifactId>schemacrawler-tools</artifactId>
87+
<type>test-jar</type>
88+
<scope>test</scope>
89+
</dependency>
7890
<dependency>
7991
<groupId>org.springframework.boot</groupId>
8092
<artifactId>spring-boot-starter-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
schemacrawler.tools.command.aichat.mcp.command.McpServerCommandProvider
1+
schemacrawler.tools.command.mcpserver.McpServerCommandProvider
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-License-Identifier: CC-BY-NC-4.0
77
*/
88

9-
package schemacrawler.tools.command.aichat.mcp.controller;
9+
package schemacrawler.tools.ai.mcpserver.server.test;
1010

1111
import static org.hamcrest.Matchers.containsString;
1212
import static org.hamcrest.Matchers.is;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-License-Identifier: CC-BY-NC-4.0
77
*/
88

9-
package schemacrawler.tools.command.aichat.mcp;
9+
package schemacrawler.tools.ai.mcpserver.test;
1010

1111
import static org.assertj.core.api.Assertions.assertThat;
1212
import java.util.Map;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SchemaCrawler AI
3+
* http://www.schemacrawler.com
4+
* Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
5+
* All rights reserved.
6+
* SPDX-License-Identifier: CC-BY-NC-4.0
7+
*/
8+
9+
package schemacrawler.tools.command.mcpserver.test;
10+
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
import static org.hamcrest.Matchers.is;
13+
import java.util.Collection;
14+
import org.junit.jupiter.api.Test;
15+
import schemacrawler.tools.executable.CommandRegistry;
16+
import us.fatehi.utility.property.PropertyName;
17+
18+
public class CommandPluginTest {
19+
20+
@Test
21+
public void testCommandPlugin() throws Exception {
22+
final CommandRegistry registry = CommandRegistry.getCommandRegistry();
23+
assertThat(isCommandSupported(registry, "mcpserver"), is(true));
24+
}
25+
26+
private boolean isCommandSupported(final CommandRegistry registry, final String command) {
27+
final Collection<PropertyName> supportedCommands = registry.getRegisteredPlugins();
28+
for (final PropertyName supportedCommand : supportedCommands) {
29+
if (supportedCommand.getName().equals(command)) {
30+
return true;
31+
}
32+
}
33+
return false;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* SchemaCrawler AI
3+
* http://www.schemacrawler.com
4+
* Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
5+
* All rights reserved.
6+
* SPDX-License-Identifier: CC-BY-NC-4.0
7+
*/
8+
9+
package schemacrawler.tools.command.mcpserver.test;
10+
11+
import static org.hamcrest.CoreMatchers.is;
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.junit.jupiter.api.Assertions.assertThrows;
14+
import org.junit.jupiter.api.Test;
15+
import schemacrawler.tools.command.mcpserver.McpServerCommandOptions;
16+
import schemacrawler.tools.command.mcpserver.McpServerCommandOptionsBuilder;
17+
import schemacrawler.tools.command.mcpserver.McpTransport;
18+
import schemacrawler.tools.options.Config;
19+
20+
public class McpServerCommandOptionsBuilderTest {
21+
22+
@Test
23+
public void mcpServerCommandOptionsBuilderTimeout() {
24+
25+
final McpServerCommandOptionsBuilder optionsBuilder = McpServerCommandOptionsBuilder.builder();
26+
27+
assertThat(optionsBuilder.toOptions().mcpTransport().name(), is("stdio"));
28+
29+
optionsBuilder.withMcpTransport(McpTransport.sse);
30+
assertThat(optionsBuilder.toOptions().mcpTransport().name(), is("sse"));
31+
32+
optionsBuilder.withMcpTransport(McpTransport.stdio);
33+
assertThat(optionsBuilder.toOptions().mcpTransport().name(), is("stdio"));
34+
}
35+
36+
@Test
37+
public void fromConfig() {
38+
Config config;
39+
40+
config = new Config();
41+
config.put("transport", "sse");
42+
final McpServerCommandOptions options =
43+
McpServerCommandOptionsBuilder.builder().fromConfig(config).toOptions();
44+
assertThat(options.mcpTransport().name(), is("sse"));
45+
}
46+
47+
@Test
48+
public void fromNullConfig() {
49+
final McpServerCommandOptions options =
50+
McpServerCommandOptionsBuilder.builder().fromConfig(null).toOptions();
51+
assertThat(options.mcpTransport().name(), is("stdio"));
52+
}
53+
54+
@Test
55+
public void fromOptions() {
56+
final McpServerCommandOptions options =
57+
McpServerCommandOptionsBuilder.builder().withMcpTransport(McpTransport.sse).toOptions();
58+
final McpServerCommandOptionsBuilder optionsBuilder =
59+
McpServerCommandOptionsBuilder.builder().fromOptions(options);
60+
assertThat(optionsBuilder.toOptions().mcpTransport().name(), is("sse"));
61+
}
62+
63+
@Test
64+
public void fromNullOptions() {
65+
final McpServerCommandOptions options =
66+
McpServerCommandOptionsBuilder.builder().fromOptions(null).toOptions();
67+
final McpServerCommandOptionsBuilder optionsBuilder =
68+
McpServerCommandOptionsBuilder.builder().fromOptions(options);
69+
assertThat(optionsBuilder.toOptions().mcpTransport().name(), is("stdio"));
70+
}
71+
72+
@Test
73+
public void toConfig() {
74+
final McpServerCommandOptionsBuilder builder = McpServerCommandOptionsBuilder.builder();
75+
assertThrows(UnsupportedOperationException.class, () -> builder.toConfig());
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* SchemaCrawler AI
3+
* http://www.schemacrawler.com
4+
* Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
5+
* All rights reserved.
6+
* SPDX-License-Identifier: CC-BY-NC-4.0
7+
*/
8+
9+
package schemacrawler.tools.command.mcpserver.test;
10+
11+
import static org.hamcrest.CoreMatchers.is;
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
14+
import static org.junit.jupiter.api.Assertions.assertThrows;
15+
import static schemacrawler.test.utility.FileHasContent.classpathResource;
16+
import static schemacrawler.test.utility.FileHasContent.hasSameContentAs;
17+
import static schemacrawler.test.utility.FileHasContent.outputOf;
18+
import java.io.IOException;
19+
import org.junit.jupiter.api.Test;
20+
import schemacrawler.test.utility.PluginCommandTestUtility;
21+
import schemacrawler.test.utility.ResolveTestContext;
22+
import schemacrawler.test.utility.TestContext;
23+
import schemacrawler.test.utility.TestWriter;
24+
import schemacrawler.tools.command.mcpserver.McpServerCommand;
25+
import schemacrawler.tools.command.mcpserver.McpServerCommandOptions;
26+
import schemacrawler.tools.command.mcpserver.McpServerCommandProvider;
27+
import schemacrawler.tools.executable.commandline.PluginCommand;
28+
import schemacrawler.tools.options.Config;
29+
30+
@ResolveTestContext
31+
public class McpServerCommandProviderTest {
32+
33+
@Test
34+
public void mcpServerCommandProviderHelpCommand(final TestContext testContext) {
35+
final PluginCommand pluginCommand = new McpServerCommandProvider().getHelpCommand();
36+
PluginCommandTestUtility.testPluginCommand(testContext, pluginCommand);
37+
}
38+
39+
@Test
40+
public void mcpServerCommandProviderPluginCommand(final TestContext testContext) {
41+
final PluginCommand pluginCommand = new McpServerCommandProvider().getCommandLineCommand();
42+
PluginCommandTestUtility.testPluginCommand(testContext, pluginCommand);
43+
}
44+
45+
@Test
46+
public void newSchemaCrawlerCommand() {
47+
final McpServerCommandProvider commandProvider = new McpServerCommandProvider();
48+
assertThrows(
49+
IllegalArgumentException.class,
50+
() -> commandProvider.newSchemaCrawlerCommand("bad-command", new Config()));
51+
52+
assertDoesNotThrow(() -> commandProvider.newSchemaCrawlerCommand("mcpserver", new Config()));
53+
54+
final Config config = new Config();
55+
config.put("api-key", "api-key");
56+
final McpServerCommand command = commandProvider.newSchemaCrawlerCommand("mcpserver", config);
57+
final McpServerCommandOptions commandOptions = command.getCommandOptions();
58+
assertThat(commandOptions.mcpTransport().name(), is("stdio"));
59+
}
60+
61+
@Test
62+
public void pluginCommand(final TestContext testContext) throws IOException {
63+
final McpServerCommandProvider commandProvider = new McpServerCommandProvider();
64+
final TestWriter testout = new TestWriter();
65+
try (final TestWriter out = testout) {
66+
out.write(commandProvider.getCommandLineCommand().toString());
67+
}
68+
assertThat(
69+
outputOf(testout), hasSameContentAs(classpathResource(testContext.testMethodFullName())));
70+
}
71+
72+
@Test
73+
public void supportsOutputFormat() {
74+
final McpServerCommandProvider commandProvider = new McpServerCommandProvider();
75+
assertThat(commandProvider.supportsOutputFormat(null, null), is(true));
76+
}
77+
}

0 commit comments

Comments
 (0)