KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > ExceptionTestCase


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow;
6
7 import com.opensymphony.workflow.basic.BasicWorkflow;
8 import com.opensymphony.workflow.config.Configuration;
9 import com.opensymphony.workflow.config.DefaultConfiguration;
10
11 import junit.framework.TestCase;
12
13 import java.net.URL JavaDoc;
14
15 import java.util.HashMap JavaDoc;
16
17
18 /**
19  * @author Hani Suleiman (hani@formicary.net)
20  * Date: May 10, 2003
21  * Time: 1:58:48 PM
22  */

23 public class ExceptionTestCase extends TestCase {
24     //~ Constructors ///////////////////////////////////////////////////////////
25

26     public ExceptionTestCase(String JavaDoc s) {
27         super(s);
28     }
29
30     //~ Methods ////////////////////////////////////////////////////////////////
31

32     public void testFactoryException() {
33         //we expect an InternalWorkflowException (can't throw a checked exception in constructor, otherwise the ejb provider
34
//will break spec by having a constructor
35
try {
36             Configuration config = new DefaultConfiguration();
37             config.load(getClass().getResource("/osworkflow-badfactory.xml"));
38         } catch (InternalWorkflowException ex) {
39             assertTrue("Expected FactoryException, but instead got " + ex.getRootCause(), ex.getRootCause() instanceof FactoryException);
40         } catch (FactoryException e) {
41             return;
42         }
43
44         fail("bad factory did not throw an error");
45     }
46
47     public void testInitializeInvalidActionException() throws Exception JavaDoc {
48         Workflow workflow = new BasicWorkflow("testuser");
49         URL JavaDoc url = getClass().getResource("/samples/auto1.xml");
50         assertNotNull("Unable to find resource /samples/auto1.xml", url);
51
52         try {
53             workflow.initialize(url.toString(), 2, new HashMap JavaDoc());
54         } catch (InvalidActionException e) {
55             return;
56         }
57
58         fail("Expected InvalidActionException but did not get one for a bad action in initialize");
59     }
60
61     public void testInvalidActionException() throws Exception JavaDoc {
62         Workflow workflow = new BasicWorkflow("testuser");
63         URL JavaDoc url = getClass().getResource("/samples/auto1.xml");
64         assertNotNull("Unable to find resource /samples/auto1.xml", url);
65
66         long id = workflow.initialize(url.toString(), 1, new HashMap JavaDoc());
67
68         try {
69             workflow.doAction(id, 10, null);
70         } catch (InvalidActionException e) {
71             return;
72         }
73
74         fail("Expected InvalidActionException but did not get one for a bad action");
75     }
76
77     public void testStoreException() throws Exception JavaDoc {
78         Configuration config = new DefaultConfiguration();
79         config.load(getClass().getResource("/osworkflow-jdbc.xml"));
80
81         Workflow workflow = new BasicWorkflow("testuser");
82         workflow.setConfiguration(config);
83
84         //correct behaviour is to get a store exception since we can't look up the DS
85
URL JavaDoc url = getClass().getResource("/samples/auto1.xml");
86         assertNotNull("Unable to find resource /samples/auto1.xml", url);
87
88         try {
89             workflow.initialize(url.toString(), 1, new HashMap JavaDoc());
90         } catch (StoreException e) {
91             return;
92         }
93
94         fail("Expected StoreException but did not get one for a bad JDBC datasource");
95     }
96 }
97
Popular Tags