From c390b89250e79e9760db2e3e716e6b9f17ba410f Mon Sep 17 00:00:00 2001 From: jade Date: Tue, 18 Aug 2026 20:46:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=B4=ED=8C=8C=EC=9D=BC=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/McpRouterControllerTest.java | 38 -------- .../dap/lib/mcp/ToolExecutionServiceTest.java | 87 ------------------- 2 files changed, 125 deletions(-) delete mode 100644 dap-gateway/src/test/java/io/shinhanlife/dap/mcg/presentation/McpRouterControllerTest.java delete mode 100644 dap-was-lib/src/test/java/io/shinhanlife/dap/lib/mcp/ToolExecutionServiceTest.java diff --git a/dap-gateway/src/test/java/io/shinhanlife/dap/mcg/presentation/McpRouterControllerTest.java b/dap-gateway/src/test/java/io/shinhanlife/dap/mcg/presentation/McpRouterControllerTest.java deleted file mode 100644 index d5a1a84f..00000000 --- a/dap-gateway/src/test/java/io/shinhanlife/dap/mcg/presentation/McpRouterControllerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.shinhanlife.dap.mcg.presentation; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.shinhanlife.dap.lib.mcp.security.SecurityProperties; -import io.shinhanlife.dap.lib.adapter.dto.JsonRpcResponse; -import io.shinhanlife.dap.mcg.config.GatewayFallbackProperties; -import io.shinhanlife.dap.mcg.registry.RedisRegistryService; -import io.shinhanlife.dap.mcg.service.ExecuteService; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.springframework.data.redis.RedisConnectionFailureException; -import org.springframework.http.ResponseEntity; - -class McpRouterControllerTest { - - @Test - void returnsEmptyToolListWhenRedisIsUnavailableAndNoFallbackIsConfigured() { - RedisRegistryService registryService = org.mockito.Mockito.mock(RedisRegistryService.class); - when(registryService.getAllTools()).thenThrow(new RedisConnectionFailureException("Redis unavailable")); - - McpRouterController controller = new McpRouterController( - registryService, - org.mockito.Mockito.mock(ExecuteService.class), - org.mockito.Mockito.mock(SecurityProperties.class), - new ObjectMapper(), - new GatewayFallbackProperties()); - - ResponseEntity response = assertDoesNotThrow(() -> controller.listTools(null)); - Map result = (Map) response.getBody().getResult(); - - assertEquals(List.of(), result.get("tools")); - } -} \ No newline at end of file diff --git a/dap-was-lib/src/test/java/io/shinhanlife/dap/lib/mcp/ToolExecutionServiceTest.java b/dap-was-lib/src/test/java/io/shinhanlife/dap/lib/mcp/ToolExecutionServiceTest.java deleted file mode 100644 index d4e115a6..00000000 --- a/dap-was-lib/src/test/java/io/shinhanlife/dap/lib/mcp/ToolExecutionServiceTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.shinhanlife.dap.lib.mcp; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.shinhanlife.dap.lib.annotation.GrowToolHint; -import io.shinhanlife.dap.lib.config.McpProperties; -import io.shinhanlife.dap.lib.util.ToolSchemaResolver; -import io.shinhanlife.dap.lib.validation.ToolArgumentSchemaValidator; -import java.util.Map; -import java.util.Arrays; -import org.junit.jupiter.api.Test; -import org.springaicommunity.mcp.annotation.McpTool; -import org.springaicommunity.mcp.annotation.McpToolParam; -import org.springframework.context.support.StaticApplicationContext; - -class McpToolExecutionServiceTest { - - @Test - void returnsNotFoundWhenNoToolMatchesTheRequestedName() { - McpToolExecutionService service = serviceWith(new Object()); - ToolExecutionResult result = service.execute("missing.cmm.tool.inquiry", null, Map.of()); - assertEquals(404, result.statusCode()); - assertEquals("TOOL_NOT_FOUND", ((Map) result.body()).get("code")); - } - - @Test - void convertsArgumentsToDtoAndExecutesTheMatchedTool() { - McpToolExecutionService service = serviceWith(new EchoTool()); - ToolExecutionResult result = service.execute("sample.cmm.value.echo", - headers(Map.of( - "requestId", "request-1", - "guid", "guid-1", - "mcpSessionId", "session-1", - "employeeNo", "employee-1", - "virtualEmployeeNo", "virtual-1", - "headerRequestId", "request-1", - "traceId", "guid-1", - "encryptedEmployeeId", "employee-1")), - Map.of("value", "hello")); - assertEquals(200, result.statusCode()); - assertEquals("hello", ((Map) result.body()).get("value")); - assertEquals("request-1", result.headers().get("x-request-id")); - assertEquals("guid-1", result.headers().get("guid")); - assertEquals("session-1", result.headers().get("mcp-session-id")); - } - - private McpRequestHeaders headers(Map values) { - try { - Class[] types = Arrays.stream(McpRequestHeaders.class.getRecordComponents()) - .map(component -> component.getType()) - .toArray(Class[]::new); - Object[] arguments = Arrays.stream(McpRequestHeaders.class.getRecordComponents()) - .map(component -> values.get(component.getName())) - .toArray(); - return McpRequestHeaders.class.getDeclaredConstructor(types).newInstance(arguments); - } catch (ReflectiveOperationException exception) { - throw new AssertionError(exception); - } - } - - private McpToolExecutionService serviceWith(Object toolBean) { - ObjectMapper objectMapper = new ObjectMapper(); - StaticApplicationContext context = new StaticApplicationContext(); - context.getBeanFactory().registerSingleton("toolBean", toolBean); - context.refresh(); - McpToolMethodRegistry registry = new McpToolMethodRegistry(context, new McpProperties()); - registry.initialize(); - return new McpToolExecutionService(registry, objectMapper, - new ToolArgumentSchemaValidator(objectMapper), new ToolSchemaResolver(objectMapper)); - } - - static class EchoTool { - @McpTool(name = "sample.cmm.value.echo", description = "Echoes a value") - @GrowToolHint - public Map execute(EchoRequest request) { - return Map.of("value", request.value); - } - } - - static class EchoRequest { - @McpToolParam(description = "Value", required = true) - private String value; - public String getValue() { return value; } - public void setValue(String value) { this.value = value; } - } -}