Update project functionality and configuration
This commit is contained in:
@@ -4,13 +4,14 @@ import static io.shinhanlife.dap.biz.mcp.TestFixtures.OBJECT_MAPPER;
|
||||
import static io.shinhanlife.dap.biz.mcp.TestFixtures.context;
|
||||
import static io.shinhanlife.dap.biz.mcp.TestFixtures.properties;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import io.shinhanlife.dap.biz.mcp.toolclient.ToolClient.ToolClientException;
|
||||
import io.shinhanlife.dap.biz.mcp.toolclient.ToolClient.ToolRequest;
|
||||
import io.shinhanlife.dap.biz.mcp.toolclient.ToolClient.ToolResponse;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
@@ -51,7 +52,7 @@ class HttpToolClientTest {
|
||||
|
||||
ToolResponse response = client.execute(request, context());
|
||||
|
||||
assertThat(response.data().path("customerName").asString()).isEqualTo("홍길동");
|
||||
assertThat(response.data().path("customerName").asText()).isEqualTo("홍길동");
|
||||
RecordedRequest recorded = server.takeRequest(1, TimeUnit.SECONDS);
|
||||
assertThat(recorded).isNotNull();
|
||||
assertThat(recorded.getMethod()).isEqualTo("POST");
|
||||
@@ -61,9 +62,35 @@ class HttpToolClientTest {
|
||||
assertThat(recorded.getHeader("mcp-session-id")).isEqualTo("session-1");
|
||||
assertThat(recorded.getHeader("employee-no")).isEqualTo("ENC(employee-1)");
|
||||
assertThat(recorded.getHeader("virtual-employee-no")).isEqualTo("ENC(virtual-1)");
|
||||
assertThat(recorded.getHeader("X-Tool-Server-API-Key")).isEqualTo("tool-server-key");
|
||||
assertThat(recorded.getHeader("x-trace-id")).isNull();
|
||||
assertThat(recorded.getHeader("Authorization")).isNull();
|
||||
assertThat(recorded.getBody().readUtf8()).contains("1234567890");
|
||||
assertThat(recorded.getBody().readUtf8())
|
||||
.contains("customerNo", "1234567890")
|
||||
.doesNotContain("arguments");
|
||||
}
|
||||
|
||||
@Test
|
||||
void postsDirectArgumentsForEveryToolServer() throws Exception {
|
||||
server.enqueue(new MockResponse().setHeader("Content-Type", "application/json")
|
||||
.setBody("{\"quote\":\"시작이 반이다.\"}"));
|
||||
HttpToolClient client =
|
||||
new HttpToolClient(OBJECT_MAPPER, properties(false, false), HttpClient.newHttpClient());
|
||||
ToolRequest request = new ToolRequest(
|
||||
"smp_quote_daily", "1.0.0", server.url("/mcp/smp_quote_daily").toString(),
|
||||
OBJECT_MAPPER.readTree("{\"category\":\"속담\"}"), 3_000);
|
||||
var base = context();
|
||||
var othContext = new io.shinhanlife.dap.biz.mcp.context.McpRequestContext(
|
||||
"oth", base.requestId(), base.guid(), base.mcpSessionId(), base.employeeNo(),
|
||||
base.virtualEmployeeNo(), base.authorization(), Instant.now().plusSeconds(10));
|
||||
|
||||
client.execute(request, othContext);
|
||||
|
||||
RecordedRequest recorded = server.takeRequest(1, TimeUnit.SECONDS);
|
||||
assertThat(recorded).isNotNull();
|
||||
assertThat(recorded.getBody().readUtf8())
|
||||
.contains("category", "속담")
|
||||
.doesNotContain("arguments");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +108,27 @@ class HttpToolClientTest {
|
||||
|
||||
ToolResponse response = client.execute(request, context());
|
||||
|
||||
assertThat(response.data().isString()).isTrue();
|
||||
assertThat(response.data().asString()).isEqualTo("123");
|
||||
assertThat(response.data().isTextual()).isTrue();
|
||||
assertThat(response.data().asText()).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesHttpStatusOnToolError() throws Exception {
|
||||
server.enqueue(new MockResponse().setResponseCode(410).setBody("gone"));
|
||||
HttpToolClient client =
|
||||
new HttpToolClient(OBJECT_MAPPER, properties(false, false), HttpClient.newHttpClient());
|
||||
ToolRequest request =
|
||||
new ToolRequest(
|
||||
"customer.search",
|
||||
"1.0.0",
|
||||
server.url("/api/v1/search").toString(),
|
||||
OBJECT_MAPPER.readTree("{\"customerNo\":\"1234567890\"}"),
|
||||
3_000);
|
||||
|
||||
assertThatThrownBy(() -> client.execute(request, context()))
|
||||
.isInstanceOfSatisfying(ToolClientException.class, exception -> {
|
||||
assertThat(exception.kind()).isEqualTo(ToolClientException.Kind.EXECUTION);
|
||||
assertThat(exception.httpStatusCode()).hasValue(410);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user