Exemplo n.º 1
0
 @Test
 public void testMvelDiscriminatesTransitionsByConditionName() {
   StateMachineBuilder<AuthFlowStateMachine, String, Object, Context> builder =
       StateMachineBuilderFactory.create(
           AuthFlowStateMachine.class, String.class, Object.class, Context.class);
   TestAction action1 = new TestAction();
   TestAction action2 = new TestAction();
   builder
       .externalTransition()
       .from("initial")
       .to("second")
       .on("Start")
       .whenMvel("script1:::3 > 2")
       .perform(action1);
   builder
       .externalTransition()
       .from("initial")
       .to("second")
       .on("Start")
       .whenMvel("script2:::3 < 2")
       .perform(action2);
   AuthFlowStateMachine stateMachine =
       builder.newStateMachine(
           "initial", StateMachineConfiguration.create().enableDebugMode(true));
   stateMachine.fire("Start", new Context());
   Assert.assertEquals("second", stateMachine.getCurrentState());
 }
Exemplo n.º 2
0
 @Test(expected = RuntimeException.class)
 public void testMvelCannotDiscriminatesTransitionsByConditionName() {
   StateMachineBuilder<AuthFlowStateMachine, String, Object, Context> builder =
       StateMachineBuilderFactory.create(
           AuthFlowStateMachine.class, String.class, Object.class, Context.class);
   TestAction action1 = new TestAction();
   TestAction action2 = new TestAction();
   builder
       .externalTransition()
       .from("initial")
       .to("second")
       .on("Start")
       .whenMvel("3 > 2")
       .perform(action1);
   builder
       .externalTransition()
       .from("initial")
       .to("second")
       .on("Start")
       .whenMvel("3 < 2")
       .perform(action2);
   AuthFlowStateMachine stateMachine =
       builder.newStateMachine(
           "initial", StateMachineConfiguration.create().enableDebugMode(true));
 }
Exemplo n.º 3
0
  @Test(expected = RuntimeException.class)
  public void testCannotDiscriminatesTransitionsByConditionName() {
    StateMachineBuilder<AuthFlowStateMachine, String, Object, Context> builder =
        StateMachineBuilderFactory.create(
            AuthFlowStateMachine.class, String.class, Object.class, Context.class);
    TestAction action1 = new TestAction();
    TestAction action2 = new TestAction();
    builder
        .externalTransition()
        .from("initial")
        .to("second")
        .on("Start")
        .when(
            new Condition<Context>() {
              @Override
              public boolean isSatisfied(Context context) {
                return true;
              }

              @Override
              public String name() {
                return "duplicateName";
              }
            })
        .perform(action1);
    builder
        .externalTransition()
        .from("initial")
        .to("second")
        .on("Start")
        .when(
            new Condition<Context>() {
              @Override
              public boolean isSatisfied(Context context) {
                return true;
              }

              @Override
              public String name() {
                return "duplicateName";
              }
            })
        .perform(action2);
    AuthFlowStateMachine stateMachine =
        builder.newStateMachine(
            "initial", StateMachineConfiguration.create().enableDebugMode(true));
  }