-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mkouba/add-basic-integration-test
Add basic integration test
- Loading branch information
Showing
12 changed files
with
428 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
integration-tests/src/main/java/io/quarkiverse/mcp/server/it/CodeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkiverse.mcp.server.it; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class CodeService { | ||
|
||
public String assist(String language) { | ||
return switch (language) { | ||
case "java" -> "System.out.println(\"Hello world!\");"; | ||
default -> throw new IllegalArgumentException("Unexpected value: " + language); | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
integration-tests/src/main/java/io/quarkiverse/mcp/server/it/McpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.mcp.server.it; | ||
|
||
import static jakarta.ws.rs.core.HttpHeaders.CONTENT_TYPE; | ||
import static jakarta.ws.rs.core.MediaType.SERVER_SENT_EVENTS; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.jboss.resteasy.reactive.client.SseEvent; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
|
||
@Path("mcp") | ||
@RegisterRestClient | ||
public interface McpClient { | ||
|
||
@GET | ||
@Path("sse") | ||
@ClientHeaderParam(name = CONTENT_TYPE, value = SERVER_SENT_EVENTS) | ||
@Produces(SERVER_SENT_EVENTS) | ||
Multi<SseEvent<String>> init(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
integration-tests/src/main/java/io/quarkiverse/mcp/server/it/McpClientInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkiverse.mcp.server.it; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.resteasy.reactive.client.SseEvent; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder; | ||
import io.vertx.ext.web.Router; | ||
|
||
// A workaround to init the MCP client via SSE in the test | ||
public class McpClientInit { | ||
|
||
void initRoute(@Observes Router router, @ConfigProperty(name = "quarkus.http.host") String host, | ||
@ConfigProperty(name = "quarkus.http.test-port") int port, | ||
@ConfigProperty(name = "quarkus.http.root-path") String root) { | ||
router.route("/test-init-mcp-client").blockingHandler(rc -> { | ||
try { | ||
URI baseUri = new URI("http://" + host + ":" + port + root); | ||
Log.infof("Test base URI: %s", baseUri); | ||
List<SseEvent<String>> sseMessages = new CopyOnWriteArrayList<>(); | ||
McpClient mcpClient = QuarkusRestClientBuilder.newBuilder() | ||
.baseUri(baseUri) | ||
.build(McpClient.class); | ||
mcpClient.init().subscribe().with(s -> sseMessages.add(s), e -> { | ||
}); | ||
Awaitility.await().until(() -> !sseMessages.isEmpty()); | ||
URI endpoint = new URI(sseMessages.get(0).data()); | ||
rc.end(endpoint.toString()); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
integration-tests/src/main/java/io/quarkiverse/mcp/server/it/ServerFeatures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.mcp.server.it; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import io.quarkiverse.mcp.server.Prompt; | ||
import io.quarkiverse.mcp.server.PromptArg; | ||
import io.quarkiverse.mcp.server.PromptMessage; | ||
import io.quarkiverse.mcp.server.TextContent; | ||
import io.quarkiverse.mcp.server.Tool; | ||
|
||
public class ServerFeatures { | ||
|
||
@Inject | ||
CodeService codeService; | ||
|
||
@Tool | ||
TextContent toLowerCase(String value) { | ||
return new TextContent(value.toLowerCase()); | ||
} | ||
|
||
@Prompt(name = "code_assist") | ||
PromptMessage codeAssist(@PromptArg(name = "lang") String language) { | ||
return PromptMessage.withUserRole(new TextContent(codeService.assist(language))); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
integration-tests/src/test/java/io/quarkiverse/mcp/server/it/ServerFeaturesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkiverse.mcp.server.it; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class ServerFeaturesIT extends ServerFeaturesTest { | ||
|
||
} |
Oops, something went wrong.