KFSM State Definitions can be generated as PlantUML state diagrams or Asciidoc formatted state tables.

Simple Visualization

The simple visualization uses the resulting definition and can render states and transitions. You will typically add a method to a unit test class as follows:

@Test
fun produceVisualizationTurnstileFSM() {
    println("== TurnStile")
    val visualization = visualize(TurnstileFSM.definition) // (1)
    File("generated", "turnstile.plantuml").writeText(plantUml(visualization)) // (2)
}
  1. TurnstileFSM.definition is the definition that will be rendered.

  2. The plantuml method accepts the output of visualize and produces a state diagram in the plantuml format.

Detail Visualisation

You may invoke the parser from a unit test similar to the simple case.

dependencies {
    testImplementation 'io.jumpco.open:kfsm-viz:1.0.6'
}
@Test
fun produceVisualizationTurnstileFSM() {
    println("== TurnStile")
    val visualization = parseStateMachine("TurnstileFSM", File("src/test/kotlin/Turnstile.kt")) // (1)
    println(visualization)
    File("generated-parsed", "turnstile.plantuml").writeText(plantUml(visualization)) // (2)
    File("generated-parsed", "turnstile.adoc").writeText(asciiDoc(visualization)) // (3)
}
  1. Provide classname for the class holding the definition DSL and the sourcefile where the class may be found.

  2. Use the plantuml method to generate the text for a plantuml state diagram.

  3. Use the asciidoc method to generate an Asciidoc formatted state table.

Expected output

Turnstile State Table

Start Event[Guard] Target Action

LOCKED

COIN

UNLOCKED

{
unlock()
}

UNLOCKED

COIN

UNLOCKED

{
returnCoin()
}

UNLOCKED

PASS

LOCKED

{
lock()
}

Turnstile State Diagram

turnstile

Examples

More examples can be found at: kfsm-viz

Gradle Plugin

Use the kfsm-viz-plugin for Gradle to make the visualization part of your build without writing code.

Resources