From 64ed7bd33f3265def181ff6d0006b910062cafe3 Mon Sep 17 00:00:00 2001 From: Filip Artur Kowalski Date: Tue, 31 Aug 2021 20:56:55 +0200 Subject: [PATCH] #146 Implement transitions alias (#150) * #146 Implement transitions alias * remove unnecesarry handlers * #146 Adjust tests for transitions atlas * #146 Adjust tests for ontransitions * Revert " #146 Adjust tests for ontransitions" This reverts commit 9a4a4e95 * #146 Fix line endings * #146 Fix line endings Co-authored-by: filip.kowalski --- .../default/docs/asciidoc/dataobjects.adoc | 4 +++ .../factory/generic/GraphNodeOptions.java | 12 ++++++++ .../factory/generic/GraphNodeOptionsTest.java | 28 +++++++++++++++++-- .../conf/taskWithTransitions-alias.conf | 7 +++++ .../conf/taskWithTransitionsAndAlias.conf | 12 ++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 task/factory/default/src/test/resources/conf/taskWithTransitions-alias.conf create mode 100644 task/factory/default/src/test/resources/conf/taskWithTransitionsAndAlias.conf diff --git a/task/factory/default/docs/asciidoc/dataobjects.adoc b/task/factory/default/docs/asciidoc/dataobjects.adoc index cbdf9686..78d82402 100644 --- a/task/factory/default/docs/asciidoc/dataobjects.adoc +++ b/task/factory/default/docs/asciidoc/dataobjects.adoc @@ -92,6 +92,10 @@ Sets a node factory name to SubtasksNodeFactory.NAME and configures |[[node]]`@node`|`link:dataobjects.html#NodeOptions[NodeOptions]`|+++ Node options define a node factory and its configuration. +++ +|[[on]]`@on`|`link:dataobjects.html#GraphNodeOptions[GraphNodeOptions]`|+++ +Alias for "onTransitions". + See link ++++ |[[onTransitions]]`@onTransitions`|`link:dataobjects.html#GraphNodeOptions[GraphNodeOptions]`|+++ The outgoing graph node edges, called transitions. A transition is named graph edge that defines the next graph node in fragment's processing. diff --git a/task/factory/default/src/main/java/io/knotx/fragments/task/factory/generic/GraphNodeOptions.java b/task/factory/default/src/main/java/io/knotx/fragments/task/factory/generic/GraphNodeOptions.java index 25c31193..c42becba 100644 --- a/task/factory/default/src/main/java/io/knotx/fragments/task/factory/generic/GraphNodeOptions.java +++ b/task/factory/default/src/main/java/io/knotx/fragments/task/factory/generic/GraphNodeOptions.java @@ -115,6 +115,18 @@ public GraphNodeOptions setOnTransitions(Map onTransit return this; } + /** + * Alias for "onTransitions". + * See {@link #setOnTransitions(Map) setOnTransitions} + * + * @param on - map of possible transitions + * @return reference to this, so the API can be used fluently + */ + public GraphNodeOptions setOn(Map on) { + this.onTransitions = on; + return this; + } + /** * Sets a node factory name to {@code ActionNodeFactory.NAME} and configures the action. * diff --git a/task/factory/default/src/test/java/io/knotx/fragments/task/factory/generic/GraphNodeOptionsTest.java b/task/factory/default/src/test/java/io/knotx/fragments/task/factory/generic/GraphNodeOptionsTest.java index c63b93cf..2b77bd5d 100644 --- a/task/factory/default/src/test/java/io/knotx/fragments/task/factory/generic/GraphNodeOptionsTest.java +++ b/task/factory/default/src/test/java/io/knotx/fragments/task/factory/generic/GraphNodeOptionsTest.java @@ -17,10 +17,8 @@ import static io.knotx.junit5.util.HoconLoader.verify; import static io.knotx.fragments.api.FragmentResult.SUCCESS_TRANSITION; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; -import io.knotx.fragments.task.factory.generic.GraphNodeOptions; import io.knotx.fragments.task.factory.generic.node.action.ActionNodeConfig; import io.knotx.fragments.task.factory.generic.node.action.ActionNodeFactory; import io.knotx.fragments.task.factory.generic.node.subtasks.SubtasksNodeConfig; @@ -28,6 +26,8 @@ import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; import io.vertx.junit5.VertxExtension; + +import java.util.Map; import java.util.Optional; import java.util.function.Consumer; import org.junit.jupiter.api.DisplayName; @@ -87,6 +87,28 @@ void expectTransitionSuccessWithNodeBThenNodeC(Vertx vertx) throws Throwable { }, vertx); } + @Test + @DisplayName("Expect 'on' to alias 'onTransitions'") + void expectAssignedTransitions(Vertx vertx) throws Throwable { + verify("conf/taskWithTransitions-alias.conf", config -> { + GraphNodeOptions graphNodeOptions = new GraphNodeOptions(config); + Map transitions = graphNodeOptions.getOnTransitions(); + + assertFalse(transitions.isEmpty()); + }, vertx); + } + + @Test + @DisplayName("Expect 'onTransitions' to take precedence over 'on' alias") + void expectAliasToTakePrecedence(Vertx vertx) throws Throwable { + verify("conf/taskWithTransitionsAndAlias.conf", config -> { + GraphNodeOptions graphNodeOptions = new GraphNodeOptions(config); + Map transitions = graphNodeOptions.getOnTransitions(); + + assertEquals(transitions.size(), 1); + assertNotNull(transitions.get("_error")); + }, vertx); + } private Consumer validateActionNode() { return config -> { diff --git a/task/factory/default/src/test/resources/conf/taskWithTransitions-alias.conf b/task/factory/default/src/test/resources/conf/taskWithTransitions-alias.conf new file mode 100644 index 00000000..b24ed568 --- /dev/null +++ b/task/factory/default/src/test/resources/conf/taskWithTransitions-alias.conf @@ -0,0 +1,7 @@ +# node & transitions +action = a +on { + _success { + action = b + } +} \ No newline at end of file diff --git a/task/factory/default/src/test/resources/conf/taskWithTransitionsAndAlias.conf b/task/factory/default/src/test/resources/conf/taskWithTransitionsAndAlias.conf new file mode 100644 index 00000000..3825b4dc --- /dev/null +++ b/task/factory/default/src/test/resources/conf/taskWithTransitionsAndAlias.conf @@ -0,0 +1,12 @@ +# node & transitions +action = a +on { + _success { + action = b + } +} +onTransitions { + _error { + action = b + } +}