001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow;
006:
007: import com.opensymphony.workflow.basic.BasicWorkflow;
008: import com.opensymphony.workflow.config.Configuration;
009: import com.opensymphony.workflow.config.DefaultConfiguration;
010:
011: import junit.framework.TestCase;
012:
013: import java.net.URL;
014:
015: import java.util.HashMap;
016:
017: /**
018: * @author Hani Suleiman (hani@formicary.net)
019: * Date: May 10, 2003
020: * Time: 1:58:48 PM
021: */
022: public class ExceptionTestCase extends TestCase {
023: //~ Constructors ///////////////////////////////////////////////////////////
024:
025: public ExceptionTestCase(String s) {
026: super (s);
027: }
028:
029: //~ Methods ////////////////////////////////////////////////////////////////
030:
031: public void testFactoryException() {
032: //we expect an InternalWorkflowException (can't throw a checked exception in constructor, otherwise the ejb provider
033: //will break spec by having a constructor
034: try {
035: Configuration config = new DefaultConfiguration();
036: config.load(getClass().getResource(
037: "/osworkflow-badfactory.xml"));
038: } catch (InternalWorkflowException ex) {
039: assertTrue("Expected FactoryException, but instead got "
040: + ex.getRootCause(),
041: ex.getRootCause() instanceof FactoryException);
042: } catch (FactoryException e) {
043: return;
044: }
045:
046: fail("bad factory did not throw an error");
047: }
048:
049: public void testInitializeInvalidActionException() throws Exception {
050: Workflow workflow = new BasicWorkflow("testuser");
051: URL url = getClass().getResource("/samples/auto1.xml");
052: assertNotNull("Unable to find resource /samples/auto1.xml", url);
053:
054: try {
055: workflow.initialize(url.toString(), 2, new HashMap());
056: } catch (InvalidActionException e) {
057: return;
058: }
059:
060: fail("Expected InvalidActionException but did not get one for a bad action in initialize");
061: }
062:
063: public void testInvalidActionException() throws Exception {
064: Workflow workflow = new BasicWorkflow("testuser");
065: URL url = getClass().getResource("/samples/auto1.xml");
066: assertNotNull("Unable to find resource /samples/auto1.xml", url);
067:
068: long id = workflow.initialize(url.toString(), 100,
069: new HashMap());
070:
071: try {
072: workflow.doAction(id, 10, null);
073: } catch (InvalidActionException e) {
074: return;
075: }
076:
077: fail("Expected InvalidActionException but did not get one for a bad action");
078: }
079:
080: public void testStoreException() throws Exception {
081: Configuration config = new DefaultConfiguration();
082: config.load(getClass().getResource(
083: "/samples/invalid/invalid-datasource.xml"));
084:
085: Workflow workflow = new BasicWorkflow("testuser");
086: workflow.setConfiguration(config);
087:
088: //correct behaviour is to get a store exception since we can't look up the DS
089: URL url = getClass().getResource("/samples/auto1.xml");
090: assertNotNull("Unable to find resource /samples/auto1.xml", url);
091:
092: try {
093: workflow.initialize(url.toString(), 100, new HashMap());
094: } catch (StoreException e) {
095: return;
096: }
097:
098: fail("Expected StoreException but did not get one for a bad JDBC datasource");
099: }
100: }
|