Author: rahul Date: Fri Jun 25 04:28:14 2010 New Revision: 957791 URL: http://svn.apache.org/viewvc?rev=957791&view=rev Log: Add a couple of helper test methods.
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java?rev=957791&r1=957790&r2=957791&view=diff ============================================================================== --- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java (original) +++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java Fri Jun 25 04:28:14 2010 @@ -36,6 +36,7 @@ import org.apache.commons.scxml.env.Trac import org.apache.commons.scxml.env.jexl.JexlEvaluator; import org.apache.commons.scxml.io.SCXMLDigester; import org.apache.commons.scxml.io.SCXMLParser; +import org.apache.commons.scxml.model.ModelException; import org.apache.commons.scxml.model.SCXML; import org.apache.commons.scxml.model.State; import org.apache.commons.scxml.model.TransitionTarget; @@ -346,6 +347,46 @@ public class SCXMLTestHelper { } /** + * Get the active leaf state for this executor instance. + * Assumes no usage of <parallel>. + * + * @param exec The {...@link SCXMLExecutor} instance whose active state is + * being queried. + * @return The <code>id</code> of the active state. + */ + public static String getCurrentState(SCXMLExecutor exec) { + Set current = exec.getCurrentStatus().getStates(); + TransitionTarget active = (TransitionTarget) current.iterator().next(); + return active.getId(); + } + + /** + * Set the active leaf state for this executor instance. + * Assumes no usage of <parallel>. + * + * @param exec The {...@link SCXMLExecutor} instance whose active state is + * to be set. + * @param id The <code>id</code> of the state to be made active. + */ + public static void setCurrentState(SCXMLExecutor exec, final String id) { + try { + exec.reset(); + } catch (ModelException me) { + throw new IllegalArgumentException("Provided SCXMLExecutor " + + "instance cannot be reset."); + } + TransitionTarget active = (TransitionTarget) exec.getStateMachine(). + getTargets().get(id); + if (active == null) { + throw new IllegalArgumentException("No target with id '" + id + + "' present in state machine."); + } + Set current = exec.getCurrentStatus().getStates(); + current.clear(); + current.add(active); + } + + /** * Discourage instantiation. */ private SCXMLTestHelper() {