Initial commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package io.shinhanlife.dap.biz.mcp.toolclient;
|
||||
|
||||
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 io.shinhanlife.dap.biz.mcp.toolclient.ToolClient.ToolRequest;
|
||||
import io.shinhanlife.dap.biz.mcp.toolclient.ToolClient.ToolResponse;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpToolClientTest {
|
||||
|
||||
private MockWebServer server;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
server = new MockWebServer();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
void postsJsonAndPropagatesCorrelationHeadersWithoutAuthorization() throws Exception {
|
||||
server.enqueue(
|
||||
new MockResponse()
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setBody("{\"customerName\":\"홍길동\"}"));
|
||||
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);
|
||||
|
||||
ToolResponse response = client.execute(request, context());
|
||||
|
||||
assertThat(response.data().path("customerName").asString()).isEqualTo("홍길동");
|
||||
RecordedRequest recorded = server.takeRequest(1, TimeUnit.SECONDS);
|
||||
assertThat(recorded).isNotNull();
|
||||
assertThat(recorded.getMethod()).isEqualTo("POST");
|
||||
// 다섯 헤더 모두 이름·값을 바꾸지 않고 그대로 bypass한다.
|
||||
assertThat(recorded.getHeader("guid")).isEqualTo("guid-1");
|
||||
assertThat(recorded.getHeader("x-request-id")).isEqualTo("req-1");
|
||||
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-trace-id")).isNull();
|
||||
assertThat(recorded.getHeader("Authorization")).isNull();
|
||||
assertThat(recorded.getBody().readUtf8()).contains("1234567890");
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesPlainTextToolResponseAsTextNode() throws Exception {
|
||||
server.enqueue(new MockResponse().setHeader("Content-Type", "text/plain").setBody("123"));
|
||||
HttpToolClient client =
|
||||
new HttpToolClient(OBJECT_MAPPER, properties(false, false), HttpClient.newHttpClient());
|
||||
ToolRequest request =
|
||||
new ToolRequest(
|
||||
"processing",
|
||||
"config",
|
||||
server.url("/mcp/v1/api/processing").toString(),
|
||||
OBJECT_MAPPER.readTree("{\"query\":\"test\"}"),
|
||||
3_000);
|
||||
|
||||
ToolResponse response = client.execute(request, context());
|
||||
|
||||
assertThat(response.data().isString()).isTrue();
|
||||
assertThat(response.data().asString()).isEqualTo("123");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user