01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.util.beanshell;
06:
07: import com.opensymphony.module.propertyset.PropertySet;
08: import com.opensymphony.module.propertyset.database.JDBCPropertySet;
09:
10: import com.opensymphony.workflow.AbstractWorkflow;
11: import com.opensymphony.workflow.Workflow;
12: import com.opensymphony.workflow.basic.BasicWorkflow;
13: import com.opensymphony.workflow.config.Configuration;
14: import com.opensymphony.workflow.config.DefaultConfiguration;
15:
16: import junit.framework.TestCase;
17:
18: import org.apache.commons.lang.exception.ExceptionUtils;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: /**
24: * Unit test to prove that the BeanShellFunctionProvider eats the key exception
25: * you need. It tells you what line the script fails, but not the underlying
26: * solution.
27: *
28: * @author Eric Pugh (epugh@upstate.com)
29: */
30: public class BeanShellFunctionProviderTestCase extends TestCase {
31: //~ Constructors ///////////////////////////////////////////////////////////
32:
33: public BeanShellFunctionProviderTestCase(String s) {
34: super (s);
35: }
36:
37: //~ Methods ////////////////////////////////////////////////////////////////
38:
39: /**
40: * Test that an exception that is thrown while processing a script is properly
41: * dealt with.
42: *
43: * In this example, by not starting up a JDBC DataSource, the BeanShell script fails.
44: * It should record the underlying lcoation of the NullPointerError JDBC error, but instead you get a null pointer
45: * exception location of the script instead.
46: *
47: * What I want somewhere:
48: * <pre>
49: * java.lang.NullPointerException
50: * at com.opensymphony.module.propertyset.database.JDBCPropertySet.setImpl(JDBCPropertySet.java:267)
51: * at com.opensymphony.module.propertyset.AbstractPropertySet.set(AbstractPropertySet.java:565)
52: * at com.opensymphony.module.propertyset.AbstractPropertySet.setString(AbstractPropertySet.java:363)
53: * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
54: * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
55: * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
56: * at java.lang.reflect.Method.invoke(Method.java:324)
57: * at bsh.Reflect.invokeMethod(Unknown Source)
58: * at bsh.Reflect.invokeObjectMethod(Unknown Source)
59: * at bsh.Name.invokeMethod(Unknown Source)
60: * at bsh.BSHMethodInvocation.eval(Unknown Source)
61: </pre>
62: *
63: */
64: public void testThrowingException() throws Exception {
65: BeanShellFunctionProvider function = new BeanShellFunctionProvider();
66: PropertySet ps = new JDBCPropertySet();
67: Map transientVars = new HashMap();
68: Map args = new HashMap();
69: args
70: .put(AbstractWorkflow.BSH_SCRIPT,
71: "String caller = \"testcaller\"; propertySet.setString(\"caller\", caller);");
72:
73: try {
74: function.execute(transientVars, args, ps);
75: } catch (Exception e) {
76: String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
77: assertTrue(
78: "Make sure our stack trace records the error in JDBC:"
79: + fullStackTrace,
80: fullStackTrace
81: .indexOf("at com.opensymphony.module.propertyset.database.JDBCPropertySet.setImpl") > -1);
82: }
83: }
84: }
|