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.loader.WorkflowDescriptor;
009:
010: import junit.framework.TestCase;
011:
012: import java.util.Collections;
013: import java.util.HashMap;
014:
015: /**
016: * Test Case for AbstractWorkflow.
017: *
018: * @author <a href="mailto:vorburger@users.sourceforge.net">Michael Vorburger</a>
019: */
020: public class ValidationTestCase extends TestCase {
021: //~ Constructors ///////////////////////////////////////////////////////////
022:
023: public ValidationTestCase(String s) {
024: super (s);
025: }
026:
027: //~ Methods ////////////////////////////////////////////////////////////////
028:
029: /**
030: * Test whether an invalid unconditional-result in an initial-actions is indeed rejected as it should.
031: *
032: * @see <a href="http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WF-130">Jira issue WF-130</a>
033: * @throws Exception If error while executing testing
034: */
035: public void testCheckResultInitialActionUnconditionalResult()
036: throws Exception {
037: try {
038: WorkflowDescriptor descriptor = DescriptorLoader
039: .getDescriptor(getClass().getClassLoader()
040: .getResource(
041: "samples/unconditional-result.xml")
042: .toString());
043: descriptor.validate();
044: fail("descriptor loaded successfully, even though unconditional-result element is incorrect");
045: } catch (InvalidWorkflowDescriptorException e) {
046: //the descriptor is invalid, which is correct
047: } catch (Exception ex) {
048: ex.printStackTrace();
049: fail("descriptor failed to load as expected, but a "
050: + ex.getClass()
051: + " exception was caught instead of InvalidWorkflowDescriptorException");
052: }
053: }
054:
055: public void testCommonActionDuplicateID() throws Exception {
056: try {
057: WorkflowDescriptor descriptor = DescriptorLoader
058: .getDescriptor(getClass()
059: .getResource(
060: "/samples/invalid/common-actions-dupid.xml")
061: .toString());
062: descriptor.validate();
063: fail("Invalid common-actions not detected correctly");
064: } catch (InvalidWorkflowDescriptorException e) {
065: }
066: }
067:
068: /**
069: * Tests whether common-actions are implemented correctly.
070: *
071: * @throws Exception If error while executing testing
072: */
073: public void testCommonActions() throws Exception {
074: try {
075: WorkflowDescriptor descriptor = DescriptorLoader
076: .getDescriptor(getClass().getResource(
077: "/samples/common-actions.xml").toString());
078: descriptor.validate();
079: } catch (InvalidWorkflowDescriptorException e) {
080: e.printStackTrace();
081: fail("Descriptor did not recognized common-actions!");
082: }
083:
084: try {
085: WorkflowDescriptor descriptor = DescriptorLoader
086: .getDescriptor(getClass().getResource(
087: "/samples/invalid/common-actions-bad.xml")
088: .toString());
089: descriptor.validate();
090: fail("Invalid common-actions not detected correctly");
091: } catch (InvalidWorkflowDescriptorException e) {
092: }
093: }
094:
095: /**
096: * Test whether a duplicate action is correctly marked as invalid
097: *
098: * @see <a href="http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WF-192">Jira issue WF-192</a>
099: * @throws Exception If error while executing testing
100: */
101: public void testDuplicateActionID() throws Exception {
102: try {
103: WorkflowDescriptor descriptor = DescriptorLoader
104: .getDescriptor(getClass().getResource(
105: "/samples/invalid/duplicate-action.xml")
106: .toString());
107: descriptor.validate();
108: fail("descriptor loaded successfully, even though duplicate action exists");
109: } catch (InvalidWorkflowDescriptorException e) {
110: //the descriptor is invalid, which is correct
111: } catch (Exception ex) {
112: ex.printStackTrace();
113: fail("descriptor failed to load as expected, but a "
114: + ex.getClass()
115: + " exception was caught instead of InvalidWorkflowDescriptorException");
116: }
117: }
118:
119: public void testFinish() throws Exception {
120: Workflow workflow = new BasicWorkflow("testuser");
121:
122: try {
123: long id = workflow.initialize(getClass().getClassLoader()
124: .getResource("samples/finish-attribute.xml")
125: .toString(), 100, Collections.EMPTY_MAP);
126: workflow.doAction(id, 1, Collections.EMPTY_MAP);
127: } catch (Exception e) {
128: fail("finish attribute workflow should be valid, instead it failed with: "
129: + e);
130:
131: return;
132: }
133: }
134:
135: /**
136: * Test validator
137: */
138: public void testValidator() throws Exception {
139: Workflow workflow = new BasicWorkflow("testuser");
140:
141: try {
142: long id = workflow.initialize(getClass().getClassLoader()
143: .getResource("samples/validator.xml").toString(),
144: 1, new HashMap());
145: } catch (InvalidInputException e) {
146: //the descriptor is invalid, which is correct
147: return;
148: } catch (Exception ex) {
149: ex.printStackTrace();
150: fail("descriptor failed to load as expected, but a "
151: + ex.getClass()
152: + " exception was caught instead of InvalidWorkflowDescriptorException");
153: }
154:
155: fail("Did not get expected InvalidInputException");
156: }
157: }
|