mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
This commit is contained in:
1 parent
16b0b516a0
commit
70921dea2c
8 files changed
+238
-40
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
package io.floci.aws.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
final class JsonataConstructedArrayFixtures {
|
||||
|
||||
private JsonataConstructedArrayFixtures() {
|
||||
}
|
||||
|
||||
static ObjectNode input(ObjectMapper mapper, int count) {
|
||||
ObjectNode input = mapper.createObjectNode();
|
||||
ArrayNode items = input.putArray("Items");
|
||||
for (int i = 0; i < count; i++) {
|
||||
items.addObject();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
static ObjectNode states(ObjectMapper mapper, int count) {
|
||||
return mapper.createObjectNode().set("input", input(mapper, count));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package io.floci.aws.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class JsonataConstructedArrayPathTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final JsonataEvaluator evaluator = new JsonataEvaluator(mapper);
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 3})
|
||||
void indexedConstructedObjectPathHasNoValueAndExistsIsFalse(int count) throws Exception {
|
||||
JsonNode states = JsonataConstructedArrayFixtures.states(mapper, count);
|
||||
assertTrue(evaluator.evaluate("{% [$states.input.Items.{'ok':true}][0].ok %}", states).isMissingNode());
|
||||
assertFalse(evaluator.evaluate("{% $exists([$states.input.Items.{'ok':true}][0].ok) %}", states).asBoolean());
|
||||
assertEquals(mapper.readTree("{}"),
|
||||
evaluator.evaluate("{% {'value':[$states.input.Items.{'ok':true}][0].ok} %}", states));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 3})
|
||||
void groupingTheConstructedArrayAllowsThePropertyRead(int count) throws Exception {
|
||||
JsonNode states = JsonataConstructedArrayFixtures.states(mapper, count);
|
||||
JsonNode grouped = evaluator.evaluate("{% ([$states.input.Items.{'ok':true}])[0].ok %}", states);
|
||||
if (count == 0) {
|
||||
assertTrue(grouped.isMissingNode());
|
||||
} else {
|
||||
assertTrue(grouped.asBoolean());
|
||||
assertEquals(mapper.readTree("{\"ok\":true}"),
|
||||
evaluator.evaluate("{% [$states.input.Items.{'ok':true}][0] %}", states));
|
||||
}
|
||||
assertEquals(count, evaluator.evaluate("{% [$states.input.Items.{'ok':true}] %}", states).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void forcedArraysAndMultipleResultsKeepTheirPathSemantics() throws Exception {
|
||||
JsonNode states = mapper.readTree("{\"input\":{\"Items\":[{\"a\":1},{\"a\":2}]}}");
|
||||
assertEquals("[1]", evaluator.evaluate("{% [$states.input.Items][0][].a %}", states).toString());
|
||||
assertEquals("[1,2]", evaluator.evaluate("{% [$states.input.Items][[0,1]].a %}", states).toString());
|
||||
assertEquals(mapper.readTree("[\"1\",\"2\"]"),
|
||||
evaluator.evaluate("{% [[1,2],[3]][0].$string() %}", states));
|
||||
assertEquals("[[{\"a\":1},{\"a\":2}]]",
|
||||
evaluator.evaluate("{% [[$states.input.Items]] %}", states).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void numericAndBooleanSingletonPathsAlsoHaveNoValue() throws Exception {
|
||||
JsonNode states = JsonataConstructedArrayFixtures.states(mapper, 1);
|
||||
assertTrue(evaluator.evaluate("{% [5][0].$string() %}", states).isMissingNode());
|
||||
assertFalse(evaluator.evaluate("{% $exists([true][0].x) %}", states).asBoolean());
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -32,11 +32,39 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 3})
|
||||
void existsOfAnIndexedConstructedObjectPathReturnsFalse(int count) throws Exception {
|
||||
String execution = startConstructedArrayExecution("exists", count,
|
||||
"{% $exists([$states.input.Items.{'ok':true}][0].ok) %}");
|
||||
assertFalse(objectMapper.readTree(waitForExecution(execution)).asBoolean());
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 3})
|
||||
void directIndexedConstructedObjectPathStillFailsAsUndefined(int count) throws Exception {
|
||||
String execution = startConstructedArrayExecution("undefined", count,
|
||||
"{% [$states.input.Items.{'ok':true}][0].ok %}");
|
||||
Response failure = waitForExecutionFailure(execution);
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertTrue(failure.jsonPath().getString("cause").contains("returned nothing (undefined)"));
|
||||
assertFalse(failure.jsonPath().getString("cause").contains("cannot be cast"));
|
||||
}
|
||||
|
||||
private String startConstructedArrayExecution(String name, int count, String expression) {
|
||||
ObjectNode definition = objectMapper.createObjectNode();
|
||||
definition.put("QueryLanguage", "JSONata").put("StartAt", "Probe");
|
||||
definition.putObject("States").putObject("Probe")
|
||||
.put("Type", "Pass").put("Output", expression).put("End", true);
|
||||
String machine = createStateMachine("jsonata-constructed-" + name + "-" + count, definition.toString());
|
||||
return startExecution(machine, JsonataConstructedArrayFixtures.input(objectMapper, count).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void passStateWithJsonataOutput() throws Exception {
|
||||
// A Pass state that transforms input using JSONata Output field
|
||||
|
||||
Reference in new issue
Block a user