Skip to content

Commit

Permalink
#146 Implement transitions alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Voycawojka committed Apr 7, 2020
1 parent 629d5f6 commit d1e5df6
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 2 deletions.
4 changes: 4 additions & 0 deletions handler/core/docs/asciidoc/dataobjects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ Sets a node factory name to <code>SubtasksNodeFactory.NAME</code> 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.
Expand Down
25 changes: 25 additions & 0 deletions handler/core/handler/common/customTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tasks {
success-task {
action = success-action
}
}

nodeFactories = [
{
factory = action
config {
actions {
success-action {
factory = test-action
config {
transition = _success
body = "custom"
}
}
}
}
}
{
factory = subtasks
}
]
24 changes: 24 additions & 0 deletions handler/core/handler/common/failingTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tasks {
failing-task {
action = failing-action
}
}

nodeFactories = [
{
factory = action
config {
actions {
failing-action {
factory = test-action
config {
transition = not-existing-transition
}
}
}
}
}
{
factory = subtasks
}
]
25 changes: 25 additions & 0 deletions handler/core/handler/common/successTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tasks {
success-task {
action = success-action
}
}

nodeFactories = [
{
factory = action
config {
actions {
success-action {
factory = test-action
config {
transition = _success
body = "success"
}
}
}
}
}
{
factory = subtasks
}
]
25 changes: 25 additions & 0 deletions handler/core/handler/common/successTaskWithHtmlBody.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tasks {
success-task {
action = success-action
}
}

nodeFactories = [
{
factory = action
config {
actions {
success-action {
factory = test-action
config {
transition = _success
body = "<div>success</div>"
}
}
}
}
}
{
factory = subtasks
}
]
12 changes: 12 additions & 0 deletions handler/core/handler/consumerFactoryFound.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/successTask.conf")) }
}
]

consumerFactories = [
{
factory = testConsumer
}
]
4 changes: 4 additions & 0 deletions handler/core/handler/consumerFactoryNameNotDefined.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
consumerFactories = [
{
}
]
5 changes: 5 additions & 0 deletions handler/core/handler/consumerFactoryNotFound.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
consumerFactories = [
{
factory = invalid
}
]
Empty file.
6 changes: 6 additions & 0 deletions handler/core/handler/fragmentWithFailingTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/failingTask.conf")) }
}
]
18 changes: 18 additions & 0 deletions handler/core/handler/fragmentWithHtmlConsumer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/successTask.conf")) }
}
]

consumerFactories = [
{
factory = fragmentHtmlBodyWriter
config {
condition {
param = debug
}
fragmentTypes = [ "snippet" ]
}
}
]
6 changes: 6 additions & 0 deletions handler/core/handler/fragmentWithSuccessTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/successTask.conf")) }
}
]
13 changes: 13 additions & 0 deletions handler/core/handler/manyTaskFactoriesWithTheSameName.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
taskFactories = [
{
factory = default
config {include required(classpath("handler/common/successTask.conf"))}
}
{
factory = default
config {include required(classpath("handler/common/customTask.conf"))}
config {
taskNameKey = task
}
}
]
6 changes: 6 additions & 0 deletions handler/core/handler/singleTaskFactoryWithFailingTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/failingTask.conf")) }
}
]
6 changes: 6 additions & 0 deletions handler/core/handler/singleTaskFactoryWithSuccessTask.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
taskFactories = [
{
factory = default
config { include required(classpath("handler/common/successTask.conf")) }
}
]
4 changes: 4 additions & 0 deletions handler/core/handler/taskFactoryNameNotDefined.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
taskFactories = [
{
}
]
5 changes: 5 additions & 0 deletions handler/core/handler/taskFactoryNotFound.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
taskFactories = [
{
factory = invalid
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ public GraphNodeOptions setOnTransitions(Map<String, GraphNodeOptions> 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<String, GraphNodeOptions> on) {
this.onTransitions = on;
return this;
}

/**
* Sets a node factory name to {@code ActionNodeFactory.NAME} and configures the action.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import static io.knotx.fragments.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.node.action.ActionNodeConfig;
import io.knotx.fragments.task.factory.node.action.ActionNodeFactory;
Expand All @@ -27,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;
Expand Down Expand Up @@ -86,6 +87,16 @@ void expectTransitionSuccessWithNodeBThenNodeC(Vertx vertx) throws Throwable {
}, vertx);
}

@Test
@DisplayName("Expect 'on' to alias 'onTransitions'")
void expectAssignedTransitions(Vertx vertx) throws Throwable {
verify("task/factory/taskWithTransitions-alias.conf", config -> {
GraphNodeOptions graphNodeOptions = new GraphNodeOptions(config);
Map<String, GraphNodeOptions> transitions = graphNodeOptions.getOnTransitions();

assertFalse(transitions.isEmpty());
}, vertx);
}

private Consumer<JsonObject> validateActionNode() {
return config -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# node & transitions
action = a
on {
_success {
action = b
}
}

0 comments on commit d1e5df6

Please sign in to comment.