Skip to content

Commit 00b02eb

Browse files
committed
[WIP] apply formatter
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 2c598b1 commit 00b02eb

File tree

2 files changed

+103
-104
lines changed

2 files changed

+103
-104
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunScriptExecutor.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
import io.serverlessworkflow.impl.WorkflowModelFactory;
3030
import io.serverlessworkflow.impl.WorkflowUtils;
3131
import io.serverlessworkflow.impl.expressions.ExpressionUtils;
32+
import io.serverlessworkflow.impl.resources.ResourceLoaderUtils;
3233
import java.io.ByteArrayOutputStream;
3334
import java.util.Arrays;
3435
import java.util.HashMap;
3536
import java.util.Map;
36-
import java.util.Objects;
3737
import java.util.concurrent.CompletableFuture;
3838
import java.util.concurrent.ExecutorService;
39-
40-
import io.serverlessworkflow.impl.resources.ResourceLoaderUtils;
4139
import org.graalvm.polyglot.Context;
4240
import org.graalvm.polyglot.PolyglotException;
4341
import org.graalvm.polyglot.Value;
@@ -95,18 +93,25 @@ public void init(RunScript taskConfiguration, WorkflowDefinition definition) {
9593

9694
fnExecutor =
9795
(workflowContext, taskContext) -> {
98-
99-
String source;
100-
if (scriptUnion.getInlineScript() != null) {
101-
source = scriptUnion.getInlineScript().getCode();
102-
} else if (scriptUnion.getExternalScript() == null) {
103-
throw new WorkflowException(WorkflowError.runtime(taskContext, new IllegalStateException(
104-
"No script source defined."
105-
)).build());
106-
} else {
107-
source = definition.resourceLoader().load(scriptUnion.getExternalScript().getSource(),
108-
ResourceLoaderUtils::readString, workflowContext, taskContext, taskContext.input());
109-
}
96+
String source;
97+
if (scriptUnion.getInlineScript() != null) {
98+
source = scriptUnion.getInlineScript().getCode();
99+
} else if (scriptUnion.getExternalScript() == null) {
100+
throw new WorkflowException(
101+
WorkflowError.runtime(
102+
taskContext, new IllegalStateException("No script source defined."))
103+
.build());
104+
} else {
105+
source =
106+
definition
107+
.resourceLoader()
108+
.load(
109+
scriptUnion.getExternalScript().getSource(),
110+
ResourceLoaderUtils::readString,
111+
workflowContext,
112+
taskContext,
113+
taskContext.input());
114+
}
110115

111116
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
112117
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
@@ -170,16 +175,12 @@ public void init(RunScript taskConfiguration, WorkflowDefinition definition) {
170175
if (!isAwait) {
171176
executorService.submit(
172177
() -> {
173-
context.eval(
174-
scriptUnion.getInlineScript().getLanguage(),
175-
source);
178+
context.eval(scriptUnion.getInlineScript().getLanguage(), source);
176179
});
177180
return application.modelFactory().fromAny(taskContext.input());
178181
}
179182

180-
context.eval(
181-
lowerLang,
182-
source);
183+
context.eval(lowerLang, source);
183184

184185
WorkflowModelFactory modelFactory = application.modelFactory();
185186

impl/test/src/test/java/io/serverlessworkflow/impl/test/RunShellScriptTest.java

Lines changed: 81 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,104 +19,102 @@
1919
import io.serverlessworkflow.api.types.Workflow;
2020
import io.serverlessworkflow.impl.WorkflowApplication;
2121
import io.serverlessworkflow.impl.WorkflowModel;
22+
import java.io.IOException;
23+
import java.util.Map;
2224
import okhttp3.mockwebserver.MockResponse;
2325
import okhttp3.mockwebserver.MockWebServer;
24-
import okio.Buffer;
2526
import org.assertj.core.api.SoftAssertions;
2627
import org.junit.jupiter.api.AfterEach;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.Test;
2930

30-
import java.io.IOException;
31-
import java.util.Map;
32-
3331
public class RunShellScriptTest {
3432

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+
});
4158
}
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+
});
4674
}
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+
});
6192
}
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+
"""
104105
console.log("hello from script");
105106
""")
106-
.setHeader("Content-Type", "application/javascript")
107-
.setResponseCode(200)
108-
);
107+
.setHeader("Content-Type", "application/javascript")
108+
.setResponseCode(200));
109109

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();
112112

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+
});
121118
}
119+
}
122120
}

0 commit comments

Comments
 (0)