commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r957793 - /commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Date Fri, 25 Jun 2010 04:32:06 GMT
Author: rahul
Date: Fri Jun 25 04:32:05 2010
New Revision: 957793

URL: http://svn.apache.org/viewvc?rev=957793&view=rev
Log:
Add a couple of helper test methods.
Porting r957791 from trunk.

Modified:
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java?rev=957793&r1=957792&r2=957793&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Fri Jun 25 04:32:05 2010
@@ -35,6 +35,7 @@ import org.apache.commons.scxml.env.jexl
 import org.apache.commons.scxml.io.SCXMLReader;
 import org.apache.commons.scxml.io.SCXMLReader.Configuration;
 import org.apache.commons.scxml.model.CustomAction;
+import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.TransitionTarget;
 /**
@@ -284,6 +285,45 @@ public class SCXMLTestHelper {
         return roundtrip;
     }
 
+    /**
+     * 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<TransitionTarget> current = exec.getCurrentStatus().getStates();
+        TransitionTarget active = current.iterator().next();
+        return active.getId();
+    }
+
+    /**
+     * Set the active leaf state for this executor instance.
+     * Assumes no usage of &lt;parallel&gt;.
+     *
+     * @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 = exec.getStateMachine().getTargets().get(id);
+        if (active == null) {
+            throw new IllegalArgumentException("No target with id '" + id
+                + "' present in state machine.");
+        }
+        Set<TransitionTarget> current = exec.getCurrentStatus().getStates();
+        current.clear();
+        current.add(active);
+    }
+
     public static String removeCarriageReturns(final String original) {
         StringBuffer buf = new StringBuffer();
         for (int i = 0; i < original.length(); i++) {



Mime
View raw message