Skip to content

Commit 1d7838d

Browse files
authored
[NO-ISSUE] Add instance() method with no argument (serverlessworkflow#1338)
* Add convenience no-arg instance() method for WorkflowDefinition Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Change Map.of to null Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Use spotless Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> --------- Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 99a360d commit 1d7838d

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public WorkflowInstance instance(Object input) {
129129
return new WorkflowMutableInstance(this, application().idFactory().get(), inputModel);
130130
}
131131

132+
public WorkflowInstance instance() {
133+
return instance(null);
134+
}
135+
132136
Optional<SchemaValidator> inputSchemaValidator() {
133137
return inputSchemaValidator;
134138
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void testOpenAPIBearerQueryInlinedBodyWithPositiveResponse() throws Excep
149149
.setResponseCode(201));
150150

151151
Map<String, Object> result =
152-
app.workflowDefinition(workflow).instance(Map.of()).start().get().asMap().orElseThrow();
152+
app.workflowDefinition(workflow).instance().start().get().asMap().orElseThrow();
153153

154154
RecordedRequest restRequest = restServer.takeRequest();
155155
assertEquals("POST", restRequest.getMethod());
@@ -194,13 +194,7 @@ public void testOpenAPIBearerQueryInlinedBodyWithNegativeResponse() throws Excep
194194
Exception exception =
195195
assertThrows(
196196
Exception.class,
197-
() ->
198-
app.workflowDefinition(workflow)
199-
.instance(Map.of())
200-
.start()
201-
.get()
202-
.asMap()
203-
.orElseThrow());
197+
() -> app.workflowDefinition(workflow).instance().start().get().asMap().orElseThrow());
204198
assertInstanceOf(WorkflowException.class, exception.getCause());
205199
assertTrue(exception.getMessage().contains("status=409"));
206200

@@ -244,11 +238,11 @@ public void testOpenAPIGetWithPositiveResponse() throws Exception {
244238
.setResponseCode(200));
245239

246240
WorkflowDefinition definition = app.workflowDefinition(workflow);
247-
assertData(definition.instance(Map.of()).start().get().asMap().orElseThrow());
241+
assertData(definition.instance().start().get().asMap().orElseThrow());
248242
RecordedRequest openAPIRequest = openApiServer.takeRequest();
249243
assertEquals("GET", openAPIRequest.getMethod());
250244

251-
assertData(definition.instance(Map.of()).start().get().asMap().orElseThrow());
245+
assertData(definition.instance().start().get().asMap().orElseThrow());
252246
openAPIRequest = openApiServer.takeRequest();
253247
assertEquals("HEAD", openAPIRequest.getMethod());
254248
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ public void setTest() throws Exception {
4141
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
4242
app.workflowDefinition(workflowChild);
4343
Map<String, Object> result =
44-
app.workflowDefinition(workflowParent)
45-
.instance(Map.of())
46-
.start()
47-
.join()
48-
.asMap()
49-
.orElseThrow();
44+
app.workflowDefinition(workflowParent).instance().start().join().asMap().orElseThrow();
5045
assertThat(result.get("counter"), is(equalTo(1)));
5146
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
5247
}
@@ -62,12 +57,7 @@ public void setBlankInputTest() throws Exception {
6257
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
6358
app.workflowDefinition(workflowChild);
6459
Map<String, Object> result =
65-
app.workflowDefinition(workflowParent)
66-
.instance(Map.of())
67-
.start()
68-
.join()
69-
.asMap()
70-
.orElseThrow();
60+
app.workflowDefinition(workflowParent).instance().start().join().asMap().orElseThrow();
7161
assertThat(result.get("counter"), is(equalTo(1)));
7262
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
7363
}
@@ -153,7 +143,7 @@ public void runSubWorkflowFromDslTest() throws Exception {
153143
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
154144
app.workflowDefinition(child);
155145
Map<String, Object> result =
156-
app.workflowDefinition(parent).instance(Map.of()).start().join().asMap().orElseThrow();
146+
app.workflowDefinition(parent).instance().start().join().asMap().orElseThrow();
157147
assertThat(result.get("counter"), is(equalTo(1)));
158148
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
159149
}
@@ -181,7 +171,7 @@ public void runSubWorkflowsFromDslTest() throws Exception {
181171
app.workflowDefinition(child);
182172
app.workflowDefinition(update);
183173
Map<String, Object> result =
184-
app.workflowDefinition(parent).instance(Map.of()).start().join().asMap().orElseThrow();
174+
app.workflowDefinition(parent).instance().start().join().asMap().orElseThrow();
185175
assertThat(result.get("counter"), is(equalTo(2)));
186176
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
187177
}

0 commit comments

Comments
 (0)