test(executors): aggiunta nuova directory di test per executors

This commit is contained in:
Lucio Lelii 2026-05-18 16:34:15 +02:00
parent 63e30ab850
commit 8d93f2e161
1 changed files with 90 additions and 0 deletions

View File

@ -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<MCPAgentChatBlockType> 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<MCPAgentChatBlockType> 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<MCPAgentChatBlockType> block() {
MCPAgentChatBlockConfiguration configuration = MCPAgentChatBlockConfiguration.builder()
.name("chat")
.model("llama3")
.goalDescription("goal")
.build();
return Block.<MCPAgentChatBlockType>builder()
.specificConfiguration(configuration)
.type(new MCPAgentChatBlockType())
.build();
}
}