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:
010: import junit.framework.TestCase;
011:
012: import java.net.URL;
013:
014: import java.util.*;
015:
016: /**
017: * User: Hani Suleiman
018: * Date: Oct 14, 2003
019: * Time: 3:02:08 PM
020: */
021: public class StepsTestCase extends TestCase {
022: //~ Instance fields ////////////////////////////////////////////////////////
023:
024: private AbstractWorkflow workflow;
025:
026: //~ Constructors ///////////////////////////////////////////////////////////
027:
028: public StepsTestCase(String s) {
029: super (s);
030: }
031:
032: //~ Methods ////////////////////////////////////////////////////////////////
033:
034: public void testEarlyJoin() throws Exception {
035: URL url = getClass().getResource("/samples/earlyjoin.xml");
036: long id = workflow.initialize(url.toString(), 100, null);
037: List currentSteps = workflow.getCurrentSteps(id);
038: assertEquals("Unexpected number of current steps", 2,
039: currentSteps.size());
040: workflow.doAction(id, 1, Collections.EMPTY_MAP);
041:
042: //we end up in step 3, with everything finished
043: List historySteps = workflow.getHistorySteps(id);
044: assertEquals("Unexpected number of history steps", 3,
045: historySteps.size());
046:
047: Step step = (Step) historySteps.get(0);
048: assertEquals("Unexpected last history step", 3, step
049: .getStepId());
050: }
051:
052: public void testJoinNodesOrder() throws Exception {
053: URL url = getClass().getResource("/samples/joinorder.xml");
054: long id = workflow.initialize(url.toString(), 1, null);
055: workflow.doAction(id, 2, null);
056: workflow.doAction(id, 3, null);
057: workflow.doAction(id, 2, null);
058: workflow.doAction(id, 4, null);
059: workflow.doAction(id, 6, null);
060: workflow.doAction(id, 7, null);
061: }
062:
063: public void testSplitCompletedHistorySteps() throws Exception {
064: URL url = getClass().getResource("/samples/joinsplit.xml");
065: long id = workflow.initialize(url.toString(), 100, null);
066: List currentSteps = workflow.getCurrentSteps(id);
067: assertEquals("Unexpected number of current steps", 1,
068: currentSteps.size());
069: workflow.doAction(id, 1, Collections.EMPTY_MAP);
070: currentSteps = workflow.getCurrentSteps(id);
071: assertEquals("Unexpected number of current steps", 2,
072: currentSteps.size());
073:
074: List historySteps = workflow.getHistorySteps(id);
075: assertEquals("Unexpected number of history steps", 1,
076: historySteps.size());
077: workflow.doAction(id, 2, Collections.EMPTY_MAP);
078:
079: //check that the same action is no longer available
080: int[] actions = workflow.getAvailableActions(id,
081: Collections.EMPTY_MAP);
082: assertEquals("Unexpected number of actions available", 1,
083: actions.length);
084: historySteps = workflow.getHistorySteps(id);
085: currentSteps = workflow.getCurrentSteps(id);
086: assertEquals("Unexpected number of current steps", 1,
087: currentSteps.size());
088: assertEquals("Unexpected number of history steps", 2,
089: historySteps.size());
090: }
091:
092: public void testStepPostFunction() throws Exception {
093: URL url = getClass().getResource("/samples/step-post.xml");
094: long id = workflow.initialize(url.toString(), 1, null);
095: workflow.doAction(id, 2, null);
096: assertTrue("post-function was not called as expected",
097: "postvalue".equals(workflow.getPropertySet(id)
098: .getString("postkey")));
099: }
100:
101: public void testStepPreFunction() throws Exception {
102: URL url = getClass().getResource("/samples/step-pre.xml");
103: long id = workflow.initialize(url.toString(), 1, null);
104: assertTrue("pre-function was not called as expected",
105: "prevalue".equals(workflow.getPropertySet(id)
106: .getString("prekey")));
107: }
108:
109: protected void setUp() throws Exception {
110: workflow = new BasicWorkflow("testuser");
111: }
112: }
|