KickJava   Java API By Example, From Geeks To Geeks.

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


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.spi.Step;
9
10 import junit.framework.TestCase;
11
12 import java.net.URL JavaDoc;
13
14 import java.util.*;
15
16
17 /**
18  * User: Hani Suleiman
19  * Date: Oct 14, 2003
20  * Time: 3:02:08 PM
21  */

22 public class StepsTestCase extends TestCase {
23     //~ Instance fields ////////////////////////////////////////////////////////
24

25     private AbstractWorkflow workflow;
26
27     //~ Constructors ///////////////////////////////////////////////////////////
28

29     public StepsTestCase(String JavaDoc s) {
30         super(s);
31     }
32
33     //~ Methods ////////////////////////////////////////////////////////////////
34

35     public void testEarlyJoin() throws Exception JavaDoc {
36         URL JavaDoc url = getClass().getResource("/samples/earlyjoin.xml");
37         long id = workflow.initialize(url.toString(), 1, null);
38         List currentSteps = workflow.getCurrentSteps(id);
39         assertEquals("Unexpected number of current steps", 2, currentSteps.size());
40         workflow.doAction(id, 1, Collections.EMPTY_MAP);
41
42         //we end up in step 3, with everything finished
43
List historySteps = workflow.getHistorySteps(id);
44         assertEquals("Unexpected number of history steps", 3, historySteps.size());
45
46         Step step = (Step) historySteps.get(2);
47         assertEquals("Unexpected last history step", 3, step.getStepId());
48     }
49
50     public void testSplitCompletedHistorySteps() throws Exception JavaDoc {
51         URL JavaDoc url = getClass().getResource("/samples/joinsplit.xml");
52         long id = workflow.initialize(url.toString(), 1, null);
53         List currentSteps = workflow.getCurrentSteps(id);
54         assertEquals("Unexpected number of current steps", 1, currentSteps.size());
55         workflow.doAction(id, 1, Collections.EMPTY_MAP);
56         currentSteps = workflow.getCurrentSteps(id);
57         assertEquals("Unexpected number of current steps", 2, currentSteps.size());
58
59         List historySteps = workflow.getHistorySteps(id);
60         assertEquals("Unexpected number of history steps", 1, historySteps.size());
61         workflow.doAction(id, 2, Collections.EMPTY_MAP);
62
63         //check that the same action is no longer available
64
int[] actions = workflow.getAvailableActions(id, Collections.EMPTY_MAP);
65         assertEquals("Unexpected number of actions available", 1, actions.length);
66         historySteps = workflow.getHistorySteps(id);
67         currentSteps = workflow.getCurrentSteps(id);
68         assertEquals("Unexpected number of current steps", 1, currentSteps.size());
69         assertEquals("Unexpected number of history steps", 2, historySteps.size());
70     }
71
72     public void testStepPostFunction() throws Exception JavaDoc {
73         URL JavaDoc url = getClass().getResource("/samples/step-post.xml");
74         long id = workflow.initialize(url.toString(), 1, null);
75         workflow.doAction(id, 2, null);
76         assertTrue("post-function was not called as expected", "postvalue".equals(workflow.getPropertySet(id).getString("postkey")));
77     }
78
79     public void testStepPreFunction() throws Exception JavaDoc {
80         URL JavaDoc url = getClass().getResource("/samples/step-pre.xml");
81         long id = workflow.initialize(url.toString(), 1, null);
82         assertTrue("pre-function was not called as expected", "prevalue".equals(workflow.getPropertySet(id).getString("prekey")));
83     }
84
85     protected void setUp() throws Exception JavaDoc {
86         workflow = new BasicWorkflow("testuser");
87     }
88 }
89
Popular Tags