update tranistions 2
This commit is contained in:
@@ -112,7 +112,7 @@ class HeuristicEventMatchingEngineTest {
|
||||
Event smEvent = Event.of("CREATE", "com.example.other.OrderEvent.CREATE");
|
||||
TriggerPoint triggerPoint = TriggerPoint.builder().event("com.example.some.OrderEvent.CREATE").build();
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,6 +123,6 @@ class HeuristicEventMatchingEngineTest {
|
||||
.polymorphicEvents(List.of("com.example.some.OrderEvent.CREATE"))
|
||||
.build();
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,4 +1003,37 @@ class HeuristicCallGraphEngineCoreTest {
|
||||
org.assertj.core.api.Assertions.assertThat(chains).hasSize(1);
|
||||
org.assertj.core.api.Assertions.assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents()).containsExactlyInAnyOrder("RECORD_EVENT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveEventFromReactiveMethodReference(@TempDir Path tempDir) throws IOException {
|
||||
String source = """
|
||||
package com.example;
|
||||
public class OrderController {
|
||||
private StateMachine stateMachine;
|
||||
public void handleReactive() {
|
||||
Mono.just("REACTIVE_EVENT").flatMap(stateMachine::sendEvent);
|
||||
}
|
||||
}
|
||||
|
||||
class StateMachine {
|
||||
public void sendEvent(String event) {}
|
||||
}
|
||||
|
||||
class Mono {
|
||||
public static Mono just(Object obj) { return new Mono(); }
|
||||
public Mono flatMap(Object mapper) { return this; }
|
||||
}
|
||||
""";
|
||||
Files.writeString(tempDir.resolve("OrderConfig.java"), source);
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
HeuristicCallGraphEngine builder = new HeuristicCallGraphEngine(context);
|
||||
|
||||
EntryPoint entryPoint = EntryPoint.builder().className("com.example.OrderController").methodName("handleReactive").build();
|
||||
TriggerPoint trigger = TriggerPoint.builder().className("com.example.StateMachine").methodName("sendEvent").event("event").build();
|
||||
List<CallChain> chains = builder.findChains(List.of(entryPoint), List.of(trigger));
|
||||
|
||||
org.assertj.core.api.Assertions.assertThat(chains).hasSize(1);
|
||||
org.assertj.core.api.Assertions.assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents()).containsExactlyInAnyOrder("REACTIVE_EVENT");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,4 +326,71 @@ class AstTransitionParserTest {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractBeanClassBodyForExternalGuard(@org.junit.jupiter.api.io.TempDir java.nio.file.Path tempDir) throws java.io.IOException {
|
||||
String guardSource = """
|
||||
package com.example;
|
||||
import org.springframework.statemachine.guard.Guard;
|
||||
import org.springframework.statemachine.StateContext;
|
||||
public class CustomGuard implements Guard<String, String> {
|
||||
@Override
|
||||
public boolean evaluate(StateContext<String, String> context) {
|
||||
return "OK".equals(context.getMessage().getPayload());
|
||||
}
|
||||
}
|
||||
""";
|
||||
String configSource = """
|
||||
package com.example;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
public class TestClass {
|
||||
private CustomGuard paymentGuard;
|
||||
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
|
||||
transitions.withExternal()
|
||||
.source("CREATED")
|
||||
.target("PAID")
|
||||
.event("PAY")
|
||||
.guard(paymentGuard);
|
||||
}
|
||||
}
|
||||
""";
|
||||
java.nio.file.Files.writeString(tempDir.resolve("CustomGuard.java"), guardSource);
|
||||
java.nio.file.Files.writeString(tempDir.resolve("TestClass.java"), configSource);
|
||||
context.scan(tempDir);
|
||||
|
||||
TypeDeclaration td = context.getTypeDeclaration("com.example.TestClass");
|
||||
MethodDeclaration method = context.findMethodDeclaration(td, "configure", true);
|
||||
|
||||
List<Transition> transitions = AstTransitionParser.parseTransitions(method, context);
|
||||
|
||||
assertThat(transitions).hasSize(1);
|
||||
assertThat(transitions.getFirst().getGuard().internalLogic())
|
||||
.contains("return \"OK\".equals(context.getMessage().getPayload());")
|
||||
.contains("public boolean evaluate");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractLocalVariableLambdaGuard() {
|
||||
String source = """
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
import org.springframework.statemachine.guard.Guard;
|
||||
public class TestClass {
|
||||
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
|
||||
Guard<String, String> myLocalGuard = context -> "LOCAL_OK".equals(context.getMessage());
|
||||
transitions.withExternal()
|
||||
.source("CREATED")
|
||||
.target("PAID")
|
||||
.event("PAY")
|
||||
.guard(myLocalGuard);
|
||||
}
|
||||
}
|
||||
""";
|
||||
MethodDeclaration method = createMethodDeclaration(source);
|
||||
|
||||
List<Transition> transitions = AstTransitionParser.parseTransitions(method, context);
|
||||
|
||||
assertThat(transitions).hasSize(1);
|
||||
assertThat(transitions.getFirst().getGuard().internalLogic())
|
||||
.contains("context -> \"LOCAL_OK\".equals(context.getMessage())");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user