KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.opensymphony.workflow.spi.WorkflowEntry;
10
11 import junit.framework.TestCase;
12
13 import java.net.URL JavaDoc;
14
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17
18
19 /**
20  * @author hani Date: Apr 24, 2004 Time: 12:35:01 PM
21  */

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

25     private Workflow workflow;
26
27     //~ Methods ////////////////////////////////////////////////////////////////
28

29     public void testBasicCommonAction() throws Exception JavaDoc {
30         URL JavaDoc url = getClass().getResource("/samples/common-actions.xml");
31         long id = workflow.initialize(url.toString(), 1, null);
32         assertEquals("Unexpected workflow state", WorkflowEntry.ACTIVATED, workflow.getEntryState(id));
33
34         //verify that a common action can be called
35
workflow.doAction(id, 100, null);
36
37         List JavaDoc historySteps = workflow.getHistorySteps(id);
38         Step historyStep = (Step) historySteps.get(0);
39         assertEquals("Unexpected old status set", "Restarted", historyStep.getStatus());
40
41         //now let's move to step 2
42
workflow.doAction(id, 1, null);
43
44         //now let's check if we can call a non-specified common action
45
try {
46             workflow.doAction(id, 100, null);
47             fail("Should not be able to call non-explicitly specified common-action");
48         } catch (InvalidActionException e) {
49         }
50
51         //now test -1 stepId stuff.
52
workflow.doAction(id, 101, null);
53         historySteps = workflow.getHistorySteps(id);
54         historyStep = (Step) historySteps.get(historySteps.size() - 1);
55         assertEquals("Unexpected old status set", "Finished", historyStep.getStatus());
56     }
57
58     public void testBasicGlobalAction() throws Exception JavaDoc {
59         URL JavaDoc url = getClass().getResource("/samples/global-actions.xml");
60         long id = workflow.initialize(url.toString(), 1, null);
61
62         int[] availableActions = workflow.getAvailableActions(id, null);
63         Object JavaDoc[] list = new Object JavaDoc[availableActions.length];
64
65         for (int i = 0; i < availableActions.length; i++) {
66             list[i] = new Integer JavaDoc(availableActions[i]);
67         }
68
69         assertTrue("Unexpected available actions " + Arrays.asList(list), Arrays.equals(new int[] {
70                     100, 101, 1
71                 }, availableActions));
72
73         //verify that a global action can be called
74
workflow.doAction(id, 100, null);
75
76         List JavaDoc historySteps = workflow.getHistorySteps(id);
77         Step historyStep = (Step) historySteps.get(0);
78         assertEquals("Unexpected old status set", "Restarted", historyStep.getStatus());
79
80         //now let's move to step 2
81
workflow.doAction(id, 1, null);
82
83         //now test -1 stepId stuff.
84
workflow.doAction(id, 101, null);
85         historySteps = workflow.getHistorySteps(id);
86         historyStep = (Step) historySteps.get(historySteps.size() - 1);
87         assertEquals("Unexpected old status set", "Finished", historyStep.getStatus());
88     }
89
90     protected void setUp() throws Exception JavaDoc {
91         workflow = new BasicWorkflow("test");
92     }
93 }
94
Popular Tags