1616package io .serverlessworkflow .fluent .agentic ;
1717
1818import static io .serverlessworkflow .fluent .agentic .Agents .*;
19+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newConflictAgent ;
20+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newCultureAgent ;
21+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newFactAgent ;
22+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newHeroAgent ;
23+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newPlotAgent ;
24+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newSceneAgent ;
25+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newSettingAgent ;
26+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newStorySeedAgent ;
27+ import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newTechnologyAgent ;
1928import static org .junit .jupiter .api .Assertions .assertEquals ;
2029import static org .mockito .ArgumentMatchers .eq ;
30+ import static org .mockito .Mockito .doReturn ;
2131import static org .mockito .Mockito .mock ;
2232import static org .mockito .Mockito .when ;
2333
@@ -38,9 +48,12 @@ class WorkflowTests {
3848
3949 @ Test
4050 public void testAgent () throws ExecutionException , InterruptedException {
41- final StorySeedAgent storySeedAgent = mock (StorySeedAgent .class );
51+ final StorySeedAgent storySeedAgent = newStorySeedAgent ();
52+
53+ doReturn ("storySeedAgent" )
54+ .when (storySeedAgent )
55+ .invoke (org .mockito .ArgumentMatchers .anyString ());
4256
43- when (storySeedAgent .invoke (eq ("A Great Story" ))).thenReturn ("storySeedAgent" );
4457 when (storySeedAgent .outputKey ()).thenReturn ("premise" );
4558 when (storySeedAgent .name ()).thenReturn ("storySeedAgent" );
4659
@@ -67,21 +80,23 @@ public void testAgent() throws ExecutionException, InterruptedException {
6780
6881 @ Test
6982 public void testAgents () throws ExecutionException , InterruptedException {
70- final StorySeedAgent storySeedAgent = mock ( StorySeedAgent . class );
71- final PlotAgent plotAgent = mock ( PlotAgent . class );
72- final SceneAgent sceneAgent = mock ( SceneAgent . class );
83+ final StorySeedAgent storySeedAgent = newStorySeedAgent ( );
84+ final PlotAgent plotAgent = newPlotAgent ( );
85+ final SceneAgent sceneAgent = newSceneAgent ( );
7386
74- when (storySeedAgent .invoke (eq ("A Great Story" ))).thenReturn ("storySeedAgent" );
7587 when (storySeedAgent .outputKey ()).thenReturn ("premise" );
7688 when (storySeedAgent .name ()).thenReturn ("storySeedAgent" );
89+ doReturn ("storySeedAgent" )
90+ .when (storySeedAgent )
91+ .invoke (org .mockito .ArgumentMatchers .anyString ());
7792
78- when (plotAgent .invoke (eq ("storySeedAgent" ))).thenReturn ("plotAgent" );
7993 when (plotAgent .outputKey ()).thenReturn ("plot" );
8094 when (plotAgent .name ()).thenReturn ("plotAgent" );
95+ doReturn ("plotAgent" ).when (plotAgent ).invoke (org .mockito .ArgumentMatchers .anyString ());
8196
82- when (sceneAgent .invoke (eq ("plotAgent" ))).thenReturn ("sceneAgent" );
8397 when (sceneAgent .outputKey ()).thenReturn ("story" );
8498 when (sceneAgent .name ()).thenReturn ("sceneAgent" );
99+ doReturn ("sceneAgent" ).when (sceneAgent ).invoke (org .mockito .ArgumentMatchers .anyString ());
85100
86101 Workflow workflow =
87102 AgentWorkflowBuilder .workflow ("storyFlow" )
@@ -110,21 +125,25 @@ public void testAgents() throws ExecutionException, InterruptedException {
110125
111126 @ Test
112127 public void testSequence () throws ExecutionException , InterruptedException {
113- final StorySeedAgent storySeedAgent = mock ( StorySeedAgent . class );
114- final PlotAgent plotAgent = mock ( PlotAgent . class );
115- final SceneAgent sceneAgent = mock ( SceneAgent . class );
128+ final StorySeedAgent storySeedAgent = newStorySeedAgent ( );
129+ final PlotAgent plotAgent = newPlotAgent ( );
130+ final SceneAgent sceneAgent = newSceneAgent ( );
116131
117- when (storySeedAgent .invoke (eq ("A Great Story" ))).thenReturn ("storySeedAgent" );
118132 when (storySeedAgent .outputKey ()).thenReturn ("premise" );
119133 when (storySeedAgent .name ()).thenReturn ("storySeedAgent" );
120134
121- when (plotAgent .invoke (eq ("storySeedAgent" ))).thenReturn ("plotAgent" );
135+ doReturn ("storySeedAgent" )
136+ .when (storySeedAgent )
137+ .invoke (org .mockito .ArgumentMatchers .anyString ());
138+
122139 when (plotAgent .outputKey ()).thenReturn ("plot" );
123140 when (plotAgent .name ()).thenReturn ("plotAgent" );
124141
125- when (sceneAgent .invoke (eq ("plotAgent" ))).thenReturn ("sceneAgent" );
142+ doReturn ("plotAgent" ).when (plotAgent ).invoke (org .mockito .ArgumentMatchers .anyString ());
143+
126144 when (sceneAgent .outputKey ()).thenReturn ("story" );
127145 when (sceneAgent .name ()).thenReturn ("sceneAgent" );
146+ doReturn ("sceneAgent" ).when (sceneAgent ).invoke (org .mockito .ArgumentMatchers .anyString ());
128147
129148 Workflow workflow =
130149 AgentWorkflowBuilder .workflow ("storyFlow" )
@@ -149,22 +168,25 @@ public void testSequence() throws ExecutionException, InterruptedException {
149168
150169 @ Test
151170 public void testParallel () throws ExecutionException , InterruptedException {
171+ final SettingAgent setting = newSettingAgent ();
172+ final HeroAgent hero = newHeroAgent ();
173+ final ConflictAgent conflict = newConflictAgent ();
152174
153- final SettingAgent setting = mock (SettingAgent .class );
154- final HeroAgent hero = mock (HeroAgent .class );
155- final ConflictAgent conflict = mock (ConflictAgent .class );
156-
157- when (setting .invoke (eq ("sci-fi" ))).thenReturn ("Fake conflict response" );
158175 when (setting .outputKey ()).thenReturn ("setting" );
159176 when (setting .name ()).thenReturn ("setting" );
177+ doReturn ("Fake setting response" )
178+ .when (setting )
179+ .invoke (org .mockito .ArgumentMatchers .anyString ());
160180
161- when (hero .invoke (eq ("sci-fi" ))).thenReturn ("Fake hero response" );
162181 when (hero .outputKey ()).thenReturn ("hero" );
163182 when (hero .name ()).thenReturn ("hero" );
183+ doReturn ("Fake hero response" ).when (hero ).invoke (org .mockito .ArgumentMatchers .anyString ());
164184
165- when (conflict .invoke (eq ("sci-fi" ))).thenReturn ("Fake setting response" );
166185 when (conflict .outputKey ()).thenReturn ("conflict" );
167186 when (conflict .name ()).thenReturn ("conflict" );
187+ doReturn ("Fake conflict response" )
188+ .when (conflict )
189+ .invoke (org .mockito .ArgumentMatchers .anyString ());
168190
169191 Workflow workflow =
170192 AgentWorkflowBuilder .workflow ("parallelFlow" )
@@ -178,9 +200,9 @@ public void testParallel() throws ExecutionException, InterruptedException {
178200 Map <String , Object > result =
179201 app .workflowDefinition (workflow ).instance (topic ).start ().get ().asMap ().orElseThrow ();
180202
181- assertEquals ("Fake conflict response" , result .get ("setting" ).toString ());
203+ assertEquals ("Fake setting response" , result .get ("setting" ).toString ());
182204 assertEquals ("Fake hero response" , result .get ("hero" ).toString ());
183- assertEquals ("Fake setting response" , result .get ("conflict" ).toString ());
205+ assertEquals ("Fake conflict response" , result .get ("conflict" ).toString ());
184206 }
185207
186208 try (WorkflowApplication app = WorkflowApplication .builder ().build ()) {
@@ -192,35 +214,40 @@ public void testParallel() throws ExecutionException, InterruptedException {
192214 .as (AgenticScope .class )
193215 .orElseThrow ();
194216
195- assertEquals ("Fake conflict response" , result .readState ("setting" ).toString ());
217+ assertEquals ("Fake setting response" , result .readState ("setting" ).toString ());
196218 assertEquals ("Fake hero response" , result .readState ("hero" ).toString ());
197- assertEquals ("Fake setting response" , result .readState ("conflict" ).toString ());
219+ assertEquals ("Fake conflict response" , result .readState ("conflict" ).toString ());
198220 }
199221 }
200222
201223 @ Test
202224 public void testSeqAndThenParallel () throws ExecutionException , InterruptedException {
203- final FactAgent factAgent = mock ( FactAgent . class );
204- final CultureAgent cultureAgent = mock ( CultureAgent . class );
205- final TechnologyAgent technologyAgent = mock ( TechnologyAgent . class );
225+ final FactAgent factAgent = newFactAgent ( );
226+ final CultureAgent cultureAgent = newCultureAgent ( );
227+ final TechnologyAgent technologyAgent = newTechnologyAgent ( );
206228
207229 List <String > cultureTraits =
208230 List .of ("Alien Culture Trait 1" , "Alien Culture Trait 2" , "Alien Culture Trait 3" );
209231
210232 List <String > technologyTraits =
211233 List .of ("Alien Technology Trait 1" , "Alien Technology Trait 2" , "Alien Technology Trait 3" );
212234
213- when (factAgent .invoke (eq ("alien" ))).thenReturn ("Some Fact about aliens" );
214235 when (factAgent .outputKey ()).thenReturn ("fact" );
215236 when (factAgent .name ()).thenReturn ("fact" );
237+ doReturn ("Some Fact about aliens" )
238+ .when (factAgent )
239+ .invoke (org .mockito .ArgumentMatchers .anyString ());
216240
217- when (cultureAgent .invoke (eq ("Some Fact about aliens" ))).thenReturn (cultureTraits );
218241 when (cultureAgent .outputKey ()).thenReturn ("culture" );
219242 when (cultureAgent .name ()).thenReturn ("culture" );
243+ doReturn (cultureTraits ).when (cultureAgent ).invoke (org .mockito .ArgumentMatchers .anyString ());
220244
221- when (technologyAgent .invoke (eq ("Some Fact about aliens" ))).thenReturn (technologyTraits );
222245 when (technologyAgent .outputKey ()).thenReturn ("technology" );
223246 when (technologyAgent .name ()).thenReturn ("technology" );
247+ doReturn (technologyTraits )
248+ .when (technologyAgent )
249+ .invoke (org .mockito .ArgumentMatchers .anyString ());
250+
224251 Workflow workflow =
225252 AgentWorkflowBuilder .workflow ("alienCultureFlow" )
226253 .tasks (
0 commit comments