弹簧状态机使用statemachinetestplan来测试一个选择过渡

发布于 2025-01-22 16:51:52 字数 778 浏览 4 评论 0原文

如果我设置了如下:

transitionConfigurer
  .withExternal()
  .source(FIRST)
    .event(EVENT_1)
    .target(SECOND)

  .and()
  .withChoice()
  .source(SECOND)
    .first(THIRD, new Guard(someService))
    .last(FIRST)

  .and()
  .withExternal()
  .source(THIRD)
    .event(EVENT_2)
    .target(FIRST);

如何使用statemachinetestplan测试使用。

我有一个如下所示的statemachinetestplan设置,这会创建一台具有初始状态的状态计算机,然后我希望能够测试选择。但是,当我在测试计划中执行.Step()时,什么也不会发生:

createStateMachineAndSetInitialState(SECOND, workflowCreator);

StateMachineTestPlan<State, Event> plan = StateMachineTestPlanBuilder.<State, Event> builder()
  .defaultAwaitTime(1)
  .stateMachine(machine)
  .step()
    .expectState(THIRD)
  .and()
  .build();

  plan.test();

If I have a StateMachine set up as below:

transitionConfigurer
  .withExternal()
  .source(FIRST)
    .event(EVENT_1)
    .target(SECOND)

  .and()
  .withChoice()
  .source(SECOND)
    .first(THIRD, new Guard(someService))
    .last(FIRST)

  .and()
  .withExternal()
  .source(THIRD)
    .event(EVENT_2)
    .target(FIRST);

How can I test the withChoice using a StateMachineTestPlan.

I have a StateMachineTestPlan set up as below, this creates a State Machine with an initial state of SECOND, I want to then be able to test the choice. However, when I perform the .step() in the test plan nothing happens:

createStateMachineAndSetInitialState(SECOND, workflowCreator);

StateMachineTestPlan<State, Event> plan = StateMachineTestPlanBuilder.<State, Event> builder()
  .defaultAwaitTime(1)
  .stateMachine(machine)
  .step()
    .expectState(THIRD)
  .and()
  .build();

  plan.test();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-01-29 16:51:52

首先,您可以为下面的方法分享您的自定义覆盖吗?

您需要确保已经配置了这样的选择状态:

@Override
  public void configure(final StateMachineStateConfigurer<States, Events> states)
      throws Exception {
    states
        .withStates()
        .initial(States.FIRST)
        .choice(States.SECOND) 
        .end(States.LAST)
        .states(States.enumSet);
  }

似乎您已达到状态(第二),但没有进入Pseeudo-State。您的测试停止了哪个状态?

First of all, can you please share your custom override for the method below?

You need to make sure you have configured choice states like this:

@Override
  public void configure(final StateMachineStateConfigurer<States, Events> states)
      throws Exception {
    states
        .withStates()
        .initial(States.FIRST)
        .choice(States.SECOND) 
        .end(States.LAST)
        .states(States.enumSet);
  }

It seems like you reached state (SECOND) but did not enter in the CHOICE pseudo-state. In which state have your test stopped at?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文