Support local resource Portal registry loading

This commit is contained in:
2026-08-18 10:08:48 +09:00
parent e86942ddd4
commit 7f431a1c37
6 changed files with 174 additions and 15 deletions

View File

@@ -10,6 +10,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.shinhanlife.dap.biz.mcp.config.McpProperties;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -18,6 +21,8 @@ import okhttp3.mockwebserver.MockWebServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestClient;
@@ -26,6 +31,9 @@ class PortalToolRegistryClientTest {
private MockWebServer portal;
private MockWebServer toolServer;
@TempDir
private Path tempDir;
@BeforeEach
void setUp() throws Exception {
portal = new MockWebServer();
@@ -96,6 +104,22 @@ class PortalToolRegistryClientTest {
assertThat(toolServer.getRequestCount()).isEqualTo(1);
}
@Test
void loadsEndpointRegistryFromLocalFileWithoutCallingPortal() throws Exception {
Path registryFile = tempDir.resolve("local-toolserver-info-sample-v1.json");
Files.writeString(registryFile, portalRegistryJson("file-1"), StandardCharsets.UTF_8);
toolServer.enqueue(manifest("manifest-1", "external.weather"));
PortalToolRegistryClient client = client(registryFile.toUri().toString(), Optional.empty());
Map<String, List<ToolMetadata>> snapshots = client.fetchAllTools();
assertThat(snapshots.get("external"))
.extracting(ToolMetadata::name)
.containsExactly("external.weather");
assertThat(portal.getRequestCount()).isZero();
assertThat(toolServer.getRequestCount()).isEqualTo(1);
}
@Test
void rejectsBlankRouteInsteadOfUsingConfiguredDefaultRoute() {
@@ -112,6 +136,10 @@ class PortalToolRegistryClientTest {
}
private PortalToolRegistryClient client(Optional<RedisPortalRegistryCache> redisPortalRegistryCache) {
return client(portal.url("/api/portal/registry").toString(), redisPortalRegistryCache);
}
private PortalToolRegistryClient client(String registryUrl, Optional<RedisPortalRegistryCache> redisPortalRegistryCache) {
RestClient restClient = RestClient.builder()
.requestFactory(new SimpleClientHttpRequestFactory())
.build();
@@ -126,10 +154,11 @@ class PortalToolRegistryClientTest {
base.trace(),
base.protocol(),
base.discovery(),
new McpProperties.Portal(true, "", portal.url("/api/portal/registry").toString(), 15),
new McpProperties.Portal(true, "", registryUrl, 15),
List.of());
ToolBundleDiscovery discovery = new ToolBundleDiscovery(restClient, OBJECT_MAPPER, mcpProperties);
return new PortalToolRegistryClient(restClient, mcpProperties, discovery, redisPortalRegistryCache);
return new PortalToolRegistryClient(
restClient, mcpProperties, discovery, redisPortalRegistryCache, OBJECT_MAPPER, new DefaultResourceLoader());
}
private MockResponse portalRegistry(String revision) {