From 8d93f2e1618947c6db96a6f5c1f62ac876b5de68 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 18 May 2026 16:34:15 +0200 Subject: [PATCH] test(executors): aggiunta nuova directory di test per executors --- .../blocks/MCPAgentChatExecutorTest.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/test/java/it/cnr/isti/workflow/manager/executions/executors/blocks/MCPAgentChatExecutorTest.java diff --git a/src/test/java/it/cnr/isti/workflow/manager/executions/executors/blocks/MCPAgentChatExecutorTest.java b/src/test/java/it/cnr/isti/workflow/manager/executions/executors/blocks/MCPAgentChatExecutorTest.java new file mode 100644 index 0000000..2f664e8 --- /dev/null +++ b/src/test/java/it/cnr/isti/workflow/manager/executions/executors/blocks/MCPAgentChatExecutorTest.java @@ -0,0 +1,90 @@ +package it.cnr.isti.workflow.manager.executions.executors.blocks; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyNoInteractions; + +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.test.util.ReflectionTestUtils; + +import it.cnr.isti.workflow.manager.blocks.Block; +import it.cnr.isti.workflow.manager.blocks.configurations.MCPAgentChatBlockConfiguration; +import it.cnr.isti.workflow.manager.blocks.factories.MCPAgentChatBlockFactory; +import it.cnr.isti.workflow.manager.blocks.types.MCPAgentChatBlockType; +import it.cnr.isti.workflow.manager.executions.ExecutionEventLogger; +import it.cnr.isti.workflow.manager.executions.InteractionResult; +import it.cnr.isti.workflow.manager.mcp.MCPAgentService; + +class MCPAgentChatExecutorTest { + + private MCPAgentChatExecutor executor; + private MCPAgentService mcpAgentService; + + @BeforeEach + void setup() { + executor = new MCPAgentChatExecutor(); + mcpAgentService = mock(MCPAgentService.class); + ReflectionTestUtils.setField(executor, "mcpAgentService", mcpAgentService); + ReflectionTestUtils.setField(executor, "llmProviders", Map.of()); + } + + @Test + void cancelWithoutSessionIdDoesNotThrowAndDoesNotCloseSession() { + Block block = block(); + ExecutionEventLogger eventLogger = mock(ExecutionEventLogger.class); + + assertDoesNotThrow(() -> executor.cancel( + block, + List.of(), + Map.of(), + Map.of(), + Map.of(), + Map.of(), + eventLogger)); + + verifyNoInteractions(mcpAgentService); + verifyNoInteractions(eventLogger); + } + + @Test + void finalResponseWithoutSessionIdCompletesWithoutClosingSession() { + Block block = block(); + ExecutionEventLogger eventLogger = mock(ExecutionEventLogger.class); + + InteractionResult result = assertDoesNotThrow(() -> executor.interact( + block, + List.of(), + Map.of(MCPAgentChatBlockFactory.FINAL_RESPONSE_FIELD, "ok"), + Map.of(), + Map.of(), + Map.of(), + Map.of(), + eventLogger)); + + assertTrue(result.completed()); + assertEquals("ok", result.outputs().get(MCPAgentChatBlockFactory.RESPONSE_OUTPUT)); + assertTrue(result.outputs().containsKey(MCPAgentChatBlockFactory.HISTORY_OUTPUT)); + assertEquals(List.of(), result.outputs().get(MCPAgentChatBlockFactory.HISTORY_OUTPUT)); + verifyNoInteractions(mcpAgentService); + verifyNoInteractions(eventLogger); + } + + private Block block() { + MCPAgentChatBlockConfiguration configuration = MCPAgentChatBlockConfiguration.builder() + .name("chat") + .model("llama3") + .goalDescription("goal") + .build(); + + return Block.builder() + .specificConfiguration(configuration) + .type(new MCPAgentChatBlockType()) + .build(); + } +}