|
34 | 34 |
|
35 | 35 | public class HTTPWorkflowDefinitionTest { |
36 | 36 |
|
37 | | - private static WorkflowApplication appl; |
| 37 | + private static WorkflowApplication appl; |
38 | 38 |
|
39 | | - @BeforeAll |
40 | | - static void init() { |
41 | | - appl = WorkflowApplication.builder().build(); |
42 | | - } |
| 39 | + @BeforeAll |
| 40 | + static void init() { |
| 41 | + appl = WorkflowApplication.builder().build(); |
| 42 | + } |
43 | 43 |
|
44 | | - @AfterAll |
45 | | - static void cleanup() { |
46 | | - appl.close(); |
47 | | - } |
| 44 | + @AfterAll |
| 45 | + static void cleanup() { |
| 46 | + appl.close(); |
| 47 | + } |
48 | 48 |
|
49 | | - @ParameterizedTest |
50 | | - @MethodSource("provideParameters") |
51 | | - void testWorkflowExecution(String fileName, Object input, Condition<Object> condition) |
52 | | - throws IOException { |
53 | | - assertThat( |
54 | | - appl.workflowDefinition(readWorkflowFromClasspath(fileName)) |
55 | | - .instance(input) |
56 | | - .start() |
57 | | - .join()) |
58 | | - .is(condition); |
59 | | - } |
| 49 | + @ParameterizedTest |
| 50 | + @MethodSource("provideParameters") |
| 51 | + void testWorkflowExecution(String fileName, Object input, Condition<Object> condition) |
| 52 | + throws IOException { |
| 53 | + assertThat( |
| 54 | + appl.workflowDefinition(readWorkflowFromClasspath(fileName)) |
| 55 | + .instance(input) |
| 56 | + .start() |
| 57 | + .join()) |
| 58 | + .is(condition); |
| 59 | + } |
60 | 60 |
|
61 | | - @ParameterizedTest |
62 | | - @ValueSource( |
63 | | - strings = { |
64 | | - "workflows-samples/call-http-query-parameters.yaml", |
65 | | - "workflows-samples/call-http-query-parameters-external-schema.yaml" |
66 | | - }) |
67 | | - void testWrongSchema(String fileName) { |
68 | | - IllegalArgumentException exception = |
69 | | - catchThrowableOfType( |
70 | | - IllegalArgumentException.class, |
71 | | - () -> appl.workflowDefinition(readWorkflowFromClasspath(fileName)).instance(Map.of())); |
72 | | - assertThat(exception) |
73 | | - .isNotNull() |
74 | | - .hasMessageContaining("There are JsonSchema validation errors"); |
75 | | - } |
| 61 | + @ParameterizedTest |
| 62 | + @ValueSource( |
| 63 | + strings = { |
| 64 | + "workflows-samples/call-http-query-parameters.yaml", |
| 65 | + "workflows-samples/call-http-query-parameters-external-schema.yaml" |
| 66 | + }) |
| 67 | + void testWrongSchema(String fileName) { |
| 68 | + IllegalArgumentException exception = |
| 69 | + catchThrowableOfType( |
| 70 | + IllegalArgumentException.class, |
| 71 | + () -> appl.workflowDefinition(readWorkflowFromClasspath(fileName)).instance(Map.of())); |
| 72 | + assertThat(exception) |
| 73 | + .isNotNull() |
| 74 | + .hasMessageContaining("There are JsonSchema validation errors"); |
| 75 | + } |
76 | 76 |
|
77 | | - private static boolean httpCondition(WorkflowModel obj) { |
78 | | - Map<String, Object> map = obj.asMap().orElseThrow(); |
79 | | - return map.containsKey("photoUrls") || map.containsKey("petId"); |
80 | | - } |
| 77 | + private static boolean httpCondition(WorkflowModel obj) { |
| 78 | + Map<String, Object> map = obj.asMap().orElseThrow(); |
| 79 | + return map.containsKey("photoUrls") || map.containsKey("petId"); |
| 80 | + } |
81 | 81 |
|
82 | | - private static Stream<Arguments> provideParameters() { |
83 | | - Map<String, Object> petInput = Map.of("petId", 10); |
84 | | - Map<String, Object> starTrekInput = Map.of("uid", "MOMA0000092393"); |
85 | | - Condition<WorkflowModel> petCondition = |
86 | | - new Condition<>(HTTPWorkflowDefinitionTest::httpCondition, "callHttpCondition"); |
87 | | - Condition<WorkflowModel> starTrekCondition = |
88 | | - new Condition<>( |
89 | | - o -> |
90 | | - ((Map<String, Object>) o.asMap().orElseThrow().get("movie")) |
91 | | - .get("title") |
92 | | - .equals("Star Trek"), |
93 | | - "StartTrek"); |
94 | | - return Stream.of( |
95 | | - Arguments.of("workflows-samples/callGetHttp.yaml", petInput, petCondition), |
96 | | - Arguments.of( |
97 | | - "workflows-samples/callGetHttp.yaml", |
98 | | - Map.of("petId", "-1"), |
99 | | - new Condition<WorkflowModel>( |
100 | | - o -> o.asMap().orElseThrow().containsKey("petId"), "notFoundCondition")), |
101 | | - Arguments.of( |
102 | | - "workflows-samples/call-http-endpoint-interpolation.yaml", petInput, |
103 | | - petCondition), |
104 | | - Arguments.of( |
105 | | - "workflows-samples/call-http-query-parameters.yaml", starTrekInput, |
106 | | - starTrekCondition), |
107 | | - Arguments.of( |
108 | | - "workflows-samples/call-http-query-parameters-external-schema.yaml", |
109 | | - starTrekInput, |
110 | | - starTrekCondition), |
111 | | - Arguments.of( |
112 | | - "workflows-samples/callPostHttp.yaml", |
113 | | - Map.of("name", "Javierito", "surname", "Unknown"), |
114 | | - new Condition<WorkflowModel>( |
115 | | - o -> o.asText().orElseThrow().equals("Javierito"), "CallHttpPostCondition"))); |
116 | | - } |
| 82 | + private static Stream<Arguments> provideParameters() { |
| 83 | + Map<String, Object> petInput = Map.of("petId", 10); |
| 84 | + Map<String, Object> starTrekInput = Map.of("uid", "MOMA0000092393"); |
| 85 | + Condition<WorkflowModel> petCondition = |
| 86 | + new Condition<>(HTTPWorkflowDefinitionTest::httpCondition, "callHttpCondition"); |
| 87 | + Condition<WorkflowModel> starTrekCondition = |
| 88 | + new Condition<>( |
| 89 | + o -> |
| 90 | + ((Map<String, Object>) o.asMap().orElseThrow().get("movie")) |
| 91 | + .get("title") |
| 92 | + .equals("Star Trek"), |
| 93 | + "StartTrek"); |
| 94 | + return Stream.of( |
| 95 | + Arguments.of("workflows-samples/callGetHttp.yaml", petInput, petCondition), |
| 96 | + Arguments.of( |
| 97 | + "workflows-samples/callGetHttp.yaml", |
| 98 | + Map.of("petId", "-1"), |
| 99 | + new Condition<WorkflowModel>( |
| 100 | + o -> o.asMap().orElseThrow().containsKey("petId"), "notFoundCondition")), |
| 101 | + Arguments.of( |
| 102 | + "workflows-samples/call-http-endpoint-interpolation.yaml", petInput, petCondition), |
| 103 | + Arguments.of( |
| 104 | + "workflows-samples/call-http-query-parameters.yaml", starTrekInput, starTrekCondition), |
| 105 | + Arguments.of( |
| 106 | + "workflows-samples/call-http-query-parameters-external-schema.yaml", |
| 107 | + starTrekInput, |
| 108 | + starTrekCondition), |
| 109 | + Arguments.of( |
| 110 | + "workflows-samples/callPostHttp.yaml", |
| 111 | + Map.of("name", "Javierito", "surname", "Unknown"), |
| 112 | + new Condition<WorkflowModel>( |
| 113 | + o -> o.asText().orElseThrow().equals("Javierito"), "CallHttpPostCondition"))); |
| 114 | + } |
117 | 115 | } |
0 commit comments