Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVEL is not enough to discriminate transitions #39

Closed
jgabrielygalan opened this issue Feb 2, 2015 · 3 comments
Closed

MVEL is not enough to discriminate transitions #39

jgabrielygalan opened this issue Feb 2, 2015 · 3 comments

Comments

@jgabrielygalan
Copy link

Hi,

We are facing a problem regarding usage of whenMvel. We have two transitions from one state to another state, where depending on an Mvel expression we want to execute different actions. The state machine is failing with

java.lang.RuntimeException: Tansition 'initial-[Start, _NoName_, 1, EXTERNAL]->second' is conflicted with 'initial-[Start, _NoName_, 1, EXTERNAL]->second'.
    at org.squirrelframework.foundation.fsm.impl.StateImpl.verify(StateImpl.java:560)
    at org.squirrelframework.foundation.fsm.impl.StateMachineBuilderImpl.verifyStateMachineDefinition(StateMachineBuilderImpl.java:487)
    at org.squirrelframework.foundation.fsm.impl.StateMachineBuilderImpl.prepare(StateMachineBuilderImpl.java:532)
    at org.squirrelframework.foundation.fsm.impl.StateMachineBuilderImpl.newStateMachine(StateMachineBuilderImpl.java:706)
    at com.buongiorno.be3aapi.services.authflow.TestStateMachineIssues.testMvelDiscriminatesTransition (TestStateMachineIssues.java:28)

(btw, there's a typo in that exception message: 'Tansition').

This is the test case:

public class TestStateMachineIssues {
    @Test
    public void testSetDebugEnabledDoesntBreak() {
        StateMachineBuilder<AuthFlowStateMachine, String, Object, Context> builder = StateMachineBuilderFactory.create(AuthFlowStateMachine.class, String.class, Object.class, Context.class);
        builder.externalTransition().from("initial").to("second").on("Start");
        AuthFlowStateMachine stateMachine = builder.newStateMachine("initial", StateMachineConfiguration.create().enableDebugMode(true));
        stateMachine.fire("Start", new Context());
        assertEquals("second", stateMachine.getCurrentState());
    }

    @Test
    public void testMvelDiscriminatesTransitions() {
        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));
        stateMachine.fire("Start", new Context());
        assertEquals("second", stateMachine.getCurrentState());
    }
}

class TestAction extends AnonymousAction<AuthFlowStateMachine, String, Object, Context> {   
@Override
public void execute(String arg0, String arg1, Object arg2, Context arg3, AuthFlowStateMachine arg4) {}
}

class Context { 
}

class AuthFlowStateMachine extends AbstractStateMachine<AuthFlowStateMachine, String, Object, Context> {    
}

So, it looks like the whenMvel expression is not enough to discriminate between both transitions.
Is there any way around this limitation?

@hekailiang
Copy link
Owner

Hi jgabrielygalan,

Yes this is a bug. I just fixed it. Now the condition will be differentiated by its name(originally was by its class name which cause cannot differentiate mvel condition), which means in order to make your test case works you need to specify mvel condition name. You can refer to the following test case. Issue39

The fix was included in 0.3.8-SNAPSHOT.

@jgabrielygalan
Copy link
Author

Thanks, it works with the latest version.

@hekailiang
Copy link
Owner

0.3.8 is released. Thanks for reporting this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants