Skip to content

Constanst.setRefValue() was always null #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Constants deserialize(JsonParser jp, DeserializationContext ctxt) throws
constantsDefinition = node;
} else {
String constantsFileDef = node.asText();
constants.setRefValue(constantsFileDef);
String constantsFileSrc = Utils.getResourceFileAsString(constantsFileDef);
JsonNode constantsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,13 @@ public void serialize(Workflow workflow, JsonGenerator gen, SerializerProvider p
gen.writeEndArray();
}

if (workflow.getConstants() != null && !workflow.getConstants().getConstantsDef().isEmpty()) {
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
if (workflow.getConstants() != null) {
if (workflow.getConstants().getConstantsDef() != null
&& !workflow.getConstants().getConstantsDef().isEmpty()) {
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
} else if (workflow.getConstants().getRefValue() != null) {
gen.writeStringField("constants", workflow.getConstants().getRefValue());
}
}

if (workflow.getTimeouts() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,21 @@ public void testConstants(String workflowLocation) {
assertEquals("pas", serbianTranslationNode.asText());
}

@ParameterizedTest
@ValueSource(strings = {"/features/constantsRef.json", "/features/constantsRef.yml"})
public void testConstantsRef(String workflowLocation) {
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));

assertNotNull(workflow);
assertNotNull(workflow.getId());
assertNotNull(workflow.getName());
assertNotNull(workflow.getStates());

assertNotNull(workflow.getConstants());
Constants constants = workflow.getConstants();
assertEquals("constantValues.json", constants.getRefValue());
}

@ParameterizedTest
@ValueSource(strings = {"/features/timeouts.json", "/features/timeouts.yml"})
public void testTimeouts(String workflowLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.serverlessworkflow.api.start.Start;
import io.serverlessworkflow.api.states.SleepState;
import io.serverlessworkflow.api.workflow.Auth;
import io.serverlessworkflow.api.workflow.Constants;
import io.serverlessworkflow.api.workflow.Events;
import io.serverlessworkflow.api.workflow.Functions;
import java.util.Arrays;
Expand All @@ -47,6 +48,7 @@ public void testSingleState() {
.withName("test-workflow-name")
.withVersion("1.0")
.withStart(new Start().withSchedule(new Schedule().withInterval("PT1S")))
.withConstants(new Constants("constantsValues.json"))
.withStates(
Arrays.asList(
new SleepState()
Expand All @@ -62,11 +64,13 @@ public void testSingleState() {

assertNotNull(workflow);
assertNotNull(workflow.getStart());
Constants constants = workflow.getConstants();
assertNotNull(constants);
assertEquals("constantsValues.json", constants.getRefValue());
assertEquals(1, workflow.getStates().size());
State state = workflow.getStates().get(0);
assertTrue(state instanceof SleepState);
assertNotNull(state.getEnd());

assertNotNull(Workflow.toJson(workflow));
assertNotNull(Workflow.toYaml(workflow));
}
Expand Down
17 changes: 17 additions & 0 deletions api/src/test/resources/features/constantsRef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "secrets",
"version": "1.0",
"specVersion": "0.8",
"name": "Custom secrets flow",
"expressionLang": "abc",
"start": "TestFunctionRefs",
"constants": "constantValues.json",
"states": [
{
"name": "TestFunctionRefs",
"type": "operation",
"actions": [],
"end": true
}
]
}
14 changes: 14 additions & 0 deletions api/src/test/resources/features/constantsRef.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: secrets
version: '1.0'
specVersion: '0.8'
name: Custom secrets flow
expressionLang: abc
start: TestFunctionRefs
constants:
constantValues.json
states:
- name: TestFunctionRefs
type: operation
actionMode: sequential
actions:
end: true