another test state machine

This commit is contained in:
2026-06-28 11:42:18 +02:00
parent 20b4ed780b
commit 16dccbf81b
39 changed files with 889 additions and 0 deletions

View File

@@ -158,6 +158,24 @@ public class GoldenUpdater {
Path.of("state_machines/inheritance_extra_functions3_state_machine"),
Path.of("src/test/resources/golden/G2StateMachineConfiguration"),
"G2StateMachineConfiguration"
),
new TestScenario(
"Enterprise Order State Machine",
Path.of("state_machines/state_machine_enterprise"),
Path.of("src/test/resources/golden/OrderStateMachineConfiguration"),
"OrderStateMachineConfiguration"
),
new TestScenario(
"Enterprise Document State Machine",
Path.of("state_machines/state_machine_enterprise"),
Path.of("src/test/resources/golden/DocumentStateMachineConfiguration"),
"DocumentStateMachineConfiguration"
),
new TestScenario(
"Enterprise User State Machine",
Path.of("state_machines/state_machine_enterprise"),
Path.of("src/test/resources/golden/UserStateMachineConfiguration"),
"UserStateMachineConfiguration"
)
);
}

View File

@@ -0,0 +1,13 @@
digraph statemachine {
rankdir=LR;
node [shape=rounded, style=filled, fillcolor=white, fontname="Arial"];
edge [fontname="Arial", fontsize=10];
_start [shape=circle, label="", fillcolor=black, width=0.1];
_start -> DRAFT;
APPROVED [fillcolor=lightgray];
DRAFT -> IN_REVIEW [label="DocumentEvent.SUBMIT", style="solid", color="black"];
IN_REVIEW -> APPROVED [label="DocumentEvent.APPROVE", style="solid", color="black"];
IN_REVIEW -> DRAFT [label="DocumentEvent.REJECT", style="solid", color="black"];
}

View File

@@ -0,0 +1,89 @@
{
"metadata" : {
"triggers" : [ ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /api/machine/{machineType}/transition/{event}",
"className" : "click.kamil.enterprise.web.StateMachineController",
"methodName" : "transition",
"sourceFile" : "src/main/java/click/kamil/enterprise/web/StateMachineController.java",
"metadata" : {
"path" : "/api/machine/{machineType}/transition/{event}",
"verb" : "POST"
},
"parameters" : [ {
"name" : "machineType",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "event",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "userId",
"type" : "String",
"annotations" : [ "RequestParam" ]
} ]
} ],
"callChains" : [ ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.enterprise.machines.document.DocumentStateMachineConfiguration",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "DocumentState.DRAFT" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "DocumentState.DRAFT",
"fullIdentifier" : "DocumentState.DRAFT"
} ],
"targetStates" : [ {
"rawName" : "DocumentState.IN_REVIEW",
"fullIdentifier" : "DocumentState.IN_REVIEW"
} ],
"event" : {
"rawName" : "DocumentEvent.SUBMIT",
"fullIdentifier" : "DocumentEvent.SUBMIT"
},
"guard" : null,
"actions" : [ ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "DocumentState.IN_REVIEW",
"fullIdentifier" : "DocumentState.IN_REVIEW"
} ],
"targetStates" : [ {
"rawName" : "DocumentState.APPROVED",
"fullIdentifier" : "DocumentState.APPROVED"
} ],
"event" : {
"rawName" : "DocumentEvent.APPROVE",
"fullIdentifier" : "DocumentEvent.APPROVE"
},
"guard" : null,
"actions" : [ ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "DocumentState.IN_REVIEW",
"fullIdentifier" : "DocumentState.IN_REVIEW"
} ],
"targetStates" : [ {
"rawName" : "DocumentState.DRAFT",
"fullIdentifier" : "DocumentState.DRAFT"
} ],
"event" : {
"rawName" : "DocumentEvent.REJECT",
"fullIdentifier" : "DocumentEvent.REJECT"
},
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "DocumentState.APPROVED" ]
}

View File

