commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r731543 - /commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Date Mon, 05 Jan 2009 12:30:00 GMT
Author: sebb
Date: Mon Jan  5 04:29:59 2009
New Revision: 731543

URL: http://svn.apache.org/viewvc?rev=731543&view=rev
Log:
Remove try/catch blocks for Exceptions that are not expected in testing
Improve non-serialisable check so it only allows DOM elements to fail

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=731543&r1=731542&r2=731543&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
Mon Jan  5 04:29:59 2009
@@ -19,7 +19,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -32,8 +31,6 @@
 
 import junit.framework.Assert;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.env.SimpleDispatcher;
 import org.apache.commons.scxml.env.Tracer;
 import org.apache.commons.scxml.env.jexl.JexlEvaluator;
@@ -65,90 +62,78 @@
         return Integer.toString(++sequence);
     }
 
-    public static SCXML digest(final URL url) {
+    public static SCXML digest(final URL url) throws Exception {
         return digest(url, null, null);
     }
 
-    public static SCXML digest(final URL url, final List customActions) {
+    public static SCXML digest(final URL url, final List customActions) throws Exception
{
         return digest(url, null, customActions);
     }
 
-    public static SCXML digest(final URL url, final ErrorHandler errHandler) {
+    public static SCXML digest(final URL url, final ErrorHandler errHandler) throws Exception
{
         return digest(url, errHandler, null);
     }
 
     public static SCXML digest(final URL url, final ErrorHandler errHandler,
-            final List customActions) {
+            final List customActions) throws Exception {
         Assert.assertNotNull(url);
         // SAX ErrorHandler may be null
         SCXML scxml = null;
-        try {
-            scxml = SCXMLDigester.digest(url, errHandler, customActions);
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage());
-        }
+        scxml = SCXMLDigester.digest(url, errHandler, customActions);
         Assert.assertNotNull(scxml);
         SCXML roundtrip = testModelSerializability(scxml);
         Assert.assertNotNull(roundtrip);
         return roundtrip;
     }
 
-    public static SCXML parse(final URL url) {
+    public static SCXML parse(final URL url) throws Exception {
         return parse(url, null, null);
     }
 
-    public static SCXML parse(final URL url, final List customActions) {
+    public static SCXML parse(final URL url, final List customActions) throws Exception {
         return parse(url, null, customActions);
     }
 
-    public static SCXML parse(final URL url, final ErrorHandler errHandler) {
+    public static SCXML parse(final URL url, final ErrorHandler errHandler) throws Exception
{
         return parse(url, errHandler, null);
     }
 
     public static SCXML parse(final URL url, final ErrorHandler errHandler,
-            final List customActions) {
+            final List customActions) throws Exception {
         Assert.assertNotNull(url);
         // SAX ErrorHandler may be null
         SCXML scxml = null;
-        try {
-            scxml = SCXMLParser.parse(url, errHandler, customActions);
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage());
-        }
+        scxml = SCXMLParser.parse(url, errHandler, customActions);
         Assert.assertNotNull(scxml);
         SCXML roundtrip = testModelSerializability(scxml);
         return roundtrip;
     }
 
-    public static SCXMLExecutor getExecutor(final URL url) {
+    public static SCXMLExecutor getExecutor(final URL url) throws Exception {
         SCXML scxml = parse(url);
         Evaluator evaluator = new JexlEvaluator();
         return getExecutor(evaluator, scxml);
     }
 
     public static SCXMLExecutor getExecutor(final URL url,
-            final Evaluator evaluator) {
+            final Evaluator evaluator) throws Exception {
         SCXML scxml = parse(url);
         return getExecutor(evaluator, scxml);
     }
 
     public static SCXMLExecutor getExecutor(final URL url,
-            final ErrorHandler errHandler) {
+            final ErrorHandler errHandler) throws Exception {
         SCXML scxml = parse(url, errHandler);
         Evaluator evaluator = new JexlEvaluator();
         return getExecutor(evaluator, scxml);
     }
 
-    public static SCXMLExecutor getExecutor(SCXML scxml) {
+    public static SCXMLExecutor getExecutor(SCXML scxml) throws Exception {
         return getExecutor(scxml, null);
     }
 
     public static SCXMLExecutor getExecutor(SCXML scxml,
-            SCXMLSemantics semantics) {
+            SCXMLSemantics semantics) throws Exception {
         Evaluator evaluator = new JexlEvaluator();
         Context context = evaluator.newContext(null);
         EventDispatcher ed = new SimpleDispatcher();
@@ -156,7 +141,7 @@
         return getExecutor(context, evaluator, scxml, ed, trc, semantics);
     }
 
-    public static SCXMLExecutor getExecutor(Evaluator evaluator, SCXML scxml) {
+    public static SCXMLExecutor getExecutor(Evaluator evaluator, SCXML scxml) throws Exception
{
         EventDispatcher ed = new SimpleDispatcher();
         Tracer trc = new Tracer();
         Assert.assertNotNull("Null evaluator", evaluator);
@@ -165,7 +150,7 @@
     }
 
     public static SCXMLExecutor getExecutor(final URL url, final Context ctx,
-            final Evaluator evaluator) {
+            final Evaluator evaluator) throws Exception {
         SCXML scxml = parse(url);
         EventDispatcher ed = new SimpleDispatcher();
         Tracer trc = new Tracer();
@@ -173,43 +158,37 @@
     }
 
     public static SCXMLExecutor getExecutor(final SCXML scxml,
-            final Context ctx, final Evaluator evaluator) {
+            final Context ctx, final Evaluator evaluator) throws Exception {
         EventDispatcher ed = new SimpleDispatcher();
         Tracer trc = new Tracer();
         return getExecutor(ctx, evaluator, scxml, ed, trc);
     }
 
     public static SCXMLExecutor getExecutor(Context context,
-            Evaluator evaluator, SCXML scxml, EventDispatcher ed, Tracer trc) {
+            Evaluator evaluator, SCXML scxml, EventDispatcher ed, Tracer trc) throws Exception
{
         return getExecutor(context, evaluator, scxml, ed, trc, null);
     }
 
     public static SCXMLExecutor getExecutor(Context context,
             Evaluator evaluator, SCXML scxml, EventDispatcher ed,
-            Tracer trc, SCXMLSemantics semantics) {
+            Tracer trc, SCXMLSemantics semantics) throws Exception {
         Assert.assertNotNull(evaluator);
         Assert.assertNotNull(context);
         Assert.assertNotNull(scxml);
         Assert.assertNotNull(ed);
         Assert.assertNotNull(trc);
         SCXMLExecutor exec = null;
-        try {
-            if (semantics == null) {
-                exec = new SCXMLExecutor(evaluator, ed, trc);
-            } else {
-                exec = new SCXMLExecutor(evaluator, ed, trc, semantics);
-            }
-            exec.addListener(scxml, trc);
-            exec.setRootContext(context);
-            exec.setSuperStep(true);
-            exec.setStateMachine(scxml);
-            exec.go();
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage());
+        if (semantics == null) {
+            exec = new SCXMLExecutor(evaluator, ed, trc);
+        } else {
+            exec = new SCXMLExecutor(evaluator, ed, trc, semantics);
         }
         Assert.assertNotNull(exec);
+        exec.addListener(scxml, trc);
+        exec.setRootContext(context);
+        exec.setSuperStep(true);
+        exec.setStateMachine(scxml);
+        exec.go();
         return exec;
     }
 
@@ -232,55 +211,37 @@
         return exec.getSCInstance().lookupContext(tt);
     }
 
-    public static Set fireEvent(SCXMLExecutor exec, String name) {
+    public static Set fireEvent(SCXMLExecutor exec, String name) throws Exception {
         TriggerEvent[] evts = {new TriggerEvent(name,
                 TriggerEvent.SIGNAL_EVENT, null)};
-        try {
-            exec.triggerEvents(evts);
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage() + " while firing event named " + name);
-        }
+        exec.triggerEvents(evts);
         return exec.getCurrentStatus().getStates();
     }
 
-    public static Set fireEvent(SCXMLExecutor exec, TriggerEvent te) {
-        try {
-            exec.triggerEvent(te);
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage() + " while firing event " + te);
-        }
+    public static Set fireEvent(SCXMLExecutor exec, TriggerEvent te) throws Exception {
+        exec.triggerEvent(te);
         return exec.getCurrentStatus().getStates();
     }
 
-    public static Set fireEvents(SCXMLExecutor exec, TriggerEvent[] evts) {
-        try {
-            exec.triggerEvents(evts);
-        } catch (Exception e) {
-            Log log = LogFactory.getLog(SCXMLTestHelper.class);
-            log.error(e.getMessage(), e);
-            Assert.fail(e.getMessage() + " while firing events " + evts);
-        }
+    public static Set fireEvents(SCXMLExecutor exec, TriggerEvent[] evts) throws Exception
{
+        exec.triggerEvents(evts);
         return exec.getCurrentStatus().getStates();
     }
 
     public static void assertPostTriggerState(SCXMLExecutor exec,
-            String triggerEventName, String expectedStateId) {
+            String triggerEventName, String expectedStateId) throws Exception {
         assertPostTriggerState(exec, new TriggerEvent(triggerEventName,
                 TriggerEvent.SIGNAL_EVENT), expectedStateId);
     }
 
     public static void assertPostTriggerStates(SCXMLExecutor exec,
-            String triggerEventName, String[] expectedStateIds) {
+            String triggerEventName, String[] expectedStateIds) throws Exception {
         assertPostTriggerStates(exec, new TriggerEvent(triggerEventName,
                 TriggerEvent.SIGNAL_EVENT), expectedStateIds);
     }
 
     public static void assertPostTriggerState(SCXMLExecutor exec,
-            TriggerEvent triggerEvent, String expectedStateId) {
+            TriggerEvent triggerEvent, String expectedStateId) throws Exception {
         Set currentStates = fireEvent(exec, triggerEvent);
         Assert.assertEquals("Expected 1 simple (leaf) state with id '"
             + expectedStateId + "' on firing event " + triggerEvent
@@ -291,7 +252,7 @@
     }
 
     public static void assertPostTriggerStates(SCXMLExecutor exec,
-            TriggerEvent triggerEvent, String[] expectedStateIds) {
+            TriggerEvent triggerEvent, String[] expectedStateIds) throws Exception {
         if (expectedStateIds == null || expectedStateIds.length == 0) {
             Assert.fail("Must specify an array of one or more "
                 + "expected state IDs");
@@ -317,7 +278,7 @@
             + "'", 0, expectedStateIdList.size());
     }
 
-    public static SCXML testModelSerializability(final SCXML scxml) {
+    public static SCXML testModelSerializability(final SCXML scxml) throws Exception {
         File fileDir = new File(SERIALIZATION_DIR);
         if (!fileDir.exists() && !fileDir.mkdir()) {
             System.err.println("SKIPPED SERIALIZATION: Failed directory creation");
@@ -337,18 +298,22 @@
             in.close();
         } catch (NotSerializableException nse) {
             // <data> nodes failed serialization
-            System.err.println("SERIALIZATION ERROR: The DOM implementation"
-                + " in use is not serializable");
-            return scxml;
-        } catch(IOException ex) {
-            throw new RuntimeException(ex);
-        } catch(ClassNotFoundException ex) {
-            throw new RuntimeException(ex);
+            String msg = nse.getMessage();
+            // Check that it is the DOM that caused the problem
+            if (msg.startsWith("org.apache.crimson.tree.")){
+                // <data> nodes failed serialization, test cases do not add
+                // other non-serializable context data
+                System.err.println("SERIALIZATION ERROR: The DOM implementation"
+                    + " in use is not serializable: " + msg);
+                return scxml;                
+            } else {
+                throw nse;
+            }
         }
         return roundtrip;
     }
 
-    public static SCXMLExecutor testExecutorSerializability(final SCXMLExecutor exec) {
+    public static SCXMLExecutor testExecutorSerializability(final SCXMLExecutor exec) throws
Exception {
         File fileDir = new File(SERIALIZATION_DIR);
         if (!fileDir.exists() && !fileDir.mkdir()) {
             System.err.println("SKIPPED SERIALIZATION: Failed directory creation");
@@ -367,15 +332,17 @@
             roundtrip = (SCXMLExecutor) in.readObject();
             in.close();
         } catch (NotSerializableException nse) {
-            // <data> nodes failed serialization, test cases do not add
-            // other non-serializable context data
-            System.err.println("SERIALIZATION ERROR: The DOM implementation"
-                + " in use is not serializable");
-            return exec;
-        } catch(IOException ex) {
-            throw new RuntimeException(ex);
-        } catch(ClassNotFoundException ex) {
-            throw new RuntimeException(ex);
+            String msg = nse.getMessage();
+            // Check that it is the DOM that caused the problem
+            if (msg.startsWith("org.apache.crimson.tree.")){
+                // <data> nodes failed serialization, test cases do not add
+                // other non-serializable context data
+                System.err.println("SERIALIZATION ERROR: The DOM implementation"
+                    + " in use is not serializable: " + msg);
+                return exec;                
+            } else {
+                throw nse;
+            }
         }
         return roundtrip;
     }



Mime
View raw message