|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertSame; |
21 | 22 | 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; |
22 | 27 | import static org.mockito.Mockito.lenient; |
23 | 28 | import static org.mockito.Mockito.mock; |
| 29 | +import static org.mockito.Mockito.verify; |
24 | 30 | import static org.mockito.Mockito.when; |
25 | 31 |
|
| 32 | +import com.bytechef.component.definition.ClusterElementContext; |
26 | 33 | import com.bytechef.component.definition.ClusterElementDefinition.ClusterElementType; |
27 | 34 | import com.bytechef.component.definition.ComponentDefinition; |
| 35 | +import com.bytechef.component.definition.Parameters; |
| 36 | +import com.bytechef.platform.component.ComponentConnection; |
28 | 37 | import com.bytechef.platform.component.ComponentDefinitionRegistry; |
29 | 38 | import com.bytechef.platform.component.context.ContextFactory; |
| 39 | +import com.bytechef.platform.component.definition.ai.agent.MultipleConnectionsToolFunction; |
30 | 40 | import com.bytechef.platform.component.domain.ClusterElementDefinition; |
31 | 41 | import java.util.List; |
| 42 | +import java.util.Map; |
32 | 43 | import java.util.Optional; |
33 | 44 | import org.junit.jupiter.api.BeforeEach; |
34 | 45 | import org.junit.jupiter.api.Test; |
@@ -179,6 +190,48 @@ void testGetClusterElementDefinitionWithNonMatchingNameThrowsException() { |
179 | 190 | exception.getMessage()); |
180 | 191 | } |
181 | 192 |
|
| 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 | + |
182 | 235 | @SuppressWarnings("unchecked") |
183 | 236 | private com.bytechef.component.definition.ClusterElementDefinition<?> createMatchableClusterElementDefinition( |
184 | 237 | String name, ClusterElementType type) { |
|
0 commit comments