|
| 1 | +/* |
| 2 | + * Copyright 2020-Present The Serverless Workflow Specification Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.serverlessworkflow.util; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | + |
| 21 | +import io.serverlessworkflow.api.Workflow; |
| 22 | +import io.serverlessworkflow.api.states.DefaultState; |
| 23 | +import io.serverlessworkflow.util.testutil.TestUtils; |
| 24 | +import io.serverlessworkflow.utils.WorkflowUtils; |
| 25 | +import org.junit.jupiter.params.ParameterizedTest; |
| 26 | +import org.junit.jupiter.params.provider.ValueSource; |
| 27 | + |
| 28 | +public class GetNumTests { |
| 29 | + @ParameterizedTest |
| 30 | + @ValueSource(strings = {"/getStates/workflowwithstates.yml"}) |
| 31 | + public void testGetNumStates(String workflowWithStates) { |
| 32 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowWithStates); |
| 33 | + int expectedStatesCount = 2; |
| 34 | + assertEquals(expectedStatesCount, WorkflowUtils.getNumOfStates(workflow)); |
| 35 | + } |
| 36 | + |
| 37 | + @ParameterizedTest |
| 38 | + @ValueSource(strings = {"/start/workflowwithnostate.yml"}) |
| 39 | + public void testGetNumStatesForNoStateInWorkflow(String workflowWithStates) { |
| 40 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowWithStates); |
| 41 | + int expectedStatesCount = 0; |
| 42 | + assertEquals(expectedStatesCount, WorkflowUtils.getNumOfStates(workflow)); |
| 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 | + } |
| 53 | +} |
0 commit comments