|
1 | 1 | package io.temporal.springai.plugin; |
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 6 | import static org.mockito.ArgumentMatchers.any; |
5 | 7 | import static org.mockito.Mockito.atLeastOnce; |
6 | 8 | import static org.mockito.Mockito.mock; |
@@ -43,9 +45,32 @@ void discoversMcpClientBeansByType() { |
43 | 45 | verify(worker, atLeastOnce()).registerActivitiesImplementations(captor.capture()); |
44 | 46 | Object registered = captor.getValue(); |
45 | 47 | assertEquals(McpClientActivityImpl.class, registered.getClass()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void twoMcpBeans_duplicateClientInfoNames_throws() { |
| 52 | + // Two distinct beans that both report the same clientInfo().name() — the activity impl |
| 53 | + // has to reject this because it keys its internal client map by that name. |
| 54 | + McpSyncClient clientA = mockClientNamed("shared"); |
| 55 | + McpSyncClient clientB = mockClientNamed("shared"); |
| 56 | + |
| 57 | + Map<String, McpSyncClient> beans = new LinkedHashMap<>(); |
| 58 | + beans.put("mcpClientA", clientA); |
| 59 | + beans.put("mcpClientB", clientB); |
| 60 | + |
| 61 | + ApplicationContext ctx = mock(ApplicationContext.class); |
| 62 | + when(ctx.getBeansOfType(McpSyncClient.class)).thenReturn(beans); |
| 63 | + |
| 64 | + McpPlugin plugin = new McpPlugin(); |
| 65 | + plugin.setApplicationContext(ctx); |
46 | 66 |
|
47 | | - // Duplicate-name protection in McpClientActivityImpl still fires if two clients share a |
48 | | - // clientInfo().name(); here they differ ("alpha" vs "beta") so construction succeeds. |
| 67 | + IllegalArgumentException thrown = |
| 68 | + assertThrows( |
| 69 | + IllegalArgumentException.class, |
| 70 | + () -> plugin.initializeWorker("mcp-tq", mock(Worker.class))); |
| 71 | + assertTrue( |
| 72 | + thrown.getMessage().contains("shared"), |
| 73 | + "expected duplicate name in message, got: " + thrown.getMessage()); |
49 | 74 | } |
50 | 75 |
|
51 | 76 | @Test |
|
0 commit comments