Support structured source/event steps in business flows
Add FlowStep with backward-compatible JSON (strings or objects), precompute linkKey in HTML export, and document precise flow highlighting in flows.json. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package click.kamil.springstatemachineexporter.analysis.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class FlowStepJsonTest {
|
||||
|
||||
private final com.fasterxml.jackson.databind.ObjectMapper mapper =
|
||||
new com.fasterxml.jackson.databind.ObjectMapper();
|
||||
|
||||
@Test
|
||||
void shouldDeserializeLegacyStringStep() throws Exception {
|
||||
FlowStep step = mapper.readValue("\"PAY\"", FlowStep.class);
|
||||
assertThat(step.getEvent()).isEqualTo("PAY");
|
||||
assertThat(step.getSource()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDeserializeStructuredStep() throws Exception {
|
||||
FlowStep step = mapper.readValue(
|
||||
"{\"source\":\"com.example.order.OrderState.PAID\",\"event\":\"com.example.order.OrderEvent.SHIP\"}",
|
||||
FlowStep.class);
|
||||
assertThat(step.getSource()).isEqualTo("com.example.order.OrderState.PAID");
|
||||
assertThat(step.getEvent()).isEqualTo("com.example.order.OrderEvent.SHIP");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSerializeEventOnlyStepAsString() throws Exception {
|
||||
String json = mapper.writeValueAsString(FlowStep.ofEvent("PAY"));
|
||||
assertThat(json).isEqualTo("\"PAY\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSerializeStructuredStepAsObject() throws Exception {
|
||||
FlowStep step = FlowStep.builder()
|
||||
.source("com.example.order.OrderState.PAID")
|
||||
.event("com.example.order.OrderEvent.SHIP")
|
||||
.linkKey("OrderState_PAID__OrderEvent_SHIP")
|
||||
.build();
|
||||
String json = mapper.writeValueAsString(step);
|
||||
assertThat(json).contains("\"source\"");
|
||||
assertThat(json).contains("\"event\"");
|
||||
assertThat(json).contains("\"linkKey\"");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package click.kamil.springstatemachineexporter.exporter;
|
||||
|
||||
import click.kamil.springstatemachineexporter.analysis.model.AnalysisResult;
|
||||
import click.kamil.springstatemachineexporter.analysis.model.BusinessFlow;
|
||||
import click.kamil.springstatemachineexporter.analysis.model.FlowStep;
|
||||
import click.kamil.springstatemachineexporter.analysis.model.CodebaseMetadata;
|
||||
import click.kamil.springstatemachineexporter.model.Event;
|
||||
import click.kamil.springstatemachineexporter.model.State;
|
||||
@@ -35,7 +36,7 @@ class JsonInterchangeContractTest {
|
||||
.startStates(Set.of("com.example.order.OrderState.NEW"))
|
||||
.endStates(Set.of("com.example.order.OrderState.PAID"))
|
||||
.renderChoicesAsDiamonds(true)
|
||||
.flows(List.of(BusinessFlow.builder().name("Pay flow").steps(List.of("PAY")).build()))
|
||||
.flows(List.of(BusinessFlow.builder().name("Pay flow").steps(List.of(FlowStep.ofEvent("PAY"))).build()))
|
||||
.metadata(CodebaseMetadata.empty())
|
||||
.build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user