Skip to content

Commit 858dbbe

Browse files
ivicacclaude
andcommitted
4761 Add test for MultipleConnectionsToolFunction dispatch in executeTool
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b2eb3ed commit 858dbbe

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

server/libs/platform/platform-component/platform-component-service/src/test/java/com/bytechef/platform/component/service/ClusterElementDefinitionServiceTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,28 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertSame;
2122
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
import static org.mockito.ArgumentMatchers.any;
24+
import static org.mockito.ArgumentMatchers.anyBoolean;
25+
import static org.mockito.ArgumentMatchers.eq;
26+
import static org.mockito.ArgumentMatchers.isNull;
2227
import static org.mockito.Mockito.lenient;
2328
import static org.mockito.Mockito.mock;
29+
import static org.mockito.Mockito.verify;
2430
import static org.mockito.Mockito.when;
2531

32+
import com.bytechef.component.definition.ClusterElementContext;
2633
import com.bytechef.component.definition.ClusterElementDefinition.ClusterElementType;
2734
import com.bytechef.component.definition.ComponentDefinition;
35+
import com.bytechef.component.definition.Parameters;
36+
import com.bytechef.platform.component.ComponentConnection;
2837
import com.bytechef.platform.component.ComponentDefinitionRegistry;
2938
import com.bytechef.platform.component.context.ContextFactory;
39+
import com.bytechef.platform.component.definition.ai.agent.MultipleConnectionsToolFunction;
3040
import com.bytechef.platform.component.domain.ClusterElementDefinition;
3141
import java.util.List;
42+
import java.util.Map;
3243
import java.util.Optional;
3344
import org.junit.jupiter.api.BeforeEach;
3445
import org.junit.jupiter.api.Test;
@@ -179,7 +190,48 @@ void testGetClusterElementDefinitionWithNonMatchingNameThrowsException() {
179190
exception.getMessage());
180191
}
181192

182-
@SuppressWarnings("unchecked")
193+
@Test
194+
void testExecuteToolDispatchesMultipleConnectionsToolFunction() throws Exception {
195+
String clusterElementName = "aiAgent";
196+
Object expectedResult = new Object();
197+
198+
MultipleConnectionsToolFunction toolFunction = mock(MultipleConnectionsToolFunction.class);
199+
200+
when(toolFunction.apply(any(), any(), any(), any(), any())).thenReturn(expectedResult);
201+
202+
com.bytechef.component.definition.ClusterElementDefinition<?> elementDefinition =
203+
mock(com.bytechef.component.definition.ClusterElementDefinition.class);
204+
205+
when(elementDefinition.getName()).thenReturn(clusterElementName);
206+
when(elementDefinition.getElement()).thenAnswer(ignored -> toolFunction);
207+
208+
ComponentDefinition componentDefinition = mock(ComponentDefinition.class);
209+
210+
when(componentDefinition.getClusterElements()).thenReturn(Optional.of(List.of(elementDefinition)));
211+
when(componentDefinitionRegistry.getComponentDefinition(COMPONENT_NAME, COMPONENT_VERSION))
212+
.thenReturn(componentDefinition);
213+
214+
ClusterElementContext clusterElementContext = mock(ClusterElementContext.class);
215+
216+
when(contextFactory.createClusterElementContext(
217+
eq(COMPONENT_NAME), eq(COMPONENT_VERSION), eq(clusterElementName), isNull(), anyBoolean()))
218+
.thenReturn(clusterElementContext);
219+
220+
Map<String, ?> inputParameters = Map.of("userPrompt", "hi");
221+
Map<String, ?> extensions = Map.of("ext", "v");
222+
Map<String, ComponentConnection> componentConnections = Map.of();
223+
224+
Object result = clusterElementDefinitionService.executeTool(
225+
COMPONENT_NAME, COMPONENT_VERSION, clusterElementName, inputParameters, extensions, componentConnections,
226+
true);
227+
228+
assertSame(expectedResult, result);
229+
230+
verify(toolFunction).apply(
231+
any(Parameters.class), any(Parameters.class), any(Parameters.class), eq(componentConnections),
232+
eq(clusterElementContext));
233+
}
234+
183235
private com.bytechef.component.definition.ClusterElementDefinition<?> createMatchableClusterElementDefinition(
184236
String name, ClusterElementType type) {
185237

@@ -197,7 +249,6 @@ private com.bytechef.component.definition.ClusterElementDefinition<?> createMatc
197249
return elementDefinition;
198250
}
199251

200-
@SuppressWarnings("unchecked")
201252
private com.bytechef.component.definition.ClusterElementDefinition<?> createFilterOnlyClusterElementDefinition(
202253
String name, ClusterElementType type) {
203254

0 commit comments

Comments
 (0)