more examples

This commit is contained in:
2026-06-07 10:24:19 +02:00
parent 2ecc8e08de
commit c8975eddde
16 changed files with 811 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
package click.kamil.springstatemachineexporter.ast.common;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class CodebaseContextTest {
@TempDir
Path tempDir;
@Test
void shouldFindEntryPointByAnnotation() throws IOException {
String source = """
package com.example;
import org.springframework.statemachine.config.EnableStateMachine;
@EnableStateMachine
public class MyConfig {}
""";
Files.writeString(tempDir.resolve("MyConfig.java"), source);
CodebaseContext context = new CodebaseContext();
context.scan(tempDir);
List<TypeDeclaration> entryPoints = context.findEntryPointClasses(List.of("EnableStateMachine"));
assertThat(entryPoints).hasSize(1);
assertThat(entryPoints.get(0).getName().getIdentifier()).isEqualTo("MyConfig");
}
@Test
void shouldFindEntryPointByInheritance() throws IOException {
String baseSource = """
package com.example;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
public abstract class BaseConfig extends StateMachineConfigurerAdapter {}
""";
String leafSource = """
package com.example;
public class LeafConfig extends BaseConfig {}
""";
Files.writeString(tempDir.resolve("BaseConfig.java"), baseSource);
Files.writeString(tempDir.resolve("LeafConfig.java"), leafSource);
CodebaseContext context = new CodebaseContext();
context.scan(tempDir);
List<TypeDeclaration> entryPoints = context.findEntryPointClasses(List.of("EnableStateMachine"));
assertThat(entryPoints).hasSize(1);
assertThat(entryPoints.get(0).getName().getIdentifier()).isEqualTo("LeafConfig");
}
@Test
void shouldNotFindAbstractClassAsEntryPoint() throws IOException {
String source = """
package com.example;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
public abstract class MyConfig extends StateMachineConfigurerAdapter {}
""";
Files.writeString(tempDir.resolve("MyConfig.java"), source);
CodebaseContext context = new CodebaseContext();
context.scan(tempDir);
List<TypeDeclaration> entryPoints = context.findEntryPointClasses(List.of("EnableStateMachine"));
assertThat(entryPoints).isEmpty();
}
@Test
void shouldResolveInheritanceWithImports() throws IOException {
Files.createDirectories(tempDir.resolve("base"));
Files.createDirectories(tempDir.resolve("leaf"));
String baseSource = """
package com.example.base;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
public abstract class BaseConfig extends StateMachineConfigurerAdapter {}
""";
String leafSource = """
package com.example.leaf;
import com.example.base.BaseConfig;
public class LeafConfig extends BaseConfig {}
""";
Files.writeString(tempDir.resolve("base/BaseConfig.java"), baseSource);
Files.writeString(tempDir.resolve("leaf/LeafConfig.java"), leafSource);
CodebaseContext context = new CodebaseContext();
context.scan(tempDir);
List<TypeDeclaration> entryPoints = context.findEntryPointClasses(List.of("EnableStateMachine"));
assertThat(entryPoints).hasSize(1);
assertThat(entryPoints.get(0).getName().getIdentifier()).isEqualTo("LeafConfig");
}
}

View File

