无法在测试上下文中注入spring状态机(没有jpastatemachinerepository类型的合格bean)

lsmepo6l  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(212)

我正在编写一个测试用例来注入我的spring状态机的一个示例,并输入一些事件,但到目前为止,没有任何东西能够使它正确地启动上下文
状态机配置

@Configuration
 @EnableStateMachineFactory(contextEvents = false)
 @RequiredArgsConstructor
 @Slf4j
 public class StateMachineConfig
    extends EnumStateMachineConfigurerAdapter<ExecutionStates, ExecutionEvents> {

   private final AbstractStateMachineMonitor stateMachineMonitor;

   private final StateMachineRuntimePersister<Events, States, String> stateMachineRuntimePersister;

@Override
public void configure(final StateMachineConfigurationConfigurer<Events, States> config)
        throws
        Exception {
    config.withConfiguration()
            .listener(new StateMachineListenerAdapter<>());

    config.withMonitoring()
            .monitor(stateMachineMonitor);
    config.withPersistence()
            .runtimePersister(stateMachineRuntimePersister);
    super.configure(config);
}

   @Override
   public void configure(final StateMachineStateConfigurer<Events, States> states)
        throws
        Exception {
    states.withStates().initial(ExecutionStates.INITED, initialAction()).end(ExecutionStates.COMPLETED)
            .states(EnumSet.allOf(ExecutionStates.class));
}

@Override
public void configure(final StateMachineTransitionConfigurer<Events, States> transitions)
        throws
        Exception {
    transitions
            .withExternal()
            .source(ExecutionStates.INITED).target(ExecutionStates.COMPLETED)
            .event(ExecutionEvents.COMPLETE);
}

持久性配置

@Configuration
public class StateMachinePersistenceConfiguration {

@Bean
public StateMachineRuntimePersister<Events, States, String> stateMachineRuntimePersister(
        final JpaStateMachineRepository jpaStateMachineRepository) {
    return new JpaPersistingStateMachineInterceptor<>(jpaStateMachineRepository);
}

}
失败测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { StateMachineConfig.class, StateMachineMonitor.class,    StateMachinePersistenceConfiguration.class})
@ContextConfiguration(classes = {StateMachinePersistenceConfiguration.class})
class Test {

@Autowired
private StateMachine<Events, States> machine;

@Test
public void testInitialState() throws Exception {
    StateMachineTestPlan<Events, States> plan =
            StateMachineTestPlanBuilder.<Events, States>builder()
            .defaultAwaitTime(2)
            .stateMachine(machine1)
            .step()
            .expectStateChanged(1)
            .expectStateEntered(Events.INIT)
            .and()
            .build();

    plan.test();
}

依赖关系
java 11
Spring Boot2.4.2Spring Boot启动器数据jpa 2.4.2
Spring状态机自动配置、启动器数据jpa、Spring状态机启动器和Spring状态机测试2.4.0
少年5
任何帮助都将不胜感激

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题