Issue while importing definition
While trying to export the state definition I found that the actions are written
using the below method :
private void writeAction(final Action, ?, ?, ?> action) { if(isExternalAction(action)) writeLine("<sqrl:action content="+quoteName(action.toString())+"/>"); }
Its is doing toString on the action object. In my case it generates following XML :
sqrl:action content="com.mycomp.workflow.actions.WorkflowEditAction@7e4c974d"
Now when I am trying to import this back. In StateMachineImporterImpl.startElement() , It is looking for '#'
else if(localName.equals("action") && uri.equals(SQRL_NAMESPACE)) { String actionContent = attributes.getValue("content"); int pos = actionContent.indexOf("#"); String actionSchema = actionContent.substring(0, pos);
Now since in my case there is no '#', I am getting IndexOutOfBound.
-###############Test Case ################ package com.mycomp.workflow;
import static org.junit.Assert.assertTrue;
import org.junit.After; import org.junit.Before; import org.junit.Test; import org.squirrelframework.foundation.fsm.Action; import org.squirrelframework.foundation.fsm.StateMachineBuilderFactory; import org.squirrelframework.foundation.fsm.UntypedStateMachine; import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder; import org.squirrelframework.foundation.fsm.UntypedStateMachineImporter; import org.squirrelframework.foundation.fsm.annotation.ContextInsensitive; import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters; import org.squirrelframework.foundation.fsm.impl.AbstractUntypedStateMachine;
public class ImportTestCase {
private UntypedStateMachineBuilder builder;
@Before public void setUp() throws Exception { builder = buildStateMachineDefinition(); }
@After public void tearDown() throws Exception {}
@Test public void testImport() {
UntypedStateMachineBase fsm = (UntypedStateMachineBase) builder.newStateMachine("NEW");
String exportedDefinition = fsm.exportXMLDefinition(true);
System.out.println(exportedDefinition);
UntypedStateMachineImporter importer = new UntypedStateMachineImporter();
UntypedStateMachineBuilder importedBuilder = importer.importDefinition(exportedDefinition);
UntypedStateMachineBase newStateMachine =
(UntypedStateMachineBase) importedBuilder.newStateMachine("ASSIGNED");
newStateMachine.fire("ACTIONED");
assertTrue("State macine not imported correctly",
newStateMachine.getCurrentState().equals("ACCEPT"));
}
public UntypedStateMachineBuilder buildStateMachineDefinition() { UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(UntypedStateMachineBase.class, String.class, String.class, Integer.class);
builder.externalTransition().from("NEW").to("ASSIGNED").on("ASSIGN")
.perform(new WorkflowAction());
builder.externalTransition().from("ASSIGNED").to("ACTIONED").on("ACCEPT");
builder.localTransition().from("ACTIONED").to("ASSIGNED").on("EDIT");
builder.externalTransition().from("ACTIONED").to("PENDING_VERIFICATION").on("EDIT");
return builder;
}
@StateMachineParameters(stateType = String.class, eventType = String.class, contextType = Integer.class) @ContextInsensitive static class UntypedStateMachineBase extends AbstractUntypedStateMachine {
}
static class WorkflowAction implements Action<UntypedStateMachine, Object, Object, Object> {
public String name() {
return "EditAction";
}
public int weight() {
return 0;
}
public boolean isAsync() {
return false;
}
public long timeout() {
return 0;
}
@Override
public void execute(Object from, Object to, Object event, Object context,
UntypedStateMachine stateMachine) {
System.out.println("Executing action");
}
}
}
-###############Test Case ################
just try to extend from AnonymousAction: static class WorkflowAction extends AnonymousAction {...