|
19 | 19 | import io.serverlessworkflow.api.types.Workflow; |
20 | 20 | import io.serverlessworkflow.impl.WorkflowApplication; |
21 | 21 | import io.serverlessworkflow.impl.WorkflowModel; |
| 22 | +import java.io.IOException; |
| 23 | +import java.util.Map; |
22 | 24 | import okhttp3.mockwebserver.MockResponse; |
23 | 25 | import okhttp3.mockwebserver.MockWebServer; |
24 | | -import okio.Buffer; |
25 | 26 | import org.assertj.core.api.SoftAssertions; |
26 | 27 | import org.junit.jupiter.api.AfterEach; |
27 | 28 | import org.junit.jupiter.api.BeforeEach; |
28 | 29 | import org.junit.jupiter.api.Test; |
29 | 30 |
|
30 | | -import java.io.IOException; |
31 | | -import java.util.Map; |
32 | | - |
33 | 31 | public class RunShellScriptTest { |
34 | 32 |
|
35 | | - private MockWebServer fileServer; |
36 | | - |
37 | | - @BeforeEach |
38 | | - void setUp() throws IOException { |
39 | | - fileServer = new MockWebServer(); |
40 | | - fileServer.start(8886); |
| 33 | + private MockWebServer fileServer; |
| 34 | + |
| 35 | + @BeforeEach |
| 36 | + void setUp() throws IOException { |
| 37 | + fileServer = new MockWebServer(); |
| 38 | + fileServer.start(8886); |
| 39 | + } |
| 40 | + |
| 41 | + @AfterEach |
| 42 | + void tearDown() throws IOException { |
| 43 | + fileServer.shutdown(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + void testConsoleLog() throws IOException { |
| 48 | + Workflow workflow = |
| 49 | + WorkflowReader.readWorkflowFromClasspath("workflows-samples/run-script/console-log.yaml"); |
| 50 | + try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
| 51 | + WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
| 52 | + |
| 53 | + SoftAssertions.assertSoftly( |
| 54 | + softly -> { |
| 55 | + softly.assertThat(model.asText()).isPresent(); |
| 56 | + softly.assertThat(model.asText().get()).isEqualTo("hello from script"); |
| 57 | + }); |
41 | 58 | } |
42 | | - |
43 | | - @AfterEach |
44 | | - void tearDown() throws IOException { |
45 | | - fileServer.shutdown(); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void testConsoleLogWithArgs() throws IOException { |
| 63 | + Workflow workflow = |
| 64 | + WorkflowReader.readWorkflowFromClasspath( |
| 65 | + "workflows-samples/run-script/console-log-args.yaml"); |
| 66 | + try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
| 67 | + WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
| 68 | + |
| 69 | + SoftAssertions.assertSoftly( |
| 70 | + softly -> { |
| 71 | + softly.assertThat(model.asText()).isPresent(); |
| 72 | + softly.assertThat(model.asText().get()).isEqualTo("Hello, world!"); |
| 73 | + }); |
46 | 74 | } |
47 | | - |
48 | | - @Test |
49 | | - void testConsoleLog() throws IOException { |
50 | | - Workflow workflow = |
51 | | - WorkflowReader.readWorkflowFromClasspath("workflows-samples/run-script/console-log.yaml"); |
52 | | - try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
53 | | - WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
54 | | - |
55 | | - SoftAssertions.assertSoftly( |
56 | | - softly -> { |
57 | | - softly.assertThat(model.asText()).isPresent(); |
58 | | - softly.assertThat(model.asText().get()).isEqualTo("hello from script"); |
59 | | - }); |
60 | | - } |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void testConsoleLogWithEnvs() throws IOException { |
| 79 | + Workflow workflow = |
| 80 | + WorkflowReader.readWorkflowFromClasspath( |
| 81 | + "workflows-samples/run-script/console-log-envs.yaml"); |
| 82 | + try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
| 83 | + WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
| 84 | + |
| 85 | + SoftAssertions.assertSoftly( |
| 86 | + softly -> { |
| 87 | + softly.assertThat(model.asText()).isPresent(); |
| 88 | + softly |
| 89 | + .assertThat(model.asText().get()) |
| 90 | + .isEqualTo("Running JavaScript code using Serverless Workflow!"); |
| 91 | + }); |
61 | 92 | } |
62 | | - |
63 | | - @Test |
64 | | - void testConsoleLogWithArgs() throws IOException { |
65 | | - Workflow workflow = |
66 | | - WorkflowReader.readWorkflowFromClasspath( |
67 | | - "workflows-samples/run-script/console-log-args.yaml"); |
68 | | - try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
69 | | - WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
70 | | - |
71 | | - SoftAssertions.assertSoftly( |
72 | | - softly -> { |
73 | | - softly.assertThat(model.asText()).isPresent(); |
74 | | - softly.assertThat(model.asText().get()).isEqualTo("Hello, world!"); |
75 | | - }); |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - @Test |
80 | | - void testConsoleLogWithEnvs() throws IOException { |
81 | | - Workflow workflow = |
82 | | - WorkflowReader.readWorkflowFromClasspath( |
83 | | - "workflows-samples/run-script/console-log-envs.yaml"); |
84 | | - try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
85 | | - WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
86 | | - |
87 | | - SoftAssertions.assertSoftly( |
88 | | - softly -> { |
89 | | - softly.assertThat(model.asText()).isPresent(); |
90 | | - softly |
91 | | - .assertThat(model.asText().get()) |
92 | | - .isEqualTo("Running JavaScript code using Serverless Workflow!"); |
93 | | - }); |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - @Test |
98 | | - void testConsoleLogWithExternalSource() throws IOException { |
99 | | - Workflow workflow = |
100 | | - WorkflowReader.readWorkflowFromClasspath( |
101 | | - "workflows-samples/run-script/console-log-external-source.yaml"); |
102 | | - |
103 | | - fileServer.enqueue(new MockResponse().setBody(""" |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void testConsoleLogWithExternalSource() throws IOException { |
| 97 | + Workflow workflow = |
| 98 | + WorkflowReader.readWorkflowFromClasspath( |
| 99 | + "workflows-samples/run-script/console-log-external-source.yaml"); |
| 100 | + |
| 101 | + fileServer.enqueue( |
| 102 | + new MockResponse() |
| 103 | + .setBody( |
| 104 | + """ |
104 | 105 | console.log("hello from script"); |
105 | 106 | """) |
106 | | - .setHeader("Content-Type", "application/javascript") |
107 | | - .setResponseCode(200) |
108 | | - ); |
| 107 | + .setHeader("Content-Type", "application/javascript") |
| 108 | + .setResponseCode(200)); |
109 | 109 |
|
110 | | - try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
111 | | - WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
| 110 | + try (WorkflowApplication appl = WorkflowApplication.builder().build()) { |
| 111 | + WorkflowModel model = appl.workflowDefinition(workflow).instance(Map.of()).start().join(); |
112 | 112 |
|
113 | | - SoftAssertions.assertSoftly( |
114 | | - softly -> { |
115 | | - softly.assertThat(model.asText()).isPresent(); |
116 | | - softly |
117 | | - .assertThat(model.asText().get()) |
118 | | - .isEqualTo("hello from script"); |
119 | | - }); |
120 | | - } |
| 113 | + SoftAssertions.assertSoftly( |
| 114 | + softly -> { |
| 115 | + softly.assertThat(model.asText()).isPresent(); |
| 116 | + softly.assertThat(model.asText().get()).isEqualTo("hello from script"); |
| 117 | + }); |
121 | 118 | } |
| 119 | + } |
122 | 120 | } |
0 commit comments