Skip to content

Commit 2397b88

Browse files
authored
Merge pull request #196 from fjtirado/constant_ref_value
Constanst.setRefValue() was always null
2 parents 96cc7a6 + a924fe0 commit 2397b88

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

api/src/main/java/io/serverlessworkflow/api/deserializers/ConstantsDeserializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public Constants deserialize(JsonParser jp, DeserializationContext ctxt) throws
6262
constantsDefinition = node;
6363
} else {
6464
String constantsFileDef = node.asText();
65+
constants.setRefValue(constantsFileDef);
6566
String constantsFileSrc = Utils.getResourceFileAsString(constantsFileDef);
6667
JsonNode constantsRefNode;
6768
ObjectMapper jsonWriter = new ObjectMapper();

api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,13 @@ public void serialize(Workflow workflow, JsonGenerator gen, SerializerProvider p
159159
gen.writeEndArray();
160160
}
161161

162-
if (workflow.getConstants() != null && !workflow.getConstants().getConstantsDef().isEmpty()) {
163-
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
162+
if (workflow.getConstants() != null) {
163+
if (workflow.getConstants().getConstantsDef() != null
164+
&& !workflow.getConstants().getConstantsDef().isEmpty()) {
165+
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
166+
} else if (workflow.getConstants().getRefValue() != null) {
167+
gen.writeStringField("constants", workflow.getConstants().getRefValue());
168+
}
164169
}
165170

166171
if (workflow.getTimeouts() != null) {

api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,21 @@ public void testConstants(String workflowLocation) {
570570
assertEquals("pas", serbianTranslationNode.asText());
571571
}
572572

573+
@ParameterizedTest
574+
@ValueSource(strings = {"/features/constantsRef.json", "/features/constantsRef.yml"})
575+
public void testConstantsRef(String workflowLocation) {
576+
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
577+
578+
assertNotNull(workflow);
579+
assertNotNull(workflow.getId());
580+
assertNotNull(workflow.getName());
581+
assertNotNull(workflow.getStates());
582+
583+
assertNotNull(workflow.getConstants());
584+
Constants constants = workflow.getConstants();
585+
assertEquals("constantValues.json", constants.getRefValue());
586+
}
587+
573588
@ParameterizedTest
574589
@ValueSource(strings = {"/features/timeouts.json", "/features/timeouts.yml"})
575590
public void testTimeouts(String workflowLocation) {

api/src/test/java/io/serverlessworkflow/api/test/WorkflowToMarkupTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.serverlessworkflow.api.start.Start;
3333
import io.serverlessworkflow.api.states.SleepState;
3434
import io.serverlessworkflow.api.workflow.Auth;
35+
import io.serverlessworkflow.api.workflow.Constants;
3536
import io.serverlessworkflow.api.workflow.Events;
3637
import io.serverlessworkflow.api.workflow.Functions;
3738
import java.util.Arrays;
@@ -47,6 +48,7 @@ public void testSingleState() {
4748
.withName("test-workflow-name")
4849
.withVersion("1.0")
4950
.withStart(new Start().withSchedule(new Schedule().withInterval("PT1S")))
51+
.withConstants(new Constants("constantsValues.json"))
5052
.withStates(
5153
Arrays.asList(
5254
new SleepState()
@@ -62,11 +64,13 @@ public void testSingleState() {
6264

6365
assertNotNull(workflow);
6466
assertNotNull(workflow.getStart());
67+
Constants constants = workflow.getConstants();
68+
assertNotNull(constants);
69+
assertEquals("constantsValues.json", constants.getRefValue());
6570
assertEquals(1, workflow.getStates().size());
6671
State state = workflow.getStates().get(0);
6772
assertTrue(state instanceof SleepState);
6873
assertNotNull(state.getEnd());
69-
7074
assertNotNull(Workflow.toJson(workflow));
7175
assertNotNull(Workflow.toYaml(workflow));
7276
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "secrets",
3+
"version": "1.0",
4+
"specVersion": "0.8",
5+
"name": "Custom secrets flow",
6+
"expressionLang": "abc",
7+
"start": "TestFunctionRefs",
8+
"constants": "constantValues.json",
9+
"states": [
10+
{
11+
"name": "TestFunctionRefs",
12+
"type": "operation",
13+
"actions": [],
14+
"end": true
15+
}
16+
]
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
id: secrets
2+
version: '1.0'
3+
specVersion: '0.8'
4+
name: Custom secrets flow
5+
expressionLang: abc
6+
start: TestFunctionRefs
7+
constants:
8+
constantValues.json
9+
states:
10+
- name: TestFunctionRefs
11+
type: operation
12+
actionMode: sequential
13+
actions:
14+
end: true

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy