Reputation: 341
I have a statemachine using Spring, this is constructed using annotations
@Configuration
@EnableStateMachine
class StateMachineConfiguration extends
StateMachineConfigurerAdapter<State, Event> {
(For the states/transitions)
and a number of handler classes for the actions
@WithStateMachine
public class AwaitingData {
@OnStateEntry(target = "AwaitingData")
public void onEntry() {
I want to build this statemachine manually so I can test various aspects. I do not want to duplicate the configuration for the test, I want to use the "real" config. I can easily build the machine using the StateMachineBuilder and my configuration class
private StateMachine<State, Event> buildStateMachine() {
StateMachineConfiguration config = new StateMachineConfiguration();
StateMachineBuilder.Builder<State, Event> builder = StateMachineBuilder.builder();
config.configure(builder.configureStates());
config.configure(builder.configureTransitions());
return builder.build();
}
but... How do I now add the actions? I want to add specific actions (depending on the specific test) with mocks, etc.
I have stepped through the library as it configures the machine but I still can't see where/how the annotated functions are added. Google is little help, usually sending me straight to the Spring docs which don't seem to cover my use case.
Upvotes: 3
Views: 562
Reputation: 2646
I created gh462 to polish docs.
Essentially as @WithStateMachine
is a spring application context integration, you need to make machine aware of a BeanFactory
. Manual builder were added so that people can use machine outside of a normal spring app context and bean model. Before I get docs polished, see from MethodAnnotationWithBuilderTests how this can be done.
Upvotes: 1