diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/expressions/ObjectExpressionFactory.java b/impl/core/src/main/java/io/serverlessworkflow/impl/expressions/ObjectExpressionFactory.java index 2362246d..8d849753 100644 --- a/impl/core/src/main/java/io/serverlessworkflow/impl/expressions/ObjectExpressionFactory.java +++ b/impl/core/src/main/java/io/serverlessworkflow/impl/expressions/ObjectExpressionFactory.java @@ -43,7 +43,7 @@ private Object buildExpressionObject(Object obj, ExpressionFactory factory) { } else if (obj instanceof Map map) { return buildExpressionMap(map, factory); } else if (obj instanceof Collection col) { - return buildExpressionList(col, factory); + return buildExpressionCollection(col, factory); } else { return obj; } @@ -84,7 +84,7 @@ private Map buildExpressionMap( : buildExpressionObject(o, factory)); } - private Collection buildExpressionList( + private Collection buildExpressionCollection( Collection col, ExpressionFactory factory) { return new ProxyCollection( col, diff --git a/impl/jackson/src/test/java/io/serverlessworkflow/impl/expressions/jq/JQExpressionFactoryTest.java b/impl/jackson/src/test/java/io/serverlessworkflow/impl/expressions/jq/JQExpressionFactoryTest.java index 4a72893c..b78d5ff7 100644 --- a/impl/jackson/src/test/java/io/serverlessworkflow/impl/expressions/jq/JQExpressionFactoryTest.java +++ b/impl/jackson/src/test/java/io/serverlessworkflow/impl/expressions/jq/JQExpressionFactoryTest.java @@ -25,41 +25,23 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; class JQExpressionFactoryTest { - @Test - void testNestedMap() { - WorkflowContext workflowContext = Mockito.mock(WorkflowContext.class); - JQExpressionFactory factory = new JQExpressionFactory(); - WorkflowValueResolver> expr = - factory.resolveMap( - ExpressionDescriptor.object( - Map.of( - "name", - "${.name}", - "surname", - "Doe", - "nested", - Map.of("name", "${.name}", "surname", "Doe")))); - Map result = - expr.apply( - workflowContext, - null, - new JacksonModel(JsonUtils.mapper().createObjectNode().put("name", "John"))); - assertThat(result.get("name")).isEqualTo("John"); - assertThat(result.get("surname")).isEqualTo("Doe"); - Map nested = (Map) result.get("nested"); - assertThat(result.get("name")).isEqualTo("John"); - assertThat(result.get("surname")).isEqualTo("Doe"); + private WorkflowContext workflowContext; + private JQExpressionFactory factory; + + @BeforeEach + void setup() { + workflowContext = Mockito.mock(WorkflowContext.class); + factory = new JQExpressionFactory(); } @Test - void testNestedArray() { - WorkflowContext workflowContext = Mockito.mock(WorkflowContext.class); - JQExpressionFactory factory = new JQExpressionFactory(); + void testArrayExpression() { WorkflowValueResolver> expr = factory.resolveMap( ExpressionDescriptor.object( @@ -78,20 +60,32 @@ void testNestedArray() { } @Test - void testList() { - WorkflowContext workflowContext = Mockito.mock(WorkflowContext.class); - JQExpressionFactory factory = new JQExpressionFactory(); + void testNesterMapAndArrayTogether() { WorkflowValueResolver> expr = factory.resolveMap( - ExpressionDescriptor.object(Map.of("array", List.of("item1", "item2", "${.name}")))); + ExpressionDescriptor.object( + Map.of( + "name", + "${.name}", + "surname", + "Doe", + "nested", + Map.of("name", "${.name}", "surname", "Doe"), + "array", + List.of("item1", "item2", "${.name}")))); Map result = expr.apply( workflowContext, null, - new JacksonModel(JsonUtils.mapper().createObjectNode().put("name", "item3"))); + new JacksonModel(JsonUtils.mapper().createObjectNode().put("name", "John"))); Iterator iter = ((Collection) result.get("array")).iterator(); assertThat(iter.next()).isEqualTo("item1"); assertThat(iter.next()).isEqualTo("item2"); - assertThat(iter.next()).isEqualTo("item3"); + assertThat(iter.next()).isEqualTo("John"); + assertThat(result.get("name")).isEqualTo("John"); + assertThat(result.get("surname")).isEqualTo("Doe"); + Map nested = (Map) result.get("nested"); + assertThat(result.get("name")).isEqualTo("John"); + assertThat(result.get("surname")).isEqualTo("Doe"); } }