Skip to content

Commit

Permalink
fix(engine): Preserve input type within for strategy (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbenyoussef authored Oct 29, 2024
1 parent 941ea6e commit 1043a71
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ private Object index(String indexName, Integer index, Object value) {
return index(indexName, index, (List) value);
}

return index(indexName, index, (String) value);
if (value instanceof String) {
return index(indexName, index, (String) value);
}

return value;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.chutneytesting.tools.Jsons;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.BooleanNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -222,6 +224,20 @@ public void should_preserve_input_types() {
assertThat(iterationWithList.status).isEqualTo(SUCCESS);
assertThat(iterationWithList.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).isInstanceOf(ArrayNode.class);
assertDoesNotThrow(() -> ZonedDateTime.parse(((ArrayNode) iterationWithList.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).elements().next().asText()));

StepExecutionReportDto iterationWithBoolean = result.steps.get(2);
assertThat(iterationWithBoolean.steps).hasSize(2);
assertThat(iterationWithBoolean.status).isEqualTo(SUCCESS);
assertThat(iterationWithBoolean.steps.get(0).context.stepResults.get("bool")).isInstanceOf(BooleanNode.class);
assertThat(iterationWithBoolean.steps.get(0).context.stepResults.get("bool_0")).isInstanceOf(BooleanNode.class);
assertThat(((BooleanNode) iterationWithBoolean.steps.get(0).context.stepResults.get("bool_0")).asBoolean()).isEqualTo(true);

StepExecutionReportDto iterationWithInteger = result.steps.get(3);
assertThat(iterationWithInteger.steps).hasSize(2);
assertThat(iterationWithInteger.status).isEqualTo(SUCCESS);
assertThat(iterationWithInteger.steps.get(0).context.stepResults.get("integer1")).isInstanceOf(IntNode.class);
assertThat(iterationWithInteger.steps.get(0).context.stepResults.get("int_0")).isInstanceOf(IntNode.class);
assertThat(((IntNode) iterationWithInteger.steps.get(0).context.stepResults.get("int_0")).asInt()).isEqualTo(3);
}

@Test
Expand Down Expand Up @@ -301,23 +317,23 @@ public void should_accept_nested_loops_and_override_dataset() {
assertThat(firstIteration.steps.get(0).name).startsWith("0 -");
assertThat(firstIteration.steps.get(0).context.stepResults).containsKey("environment_0.0");
assertThat(firstIteration.steps.get(0).context.stepResults.get("environment_0.0")).isInstanceOf(TextNode.class);
assertThat(((TextNode)firstIteration.steps.get(0).context.stepResults.get("environment_0.0")).asText()).isEqualTo("overriddenEnvX");
assertThat(((TextNode) firstIteration.steps.get(0).context.stepResults.get("environment_0.0")).asText()).isEqualTo("overriddenEnvX");
assertThat(firstIteration.steps.get(1).name).startsWith("1 -");
assertThat(firstIteration.steps.get(1).context.stepResults).containsKey("environment_0.1");
assertThat(firstIteration.steps.get(1).context.stepResults.get("environment_0.1")).isInstanceOf(TextNode.class);
assertThat(((TextNode)firstIteration.steps.get(1).context.stepResults.get("environment_0.1")).asText()).isEqualTo("overriddenEnvY");
assertThat(((TextNode) firstIteration.steps.get(1).context.stepResults.get("environment_0.1")).asText()).isEqualTo("overriddenEnvY");

// And the second iteration contains 2 nested iterations
StepExecutionReportDto secondIteration = parentIterativeStep.steps.get(1).steps.get(0);
assertThat(secondIteration.steps).hasSize(2);
assertThat(secondIteration.steps.get(0).name).startsWith("0 -");
assertThat(secondIteration.steps.get(0).context.stepResults).containsKey("environment_1.0");
assertThat(secondIteration.steps.get(0).context.stepResults.get("environment_1.0")).isInstanceOf(TextNode.class);
assertThat(((TextNode)secondIteration.steps.get(0).context.stepResults.get("environment_1.0")).asText()).isEqualTo("overriddenEnvX");
assertThat(((TextNode) secondIteration.steps.get(0).context.stepResults.get("environment_1.0")).asText()).isEqualTo("overriddenEnvX");
assertThat(secondIteration.steps.get(1).name).startsWith("1 -");
assertThat(secondIteration.steps.get(1).context.stepResults).containsKey("environment_1.1");
assertThat(secondIteration.steps.get(1).context.stepResults.get("environment_1.1")).isInstanceOf(TextNode.class);
assertThat(((TextNode)secondIteration.steps.get(1).context.stepResults.get("environment_1.1")).asText()).contains("overriddenEnvY");
assertThat(((TextNode) secondIteration.steps.get(1).context.stepResults.get("environment_1.1")).asText()).contains("overriddenEnvY");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,45 @@
"dataset": "${#dataset}"
}
}
},
{
"name": "Preserve boolean inputs",
"type": "context-put",
"inputs": {
"entries": {
"bool": true
}
},
"outputs": {
"bool_<i>": "${#bool}"
},
"strategy": {
"type": "for",
"parameters": {
"index": "i",
"dataset": "${#dataset}"
}
}
},
{
"name": "Preserve integer inputs",
"type": "context-put",
"inputs": {
"entries": {
"integer1": 1,
"integer2": 2
}
},
"outputs": {
"int_<i>": "${#integer1 + #integer2}"
},
"strategy": {
"type": "for",
"parameters": {
"index": "i",
"dataset": "${#dataset}"
}
}
}
]
},
Expand Down

0 comments on commit 1043a71

Please sign in to comment.