File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
main/java/io/serverlessworkflow/utils
test/java/io/serverlessworkflow/util Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 29
29
import java .util .stream .Collectors ;
30
30
31
31
/** Provides common utility methods to provide most often needed answers from a workflow */
32
+ @ SuppressWarnings ("StreamToLoop" )
32
33
public final class WorkflowUtils {
33
34
private static final int DEFAULT_STARTING_STATE_POSITION = 0 ;
34
- private static final int DEFAULT_STATE_COUNT = 0 ;
35
+ private static final long DEFAULT_STATE_COUNT = 0 ;
35
36
36
37
/**
37
38
* Gets State matching Start state. If start is not present returns first state. If start is
@@ -268,21 +269,25 @@ public static List<Action> getActionsForFunctionDefinition(
268
269
269
270
/**
270
271
* Gets Num of State in the workflow does not consider child workflow
272
+ *
271
273
* @param workflow
272
274
* @return
273
275
*/
274
- public static int getNumOfStates (Workflow workflow ) {
276
+ public static long getNumOfStates (Workflow workflow ) {
275
277
return hasStates (workflow ) ? workflow .getStates ().size () : DEFAULT_STATE_COUNT ;
276
278
}
277
279
278
280
/**
281
+ * Gets Num of States for State Type
279
282
*
280
283
* @param workflow
281
284
* @param type
282
285
* @return
283
286
*/
284
- public static int getNumOfStates (Workflow workflow ,DefaultState .Type type ) {
285
- return hasStates (workflow ) ? workflow .getStates ().size () : DEFAULT_STATE_COUNT ;
287
+ public static long getNumOfStates (Workflow workflow , DefaultState .Type type ) {
288
+ return hasStates (workflow )
289
+ ? workflow .getStates ().stream ().filter (state -> state .getType () == type ).count ()
290
+ : DEFAULT_STATE_COUNT ;
286
291
}
287
292
288
293
private static List <Action > getActionsWhichUsesFunctionDefinition (
Original file line number Diff line number Diff line change 19
19
import static org .junit .jupiter .api .Assertions .assertEquals ;
20
20
21
21
import io .serverlessworkflow .api .Workflow ;
22
+ import io .serverlessworkflow .api .states .DefaultState ;
22
23
import io .serverlessworkflow .util .testutil .TestUtils ;
23
24
import io .serverlessworkflow .utils .WorkflowUtils ;
24
25
import org .junit .jupiter .params .ParameterizedTest ;
@@ -40,4 +41,13 @@ public void testGetNumStatesForNoStateInWorkflow(String workflowWithStates) {
40
41
int expectedStatesCount = 0 ;
41
42
assertEquals (expectedStatesCount , WorkflowUtils .getNumOfStates (workflow ));
42
43
}
44
+
45
+ @ ParameterizedTest
46
+ @ ValueSource (strings = {"/getStates/workflowwithstates.yml" })
47
+ public void testGetNumStatesOfEventType (String workflowWithStates ) {
48
+ Workflow workflow = TestUtils .createWorkflowFromTestResource (workflowWithStates );
49
+ int expectedStatesCount = 2 ;
50
+ assertEquals (
51
+ expectedStatesCount , WorkflowUtils .getNumOfStates (workflow , DefaultState .Type .EVENT ));
52
+ }
43
53
}
You can’t perform that action at this time.
0 commit comments