diff --git a/fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ForEachTaskBuilder.java b/fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ForEachTaskBuilder.java index 196ed888e..21ef0e9bc 100644 --- a/fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ForEachTaskBuilder.java +++ b/fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ForEachTaskBuilder.java @@ -21,6 +21,7 @@ import io.serverlessworkflow.api.types.TaskItem; import io.serverlessworkflow.fluent.spec.spi.ForEachTaskFluent; import java.util.List; +import java.util.Objects; import java.util.function.Consumer; public class ForEachTaskBuilder> @@ -85,6 +86,8 @@ public ForEachTaskBuilder tasks(Consumer doBuilderConsumer) { public ForTask build() { this.forTask.setFor(this.forTaskConfiguration); + Objects.requireNonNull( + this.forTask.getFor().getIn(), "'in' is a required property for ForTask"); return this.forTask; } } diff --git a/fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java b/fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java index 4ba41c203..57af6a590 100644 --- a/fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java +++ b/fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java @@ -119,7 +119,7 @@ void testDoTaskSetAndForEach() { .tasks( d -> d.set("initCtx", "$.foo = 'bar'") - .forEach("item", f -> f.each("item").at("$.list"))) + .forEach("item", f -> f.each("item").at("index").in("$.list"))) .build(); List items = wf.getDo(); diff --git a/impl/test/src/test/java/io/serverlessworkflow/impl/test/ForTaskMissingInTest.java b/impl/test/src/test/java/io/serverlessworkflow/impl/test/ForTaskMissingInTest.java new file mode 100644 index 000000000..88c3a7a9b --- /dev/null +++ b/impl/test/src/test/java/io/serverlessworkflow/impl/test/ForTaskMissingInTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2020-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.serverlessworkflow.impl.test; + +import static io.serverlessworkflow.fluent.spec.dsl.DSL.*; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import io.serverlessworkflow.api.types.Workflow; +import io.serverlessworkflow.fluent.spec.WorkflowBuilder; +import org.junit.jupiter.api.Test; + +class ForTaskMissingInTest { + + @Test + void forTaskWithoutInShouldFailWithDescriptiveMessage() { + + assertThatThrownBy( + () -> { + Workflow ignored = + WorkflowBuilder.workflow("for-missing-in", "test", "0.1.0") + .tasks( + doTasks( + forEach( + "loopWithoutIn", + f -> + f.each("item") + .tasks(t -> t.set("noop", s -> s.put("done", true)))))) + .build(); + }) + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("'in' is a required property for ForTask"); + } +}