@@ -0,0 +1,76 @@
@startuml
skinparam state {
BackgroundColor<<choice>> LightYellow
}
[*] --> STATE1
state STATE17 <<choice>>
state STATE16 <<choice>>
state STATE2 <<choice>>
state STATE14 <<choice>>
state STATE12 <<choice>>
state STATE11 <<choice>>
state STATE8 <<choice>>
state STATEY <<choice>>
state STATE20 <<choice>>
state STATE9 <<choice>>
state STATE19 <<choice>>
state STATE18 <<choice>>
STATE1 -[#1E90FF,bold]-> STATE2 : EVENT1
STATE2 -[#1E90FF,bold]-> STATE3 : EVENT2
STATE3 -[#1E90FF,bold]-> STATE4 : EVENT3
STATE4 -[#1E90FF,bold]-> STATE5 : EVENT4
STATE5 -[#1E90FF,bold]-> STATE6 : EVENT5
STATE6 -[#1E90FF,bold]-> STATE7 : EVENT6
STATE7 -[#1E90FF,bold]-> STATE8 : EVENT7
STATE8 -[#1E90FF,bold]-> STATE9 : EVENT8
STATE9 -[#1E90FF,bold]-> STATE10 : EVENT9
STATE10 -[#1E90FF,bold]-> STATE11 : EVENT10
STATE11 -[#1E90FF,bold]-> STATE12 : EVENT11
STATE12 -[#1E90FF,bold]-> STATE13 : EVENT12
STATE13 -[#1E90FF,bold]-> STATE14 : EVENT13
STATE14 -[#1E90FF,bold]-> STATE15 : EVENT14
STATE15 -[#1E90FF,bold]-> STATE16 : EVENT15
STATE1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE5 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> STATEY : EVENTY
STATEY -[#4682B4,bold]-> STATEX : [guardVarEquals("value1")] (order=0)
STATEY -[#4682B4,bold]-> STATEZ : (order=1)
STATE16 -[#4682B4,bold]-> STATE17 : [guardVarEquals("value1")] (order=0)
STATE16 -[#4682B4,bold]-> STATE18 : [guardVarEquals("value2")] (order=1)
STATE16 -[#4682B4,bold]-> STATE19 : (order=2)
STATE17 -[#FF6347,bold]-> STATE20 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE17 -[#FF6347,bold]-> STATE16 : (order=1)
STATE18 -[#FF69B4,bold]-> STATE19 : [guardVarEquals("value3")] (order=0)
STATE18 -[#FF69B4,bold]-> STATE20 : (order=1)
STATE19 -[#6A5ACD,bold]-> STATE1 : [guardVarEquals("reset")] (order=0)
STATE19 -[#6A5ACD,bold]-> STATE20 : (order=1)
STATE20 -[#32CD32,bold]-> STATE5 : [guardEventHeaderEquals("header2","bar")] (order=0)
STATE20 -[#32CD32,bold]-> STATE1 : (order=1)
STATE11 -[#FF69B4,bold]-> STATE13 : [guardVarEquals("goTo13")] (order=0)
STATE11 -[#FF69B4,bold]-> STATE14 : [guardVarEquals("goTo14")] (order=1)
STATE11 -[#FF69B4,bold]-> STATE15 : (order=2)
STATE12 -[#6A5ACD,bold]-> STATE10 : [guardVarEquals("goBack10")] (order=0)
STATE12 -[#6A5ACD,bold]-> STATE11 : (order=1)
STATE14 -[#FFD700,bold]-> STATE12 : [guardVarEquals("loop12")] (order=0)
STATE14 -[#FFD700,bold]-> STATE16 : (order=1)
STATE9 -[#FFD700,bold]-> STATE8 : [guardVarEquals("stepBack")] (order=0)
STATE9 -[#FFD700,bold]-> STATE7 : [guardVarEquals("stepBackMore")] (order=1)
STATE9 -[#FFD700,bold]-> STATE6 : (order=2)
STATE8 -[#FF6347,bold]-> STATE9 : [guardVarEquals("forward9")] (order=0)
STATE8 -[#FF6347,bold]-> STATE10 : (order=1)
STATE2 -[#1E90FF,bold]-> STATE_EXTRA_1 : EVENTX
STATE2 -[#32CD32,bold]-> STATE1 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE2 -[#32CD32,bold]-> STATE_EXTRA_1 : (order=1)
STATE_EXTRA_1 -[#1E90FF,bold]-> STATE_EXTRA_3 : EVENTY
STATE_EXTRA_1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATE_EXTRA_2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATEZ --> [*]
@enduml

View File

@@ -0,0 +1,77 @@
@startuml
skinparam state {
BackgroundColor<<choice>> LightYellow
}
[*] --> STATE1
state STATE17 <<choice>>
state STATE16 <<choice>>
state STATE14 <<choice>>
state STATE12 <<choice>>
state STATE11 <<choice>>
state STATE8 <<choice>>
state STATEY <<choice>>
state STATE20 <<choice>>
state STATE9 <<choice>>
state STATE_EXTRA_1_2 <<choice>>
state STATE19 <<choice>>
state STATE18 <<choice>>
STATE1 -[#1E90FF,bold]-> STATE2 : EVENT1
STATE2 -[#1E90FF,bold]-> STATE3 : EVENT2
STATE3 -[#1E90FF,bold]-> STATE4 : EVENT3
STATE4 -[#1E90FF,bold]-> STATE5 : EVENT4
STATE5 -[#1E90FF,bold]-> STATE6 : EVENT5
STATE6 -[#1E90FF,bold]-> STATE7 : EVENT6
STATE7 -[#1E90FF,bold]-> STATE8 : EVENT7
STATE8 -[#1E90FF,bold]-> STATE9 : EVENT8
STATE9 -[#1E90FF,bold]-> STATE10 : EVENT9
STATE10 -[#1E90FF,bold]-> STATE11 : EVENT10
STATE11 -[#1E90FF,bold]-> STATE12 : EVENT11
STATE12 -[#1E90FF,bold]-> STATE13 : EVENT12
STATE13 -[#1E90FF,bold]-> STATE14 : EVENT13
STATE14 -[#1E90FF,bold]-> STATE15 : EVENT14
STATE15 -[#1E90FF,bold]-> STATE16 : EVENT15
STATE1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE5 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> STATEY : EVENTY
STATEY -[#FF6347,bold]-> STATEX : [guardVarEquals("value1")] (order=0)
STATEY -[#FF6347,bold]-> STATEZ : (order=1)
STATE16 -[#4682B4,bold]-> STATE17 : [guardVarEquals("value1")] (order=0)
STATE16 -[#4682B4,bold]-> STATE18 : [guardVarEquals("value2")] (order=1)
STATE16 -[#4682B4,bold]-> STATE19 : (order=2)
STATE17 -[#FF6347,bold]-> STATE20 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE17 -[#FF6347,bold]-> STATE16 : (order=1)
STATE18 -[#FF69B4,bold]-> STATE19 : [guardVarEquals("value3")] (order=0)
STATE18 -[#FF69B4,bold]-> STATE20 : (order=1)
STATE19 -[#6A5ACD,bold]-> STATE1 : [guardVarEquals("reset")] (order=0)
STATE19 -[#6A5ACD,bold]-> STATE20 : (order=1)
STATE20 -[#4682B4,bold]-> STATE5 : [guardEventHeaderEquals("header2","bar")] (order=0)
STATE20 -[#4682B4,bold]-> STATE1 : (order=1)
STATE11 -[#6A5ACD,bold]-> STATE13 : [guardVarEquals("goTo13")] (order=0)
STATE11 -[#6A5ACD,bold]-> STATE14 : [guardVarEquals("goTo14")] (order=1)
STATE11 -[#6A5ACD,bold]-> STATE15 : (order=2)
STATE12 -[#FFD700,bold]-> STATE10 : [guardVarEquals("goBack10")] (order=0)
STATE12 -[#FFD700,bold]-> STATE11 : (order=1)
STATE14 -[#32CD32,bold]-> STATE12 : [guardVarEquals("loop12")] (order=0)
STATE14 -[#32CD32,bold]-> STATE16 : (order=1)
STATE9 -[#32CD32,bold]-> STATE8 : [guardVarEquals("stepBack")] (order=0)
STATE9 -[#32CD32,bold]-> STATE7 : [guardVarEquals("stepBackMore")] (order=1)
STATE9 -[#32CD32,bold]-> STATE6 : (order=2)
STATE8 -[#FF69B4,bold]-> STATE9 : [guardVarEquals("forward9")] (order=0)
STATE8 -[#FF69B4,bold]-> STATE10 : (order=1)
STATE9 -[#1E90FF,bold]-> STATE_EXTRA_1_1 : EVENT_1_1
STATE_EXTRA_1_2 -[#FFD700,bold]-> STATE_EXTRA_1_1 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE_EXTRA_1_2 -[#FFD700,bold]-> STATE_EXTRA_1_3 : (order=1)
STATE_EXTRA_1_3 -[#1E90FF,bold]-> STATE_EXTRA_1 : EVENT_1_2
STATE_EXTRA_1_1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATE_EXTRA_1_2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATE_EXTRA_1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATEZ --> [*]
@enduml

View File

@@ -0,0 +1,40 @@
@startuml
skinparam state {
BackgroundColor<<choice>> LightYellow
}
[*] --> STATE1
state STATE8 <<choice>>
state STATEY <<choice>>
state STATE9 <<choice>>
STATE1 -[#1E90FF,bold]-> STATE2 : EVENT1
STATE2 -[#1E90FF,bold]-> STATE3 : EVENT2
STATE3 -[#1E90FF,bold]-> STATE4 : EVENT3
STATE4 -[#1E90FF,bold]-> STATE5 : EVENT4
STATE5 -[#1E90FF,bold]-> STATE6 : EVENT5
STATE6 -[#1E90FF,bold]-> STATE7 : EVENT6
STATE7 -[#1E90FF,bold]-> STATE8 : EVENT7
STATE8 -[#1E90FF,bold]-> STATE9 : EVENT8
STATE9 -[#1E90FF,bold]-> STATE10 : EVENT9
STATE1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE5 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> STATEY : EVENTY
STATEY -[#4682B4,bold]-> STATEX : [guardVarEquals("value1")] (order=0)
STATEY -[#4682B4,bold]-> STATEZ : (order=1)
STATE9 -[#32CD32,bold]-> STATE8 : [guardVarEquals("stepBack")] (order=0)
STATE9 -[#32CD32,bold]-> STATE7 : [guardVarEquals("stepBackMore")] (order=1)
STATE9 -[#32CD32,bold]-> STATE6 : (order=2)
STATE8 -[#FF6347,bold]-> STATE9 : [guardVarEquals("forward9")] (order=0)
STATE8 -[#FF6347,bold]-> STATE10 : (order=1)
STATE3 -[#1E90FF,bold]-> STATE_EXTRA_2 : EVENT_1_2
STATE_EXTRA_2 -[#1E90FF,bold]-> STATE_EXTRA_3 : EVENT_1_2
STATE_EXTRA_3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATEZ --> [*]
@enduml

View File

@@ -0,0 +1,41 @@
@startuml
skinparam state {
BackgroundColor<<choice>> LightYellow
}
[*] --> STATE1
state STATE8 <<choice>>
state STATEY <<choice>>
state STATE9 <<choice>>
STATE1 -[#1E90FF,bold]-> STATE2 : EVENT1
STATE2 -[#1E90FF,bold]-> STATE3 : EVENT2
STATE3 -[#1E90FF,bold]-> STATE4 : EVENT3
STATE4 -[#1E90FF,bold]-> STATE5 : EVENT4
STATE5 -[#1E90FF,bold]-> STATE6 : EVENT5
STATE6 -[#1E90FF,bold]-> STATE7 : EVENT6
STATE7 -[#1E90FF,bold]-> STATE8 : EVENT7
STATE8 -[#1E90FF,bold]-> STATE9 : EVENT8
STATE9 -[#1E90FF,bold]-> STATE10 : EVENT9
STATE1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE5 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> STATEY : EVENTY
STATEY -[#4682B4,bold]-> STATEX : [guardVarEquals("value1")] (order=0)
STATEY -[#4682B4,bold]-> STATEZ : (order=1)
STATE9 -[#32CD32,bold]-> STATE8 : [guardVarEquals("stepBack")] (order=0)
STATE9 -[#32CD32,bold]-> STATE7 : [guardVarEquals("stepBackMore")] (order=1)
STATE9 -[#32CD32,bold]-> STATE6 : (order=2)
STATE8 -[#FF6347,bold]-> STATE9 : [guardVarEquals("forward9")] (order=0)
STATE8 -[#FF6347,bold]-> STATE10 : (order=1)
STATE3 -[#1E90FF,bold]-> STATE_EXTRA_1 : EVENT_1_2
STATE_EXTRA_1 -[#1E90FF,bold]-> STATE_EXTRA_2 : EVENT_1_3
STATE_EXTRA_1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE_EXTRA_2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATEZ --> [*]
@enduml

View File

@@ -0,0 +1,76 @@
@startuml
skinparam state {
BackgroundColor<<choice>> LightYellow
}
[*] --> STATE1
state STATE17 <<choice>>
state STATE16 <<choice>>
state STATE2 <<choice>>
state STATE14 <<choice>>
state STATE12 <<choice>>
state STATE11 <<choice>>
state STATE8 <<choice>>
state STATEY <<choice>>
state STATE20 <<choice>>
state STATE9 <<choice>>
state STATE19 <<choice>>
state STATE18 <<choice>>
STATE1 -[#1E90FF,bold]-> STATE2 : EVENT1
STATE2 -[#1E90FF,bold]-> STATE3 : EVENT2
STATE3 -[#1E90FF,bold]-> STATE4 : EVENT3
STATE4 -[#1E90FF,bold]-> STATE5 : EVENT4
STATE5 -[#1E90FF,bold]-> STATE6 : EVENT5
STATE6 -[#1E90FF,bold]-> STATE7 : EVENT6
STATE7 -[#1E90FF,bold]-> STATE8 : EVENT7
STATE8 -[#1E90FF,bold]-> STATE9 : EVENT8
STATE9 -[#1E90FF,bold]-> STATE10 : EVENT9
STATE10 -[#1E90FF,bold]-> STATE11 : EVENT10
STATE11 -[#1E90FF,bold]-> STATE12 : EVENT11
STATE12 -[#1E90FF,bold]-> STATE13 : EVENT12
STATE13 -[#1E90FF,bold]-> STATE14 : EVENT13
STATE14 -[#1E90FF,bold]-> STATE15 : EVENT14
STATE15 -[#1E90FF,bold]-> STATE16 : EVENT15
STATE1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE3 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE5 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL
STATE4 -[#1E90FF,bold]-> STATEY : EVENTY
STATEY -[#4682B4,bold]-> STATEX : [guardVarEquals("value1")] (order=0)
STATEY -[#4682B4,bold]-> STATEZ : (order=1)
STATE16 -[#4682B4,bold]-> STATE17 : [guardVarEquals("value1")] (order=0)
STATE16 -[#4682B4,bold]-> STATE18 : [guardVarEquals("value2")] (order=1)
STATE16 -[#4682B4,bold]-> STATE19 : (order=2)
STATE17 -[#FF6347,bold]-> STATE20 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE17 -[#FF6347,bold]-> STATE16 : (order=1)
STATE18 -[#FF69B4,bold]-> STATE19 : [guardVarEquals("value3")] (order=0)
STATE18 -[#FF69B4,bold]-> STATE20 : (order=1)
STATE19 -[#6A5ACD,bold]-> STATE1 : [guardVarEquals("reset")] (order=0)
STATE19 -[#6A5ACD,bold]-> STATE20 : (order=1)
STATE20 -[#32CD32,bold]-> STATE5 : [guardEventHeaderEquals("header2","bar")] (order=0)
STATE20 -[#32CD32,bold]-> STATE1 : (order=1)
STATE11 -[#FF69B4,bold]-> STATE13 : [guardVarEquals("goTo13")] (order=0)
STATE11 -[#FF69B4,bold]-> STATE14 : [guardVarEquals("goTo14")] (order=1)
STATE11 -[#FF69B4,bold]-> STATE15 : (order=2)
STATE12 -[#6A5ACD,bold]-> STATE10 : [guardVarEquals("goBack10")] (order=0)
STATE12 -[#6A5ACD,bold]-> STATE11 : (order=1)
STATE14 -[#FFD700,bold]-> STATE12 : [guardVarEquals("loop12")] (order=0)
STATE14 -[#FFD700,bold]-> STATE16 : (order=1)
STATE9 -[#FFD700,bold]-> STATE8 : [guardVarEquals("stepBack")] (order=0)
STATE9 -[#FFD700,bold]-> STATE7 : [guardVarEquals("stepBackMore")] (order=1)
STATE9 -[#FFD700,bold]-> STATE6 : (order=2)
STATE8 -[#FF6347,bold]-> STATE9 : [guardVarEquals("forward9")] (order=0)
STATE8 -[#FF6347,bold]-> STATE10 : (order=1)
STATE2 -[#1E90FF,bold]-> STATE_EXTRA_1 : EVENTX
STATE2 -[#32CD32,bold]-> STATE1 : [guardEventHeaderEquals("header1","foo")] (order=0)
STATE2 -[#32CD32,bold]-> STATE_EXTRA_1 : (order=1)
STATE_EXTRA_1 -[#1E90FF,bold]-> STATE_EXTRA_3 : EVENTY
STATE_EXTRA_1 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATE_EXTRA_2 -[#1E90FF,bold]-> CANCEL : EVENT_CANCEL_2
STATEZ --> [*]
@enduml