-
Notifications
You must be signed in to change notification settings - Fork 8
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 #6 from mkouba/server-ping
Implement server ping utility
- Loading branch information
Showing
7 changed files
with
181 additions
and
86 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
44 changes: 44 additions & 0 deletions
44
deployment/src/test/java/io/quarkiverse/mcp/server/test/ping/PingTest.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,44 @@ | ||
package io.quarkiverse.mcp.server.test.ping; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class PingTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root.addClasses(McpClient.class)); | ||
|
||
@Test | ||
public void testPing() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject pingMessage = newMessage("ping"); | ||
|
||
JsonObject pingResponse = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(pingMessage.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject pingResult = assertResponseMessage(pingMessage, pingResponse); | ||
assertNotNull(pingResult); | ||
assertTrue(pingResult.isEmpty()); | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
deployment/src/test/java/io/quarkiverse/mcp/server/test/prompts/PromptsTest.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,86 @@ | ||
package io.quarkiverse.mcp.server.test.prompts; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.test.FooService; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class PromptsTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root.addClasses(McpClient.class, FooService.class, MyPrompts.class)); | ||
|
||
@Test | ||
public void testPrompts() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject promptListMessage = newMessage("prompts/list"); | ||
|
||
JsonObject promptListResponse = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(promptListMessage.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject promptListResult = assertResponseMessage(promptListMessage, promptListResponse); | ||
assertNotNull(promptListResult); | ||
JsonArray prompts = promptListResult.getJsonArray("prompts"); | ||
assertEquals(4, prompts.size()); | ||
|
||
assertPromptMessage("Hello Lu!", endpoint, "foo", new JsonObject() | ||
.put("name", "Lu") | ||
.put("repeat", 1) | ||
.put("options", new JsonObject() | ||
.put("enabled", true))); | ||
assertPromptMessage("LU", endpoint, "BAR", new JsonObject() | ||
.put("val", "Lu")); | ||
assertPromptMessage("LU", endpoint, "uni_bar", new JsonObject() | ||
.put("val", "Lu")); | ||
assertPromptMessage("LU", endpoint, "uni_list_bar", new JsonObject() | ||
.put("val", "Lu")); | ||
} | ||
|
||
private void assertPromptMessage(String expectedText, URI endpoint, String name, JsonObject arguments) { | ||
JsonObject promptGetMessage = newMessage("prompts/get") | ||
.put("params", new JsonObject() | ||
.put("name", name) | ||
.put("arguments", arguments)); | ||
|
||
JsonObject promptGetResponse = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(promptGetMessage.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject promptGetResult = assertResponseMessage(promptGetMessage, promptGetResponse); | ||
assertNotNull(promptGetResult); | ||
JsonArray messages = promptGetResult.getJsonArray("messages"); | ||
assertEquals(1, messages.size()); | ||
JsonObject message = messages.getJsonObject(0); | ||
assertEquals("user", message.getString("role")); | ||
JsonObject content = message.getJsonObject("content"); | ||
assertEquals("text", content.getString("type")); | ||
assertEquals(expectedText, content.getString("text")); | ||
} | ||
|
||
} |
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