Skip to content

Commit

Permalink
#146 Implement transitions alias (#150)
Browse files Browse the repository at this point in the history
* #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 9a4a4e9

* #146 Fix line endings

* #146 Fix line endings

Co-authored-by: filip.kowalski <[email protected]>
  • Loading branch information
Voycawojka and filip.kowalski authored Aug 31, 2021
1 parent 31b184f commit 64ed7bd
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions task/factory/default/docs/asciidoc/dataobjects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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
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,17 +17,17 @@

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;
import io.knotx.fragments.task.factory.generic.node.subtasks.SubtasksNodeFactory;
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 @@ -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<String, GraphNodeOptions> 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<String, GraphNodeOptions> transitions = graphNodeOptions.getOnTransitions();

assertEquals(transitions.size(), 1);
assertNotNull(transitions.get("_error"));
}, 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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# node & transitions
action = a
on {
_success {
action = b
}
}
onTransitions {
_error {
action = b
}
}

0 comments on commit 64ed7bd

Please sign in to comment.