1 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 ; 14 15 import java.util.HashMap ; 16 17 18 23 public class ExceptionTestCase extends TestCase { 24 26 public ExceptionTestCase(String s) { 27 super(s); 28 } 29 30 32 public void testFactoryException() { 33 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 { 48 Workflow workflow = new BasicWorkflow("testuser"); 49 URL 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 ()); 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 { 62 Workflow workflow = new BasicWorkflow("testuser"); 63 URL 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 ()); 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 { 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 URL 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 ()); 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 |