|
| 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 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 21 | + |
| 22 | +import io.serverlessworkflow.api.Workflow; |
| 23 | +import io.serverlessworkflow.api.events.EventDefinition; |
| 24 | +import io.serverlessworkflow.util.testutil.TestUtils; |
| 25 | +import io.serverlessworkflow.utils.WorkflowUtils; |
| 26 | +import java.util.List; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import org.junit.jupiter.params.ParameterizedTest; |
| 29 | +import org.junit.jupiter.params.provider.ValueSource; |
| 30 | + |
| 31 | +class DefinedEventsTest { |
| 32 | + @ParameterizedTest |
| 33 | + @ValueSource(strings = {"/events/workflowwithevents.yml"}) |
| 34 | + public void testGetDefinedConsumedEvents(String workflowEvents) { |
| 35 | + int consumedEventsCount = 2; |
| 36 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents); |
| 37 | + List<EventDefinition> consumedEvents = WorkflowUtils.getDefinedConsumedEvents(workflow); |
| 38 | + assertEquals(consumedEventsCount, consumedEvents.size()); |
| 39 | + } |
| 40 | + |
| 41 | + @ParameterizedTest |
| 42 | + @ValueSource(strings = {"/events/workflowwithevents.yml"}) |
| 43 | + public void testGetDefinedroducedEvents(String workflowEvents) { |
| 44 | + int producedEventsCounts = 1; |
| 45 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents); |
| 46 | + List<EventDefinition> producedEvents = WorkflowUtils.getDefinedProducedEvents(workflow); |
| 47 | + assertEquals(producedEventsCounts, producedEvents.size()); |
| 48 | + } |
| 49 | + |
| 50 | + @ParameterizedTest |
| 51 | + @ValueSource(strings = {"/events/workflowwithevents.yml"}) |
| 52 | + public void testGetDefinedConsumedEventsCount(String workflowEvents) { |
| 53 | + int consumedEventsCountExpected = 2; |
| 54 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents); |
| 55 | + int consumedEventsCount = WorkflowUtils.getDefinedConsumedEventsCount(workflow); |
| 56 | + assertEquals(consumedEventsCountExpected, consumedEventsCount); |
| 57 | + } |
| 58 | + |
| 59 | + @ParameterizedTest |
| 60 | + @ValueSource(strings = {"/events/workflowwithevents.yml"}) |
| 61 | + public void testGetDefinedroducedEventsCount(String workflowEvents) { |
| 62 | + int producedEventsCountExpected = 1; |
| 63 | + Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents); |
| 64 | + int producedEventsCount = WorkflowUtils.getDefinedProducedEventsCount(workflow); |
| 65 | + assertEquals(producedEventsCountExpected, producedEventsCount); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testGetDefinedEventsForNullWorkflow() { |
| 70 | + assertNull(WorkflowUtils.getDefinedEvents(null, EventDefinition.Kind.CONSUMED)); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testGetDefinedEventsCountForNullWorkflow() { |
| 75 | + int expectedCount = 0; |
| 76 | + assertEquals( |
| 77 | + expectedCount, WorkflowUtils.getDefinedEventsCount(null, EventDefinition.Kind.PRODUCED)); |
| 78 | + } |
| 79 | +} |
0 commit comments