KickJava   Java API By Example, From Geeks To Geeks.

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


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.loader.WorkflowDescriptor;
9
10 import junit.framework.TestCase;
11
12 import java.util.HashMap JavaDoc;
13
14
15 /**
16  * Test Case for AbstractWorkflow.
17  *
18  * @author <a HREF="mailto:vorburger@users.sourceforge.net">Michael Vorburger</a>
19  * @version $Id: ValidationTestCase.java,v 1.7 2004/05/05 23:09:45 hani Exp $ (Created on Feb 11, 2003 at 7:48:39 PM)
20  */

21 public class ValidationTestCase extends TestCase {
22     //~ Constructors ///////////////////////////////////////////////////////////
23

24     public ValidationTestCase(String JavaDoc s) {
25         super(s);
26     }
27
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     /**
31      * Test whether an invalid unconditional-result in an initial-actions is indeed rejected as it should.
32      *
33      * @see <a HREF="http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WF-130">Jira issue WF-130</a>
34      * @throws Exception If error while executing testing
35      */

36     public void testCheckResultInitialActionUnconditionalResult() throws Exception JavaDoc {
37         try {
38             WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getClassLoader().getResource("samples/unconditional-result.xml").toString());
39             descriptor.validate();
40             fail("descriptor loaded successfully, even though unconditional-result element is incorrect");
41         } catch (InvalidWorkflowDescriptorException e) {
42             //the descriptor is invalid, which is correct
43
} catch (Exception JavaDoc ex) {
44             ex.printStackTrace();
45             fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException");
46         }
47     }
48
49     /**
50      * Tests whether common-actions are implemented correctly.
51      *
52      * @throws Exception If error while executing testing
53      */

54     public void testCommonActions() throws Exception JavaDoc {
55         try {
56             WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/common-actions.xml").toString());
57             descriptor.validate();
58         } catch (InvalidWorkflowDescriptorException e) {
59             e.printStackTrace();
60             fail("Descriptor did not recognized common-actions!");
61         }
62
63         try {
64             WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/invalid/common-actions-bad.xml").toString());
65             descriptor.validate();
66             fail("Invalid common-actions not detected correctly");
67         } catch (InvalidWorkflowDescriptorException e) {
68         }
69     }
70
71     /**
72      * Test whether a duplicate action is correctly marked as invalid
73      *
74      * @see <a HREF="http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WF-192">Jira issue WF-192</a>
75      * @throws Exception If error while executing testing
76      */

77     public void testDuplicateActionID() throws Exception JavaDoc {
78         try {
79             WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(getClass().getResource("/samples/invalid/duplicate-action.xml").toString());
80             descriptor.validate();
81             fail("descriptor loaded successfully, even though duplicate action exists");
82         } catch (InvalidWorkflowDescriptorException e) {
83             //the descriptor is invalid, which is correct
84
} catch (Exception JavaDoc ex) {
85             ex.printStackTrace();
86             fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException");
87         }
88     }
89
90     /**
91      * Test validator
92      */

93     public void testValidator() throws Exception JavaDoc {
94         Workflow workflow = new BasicWorkflow("testuser");
95
96         try {
97             long id = workflow.initialize(getClass().getClassLoader().getResource("samples/validator.xml").toString(), 1, new HashMap JavaDoc());
98         } catch (InvalidInputException e) {
99             //the descriptor is invalid, which is correct
100
return;
101         } catch (Exception JavaDoc ex) {
102             ex.printStackTrace();
103             fail("descriptor failed to load as expected, but a " + ex.getClass() + " exception was caught instead of InvalidWorkflowDescriptorException");
104         }
105
106         fail("Did not get expected InvalidInputException");
107     }
108 }
109
Popular Tags