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 2929import java .util .stream .Collectors ;
3030
3131/** Provides common utility methods to provide most often needed answers from a workflow */
32+ @ SuppressWarnings ("StreamToLoop" )
3233public final class WorkflowUtils {
3334 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 ;
3536
3637 /**
3738 * 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(
268269
269270 /**
270271 * Gets Num of State in the workflow does not consider child workflow
272+ *
271273 * @param workflow
272274 * @return
273275 */
274- public static int getNumOfStates (Workflow workflow ) {
276+ public static long getNumOfStates (Workflow workflow ) {
275277 return hasStates (workflow ) ? workflow .getStates ().size () : DEFAULT_STATE_COUNT ;
276278 }
277279
278280 /**
281+ * Gets Num of States for State Type
279282 *
280283 * @param workflow
281284 * @param type
282285 * @return
283286 */
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 ;
286291 }
287292
288293 private static List <Action > getActionsWhichUsesFunctionDefinition (
Original file line number Diff line number Diff line change 1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020
2121import io .serverlessworkflow .api .Workflow ;
22+ import io .serverlessworkflow .api .states .DefaultState ;
2223import io .serverlessworkflow .util .testutil .TestUtils ;
2324import io .serverlessworkflow .utils .WorkflowUtils ;
2425import org .junit .jupiter .params .ParameterizedTest ;
@@ -40,4 +41,13 @@ public void testGetNumStatesForNoStateInWorkflow(String workflowWithStates) {
4041 int expectedStatesCount = 0 ;
4142 assertEquals (expectedStatesCount , WorkflowUtils .getNumOfStates (workflow ));
4243 }
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+ }
4353}
You can’t perform that action at this time.
0 commit comments