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.spi.Step;
009: import com.opensymphony.workflow.spi.WorkflowEntry;
010:
011: import junit.framework.TestCase;
012:
013: import java.net.URL;
014:
015: import java.util.ArrayList;
016: import java.util.HashMap;
017: import java.util.List;
018: import java.util.Map;
019:
020: /**
021: * Test that when an auto execute action happens, the correct actions occur.
022: *
023: * @author Hani Suleiman (hani@formicary.net)
024: * Date: May 9, 2003
025: * Time: 10:26:48 PM
026: */
027: public class ActionsTestCase extends TestCase {
028: //~ Instance fields ////////////////////////////////////////////////////////
029:
030: //string used by propertyset-create.xml
031: public String myvar;
032: private AbstractWorkflow workflow;
033:
034: //~ Constructors ///////////////////////////////////////////////////////////
035:
036: public ActionsTestCase(String s) {
037: super (s);
038: }
039:
040: //~ Methods ////////////////////////////////////////////////////////////////
041:
042: public void testAutoWithSplit() throws Exception {
043: URL url = getClass().getResource("/samples/auto-split.xml");
044: long id = workflow.initialize(url.toString(), 1, null);
045: List currentSteps = workflow.getCurrentSteps(id);
046: assertEquals("Unexpected number of current steps", 2,
047: currentSteps.size());
048: }
049:
050: public void testConditionCheck() throws Exception {
051: long id = workflow.initialize(getClass().getResource(
052: "/samples/auto4.xml").toString(), 100, null);
053: List currentSteps = workflow.getCurrentSteps(id);
054: assertEquals("Unexpected number of current steps", 1,
055: currentSteps.size());
056: assertEquals("Unexpected current step", 3, ((Step) currentSteps
057: .get(0)).getStepId());
058: }
059:
060: public void testExecOnlyOne() throws Exception {
061: long id = workflow.initialize(getClass().getResource(
062: "/samples/auto2.xml").toString(), 100, null);
063: List currentSteps = workflow.getCurrentSteps(id);
064: assertEquals("Unexpected number of current steps", 1,
065: currentSteps.size());
066: assertEquals("Unexpected current step", 4, ((Step) currentSteps
067: .get(0)).getStepId());
068:
069: List history = workflow.getHistorySteps(id);
070: assertEquals("Expected to have one history step", 1, history
071: .size());
072: assertEquals("Unexpected history step", 2, ((Step) history
073: .get(0)).getStepId());
074: }
075:
076: public void testExecTwoActions() throws Exception {
077: long id = workflow.initialize(getClass().getResource(
078: "/samples/auto3.xml").toString(), 100, null);
079: List currentSteps = workflow.getCurrentSteps(id);
080: assertEquals("Unexpected number of current steps", 1,
081: currentSteps.size());
082: assertEquals("Unexpected current step", 3, ((Step) currentSteps
083: .get(0)).getStepId());
084:
085: List history = workflow.getHistorySteps(id);
086: assertEquals("Expected to have two history steps", 2, history
087: .size());
088: assertEquals("Unexpected first history step", 2,
089: ((Step) history.get(0)).getStepId());
090: assertEquals("Unexpected second history step", 1,
091: ((Step) history.get(1)).getStepId());
092: }
093:
094: public void testPropertySetCreated() throws Exception {
095: Map inputs = new HashMap();
096: List list = new ArrayList();
097: inputs.put("list", list);
098:
099: long id = workflow.initialize(getClass().getResource(
100: "/samples/propertyset-create.xml").toString(), 1,
101: inputs);
102: String value = (String) list.get(0);
103: assertEquals("Unexpected property set value for key myvar",
104: "anything", value);
105:
106: List currentSteps = workflow.getCurrentSteps(id);
107: assertEquals("Unexpected number of current steps", 1,
108: currentSteps.size());
109: assertEquals("Unexpected current step", 1, ((Step) currentSteps
110: .get(0)).getStepId());
111: }
112:
113: public void testSimpleAuto() throws Exception {
114: long id = workflow.initialize(getClass().getResource(
115: "/samples/auto1.xml").toString(), 100, null);
116: List currentSteps = workflow.getCurrentSteps(id);
117: assertEquals("Unexpected number of current steps", 1,
118: currentSteps.size());
119: assertEquals("Unexpected current step", 2, ((Step) currentSteps
120: .get(0)).getStepId());
121: }
122:
123: public void testSimpleFinish() throws Exception {
124: long id = workflow.initialize(getClass().getResource(
125: "/samples/finish1.xml").toString(), 100, null);
126: workflow.doAction(id, 1, null);
127: assertTrue("Finished workflow should have no current steps",
128: workflow.getCurrentSteps(id).size() == 0);
129: assertEquals("Unexpected workflow entry state",
130: WorkflowEntry.COMPLETED, workflow.getEntryState(id));
131:
132: List historySteps = workflow.getHistorySteps(id);
133:
134: //last history step should have status of LastFinished
135: assertEquals("Unexpected number of history steps", 1,
136: historySteps.size());
137: }
138:
139: public void testSimpleFinishWithoutRestriction() throws Exception {
140: long id = workflow.initialize(getClass().getResource(
141: "/samples/finish2.xml").toString(), 100, null);
142: workflow.doAction(id, 1, null);
143: assertTrue("Finished workflow should have no current steps",
144: workflow.getCurrentSteps(id).size() == 0);
145: assertEquals("Unexpected workflow entry state",
146: WorkflowEntry.COMPLETED, workflow.getEntryState(id));
147:
148: List historySteps = workflow.getHistorySteps(id);
149:
150: //last history step should have status of LastFinished
151: assertEquals("Unexpected number of history steps", 1,
152: historySteps.size());
153: }
154:
155: protected void setUp() throws Exception {
156: workflow = new BasicWorkflow("testuser");
157: }
158: }
|