Class ScenarioTemplateHelper
Exposed in all three template engines (Velocity, JavaScript, Mustache) under
the scenario key (see TemplateFunctions.BUILT_IN_HELPERS).
Template API:
$scenario.get("name")— current state of scenarioname("Started"if never set,""for anullname)$scenario.set("name", "state")— updates the state and returns""so it can be called inline in Velocity (e.g.$scenario.set('flow','step2'))$scenario.matches("name", "state")—trueif the current state equalsstate
The helper is backed by the live ScenarioManager wired into
CrossProtocolEventBus.getInstance() by
HttpState — the same instance that matchers
use. So a set from a template is immediately visible to a subsequent
matcher matchesState check and vice-versa. The instance is resolved
lazily on each call (rather than captured at construction) because
TemplateFunctions#BUILT_IN_HELPERS is a static singleton created before
any server is initialised; lazy resolution lets a single helper instance track
whichever server is currently running.
Thread-safety: this helper is stateless and shared across all template
executions. ScenarioManager is itself concurrency-safe (its state store
is backed by a ConcurrentHashMap with compare-and-set transitions), so
no additional synchronisation is required here.
Limitation: when no server has been initialised (e.g. the template engine
is exercised in isolation with no HttpState), there is
no live ScenarioManager; in that case get/matches return
the unset defaults and set is a no-op rather than throwing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the current state of the named scenario, orScenarioManager.STARTED("Started") if the scenario has never been set.booleanReturnstrueif the current state of the named scenario equalsstate.Updates the state of the named scenario.toString()
-
Constructor Details
-
ScenarioTemplateHelper
public ScenarioTemplateHelper()
-
-
Method Details
-
get
Returns the current state of the named scenario, orScenarioManager.STARTED("Started") if the scenario has never been set. Returns""for anullname or when no liveScenarioManageris available. -
set
Updates the state of the named scenario. Returns""so it can be invoked inline within a Velocity template (e.g.$scenario.set('flow','step2')) without emitting any output. No-op when no liveScenarioManageris available, or whenname/stateisnull. -
matches
Returnstrueif the current state of the named scenario equalsstate. Mirrors matcher semantics: an unset scenario is implicitly in theScenarioManager.STARTEDstate. Returnsfalsewhen no liveScenarioManageris available (except wherestatematches the implicit "Started" default). -
toString
-