1818
1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020import static org .junit .jupiter .api .Assertions .assertNotNull ;
21+ import static org .junit .jupiter .api .Assertions .assertSame ;
2122import 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 ;
2227import static org .mockito .Mockito .lenient ;
2328import static org .mockito .Mockito .mock ;
29+ import static org .mockito .Mockito .verify ;
2430import static org .mockito .Mockito .when ;
2531
32+ import com .bytechef .component .definition .ClusterElementContext ;
2633import com .bytechef .component .definition .ClusterElementDefinition .ClusterElementType ;
2734import com .bytechef .component .definition .ComponentDefinition ;
35+ import com .bytechef .component .definition .Parameters ;
36+ import com .bytechef .platform .component .ComponentConnection ;
2837import com .bytechef .platform .component .ComponentDefinitionRegistry ;
2938import com .bytechef .platform .component .context .ContextFactory ;
39+ import com .bytechef .platform .component .definition .ai .agent .MultipleConnectionsToolFunction ;
3040import com .bytechef .platform .component .domain .ClusterElementDefinition ;
3141import java .util .List ;
42+ import java .util .Map ;
3243import java .util .Optional ;
3344import org .junit .jupiter .api .BeforeEach ;
3445import 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