@@ -0,0 +1,33 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> DocumentState.DRAFT
DocumentState.DRAFT -[#1E90FF,bold]-> DocumentState.IN_REVIEW <<external>> : DocumentEvent.SUBMIT
DocumentState.IN_REVIEW -[#1E90FF,bold]-> DocumentState.APPROVED <<external>> : DocumentEvent.APPROVE
DocumentState.IN_REVIEW -[#1E90FF,bold]-> DocumentState.DRAFT <<external>> : DocumentEvent.REJECT
DocumentState.APPROVED --> [*]
@enduml

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="DRAFT">
<state id="DRAFT">
<transition target="IN_REVIEW" event="DocumentEvent.SUBMIT"/>
</state>
<state id="IN_REVIEW">
<transition target="APPROVED" event="DocumentEvent.APPROVE"/>
<transition target="DRAFT" event="DocumentEvent.REJECT"/>
</state>
<state id="APPROVED">
</state>
</scxml>

View File

@@ -0,0 +1,12 @@
digraph statemachine {
rankdir=LR;
node [shape=rounded, style=filled, fillcolor=white, fontname="Arial"];
edge [fontname="Arial", fontsize=10];
_start [shape=circle, label="", fillcolor=black, width=0.1];
_start -> NEW;
SHIPPED [fillcolor=lightgray];
NEW -> PENDING [label="OrderEvent.PAY / λ", style="solid", color="black"];
PENDING -> SHIPPED [label="OrderEvent.SHIP", style="solid", color="black"];
}

View File

@@ -0,0 +1,79 @@
{
"metadata" : {
"triggers" : [ ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /api/machine/{machineType}/transition/{event}",
"className" : "click.kamil.enterprise.web.StateMachineController",
"methodName" : "transition",
"sourceFile" : "src/main/java/click/kamil/enterprise/web/StateMachineController.java",
"metadata" : {
"path" : "/api/machine/{machineType}/transition/{event}",
"verb" : "POST"
},
"parameters" : [ {
"name" : "machineType",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "event",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "userId",
"type" : "String",
"annotations" : [ "RequestParam" ]
} ]
} ],
"callChains" : [ ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.enterprise.machines.order.OrderStateMachineConfiguration",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "OrderState.NEW" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "OrderState.NEW",
"fullIdentifier" : "OrderState.NEW"
} ],
"targetStates" : [ {
"rawName" : "OrderState.PENDING",
"fullIdentifier" : "OrderState.PENDING"
} ],
"event" : {
"rawName" : "OrderEvent.PAY",
"fullIdentifier" : "OrderEvent.PAY"
},
"guard" : null,
"actions" : [ {
"expression" : "context -> System.out.println(\"Payment processed.\")",
"isLambda" : true,
"internalLogic" : "context -> System.out.println(\"Payment processed.\")",
"lineNumber" : 28,
"className" : "click.kamil.enterprise.machines.order.OrderStateMachineConfiguration",
"sourceFile" : "src/main/java/click/kamil/enterprise/machines/order/OrderStateMachineConfiguration.java"
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "OrderState.PENDING",
"fullIdentifier" : "OrderState.PENDING"
} ],
"targetStates" : [ {
"rawName" : "OrderState.SHIPPED",
"fullIdentifier" : "OrderState.SHIPPED"
} ],
"event" : {
"rawName" : "OrderEvent.SHIP",
"fullIdentifier" : "OrderEvent.SHIP"
},
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "OrderState.SHIPPED" ]
}

View File

@@ -0,0 +1,32 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> OrderState.NEW
OrderState.NEW -[#1E90FF,bold]-> OrderState.PENDING <<external>> : OrderEvent.PAY / λ
OrderState.PENDING -[#1E90FF,bold]-> OrderState.SHIPPED <<external>> : OrderEvent.SHIP
OrderState.SHIPPED --> [*]
@enduml

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="NEW">
<state id="NEW">
<transition target="PENDING" event="OrderEvent.PAY"/>
</state>
<state id="PENDING">
<transition target="SHIPPED" event="OrderEvent.SHIP"/>
</state>
<state id="SHIPPED">
</state>
</scxml>

View File

@@ -0,0 +1,12 @@
digraph statemachine {
rankdir=LR;
node [shape=rounded, style=filled, fillcolor=white, fontname="Arial"];
edge [fontname="Arial", fontsize=10];
_start [shape=circle, label="", fillcolor=black, width=0.1];
_start -> GUEST;
VERIFIED [fillcolor=lightgray];
GUEST -> REGISTERED [label="UserEvent.REGISTER", style="solid", color="black"];
REGISTERED -> VERIFIED [label="UserEvent.VERIFY", style="solid", color="black"];
}

View File

@@ -0,0 +1,72 @@
{
"metadata" : {
"triggers" : [ ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /api/machine/{machineType}/transition/{event}",
"className" : "click.kamil.enterprise.web.StateMachineController",
"methodName" : "transition",
"sourceFile" : "src/main/java/click/kamil/enterprise/web/StateMachineController.java",
"metadata" : {
"path" : "/api/machine/{machineType}/transition/{event}",
"verb" : "POST"
},
"parameters" : [ {
"name" : "machineType",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "event",
"type" : "String",
"annotations" : [ "PathVariable" ]
}, {
"name" : "userId",
"type" : "String",
"annotations" : [ "RequestParam" ]
} ]
} ],
"callChains" : [ ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.enterprise.machines.user.UserStateMachineConfiguration",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "UserState.GUEST" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "UserState.GUEST",
"fullIdentifier" : "UserState.GUEST"
} ],
"targetStates" : [ {
"rawName" : "UserState.REGISTERED",
"fullIdentifier" : "UserState.REGISTERED"
} ],
"event" : {
"rawName" : "UserEvent.REGISTER",
"fullIdentifier" : "UserEvent.REGISTER"
},
"guard" : null,
"actions" : [ ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "UserState.REGISTERED",
"fullIdentifier" : "UserState.REGISTERED"
} ],
"targetStates" : [ {
"rawName" : "UserState.VERIFIED",
"fullIdentifier" : "UserState.VERIFIED"
} ],
"event" : {
"rawName" : "UserEvent.VERIFY",
"fullIdentifier" : "UserEvent.VERIFY"
},
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "UserState.VERIFIED" ]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,32 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> UserState.GUEST
UserState.GUEST -[#1E90FF,bold]-> UserState.REGISTERED <<external>> : UserEvent.REGISTER
UserState.REGISTERED -[#1E90FF,bold]-> UserState.VERIFIED <<external>> : UserEvent.VERIFY
UserState.VERIFIED --> [*]
@enduml

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="GUEST">
<state id="GUEST">
<transition target="REGISTERED" event="UserEvent.REGISTER"/>
</state>
<state id="REGISTERED">
<transition target="VERIFIED" event="UserEvent.VERIFY"/>
</state>
<state id="VERIFIED">
</state>
</scxml>