01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow;
06:
07: import com.opensymphony.workflow.basic.BasicWorkflow;
08: import com.opensymphony.workflow.spi.Step;
09: import com.opensymphony.workflow.spi.WorkflowEntry;
10:
11: import junit.framework.TestCase;
12:
13: import java.net.URL;
14:
15: import java.util.Arrays;
16: import java.util.List;
17:
18: /**
19: * @author hani Date: Apr 24, 2004 Time: 12:35:01 PM
20: */
21: public class CommonAndGlobalActionsTestCase extends TestCase {
22: //~ Instance fields ////////////////////////////////////////////////////////
23:
24: private Workflow workflow;
25:
26: //~ Methods ////////////////////////////////////////////////////////////////
27:
28: public void testBasicCommonAction() throws Exception {
29: URL url = getClass().getResource("/samples/common-actions.xml");
30: long id = workflow.initialize(url.toString(), 50, null);
31: assertEquals("Unexpected workflow state",
32: WorkflowEntry.ACTIVATED, workflow.getEntryState(id));
33:
34: //verify that a common action can be called
35: workflow.doAction(id, 100, null);
36:
37: List historySteps = workflow.getHistorySteps(id);
38: Step historyStep = (Step) historySteps.get(0);
39: assertEquals("Unexpected old status set", "Restarted",
40: historyStep.getStatus());
41:
42: //now let's move to step 2
43: workflow.doAction(id, 1, null);
44:
45: //now let's check if we can call a non-specified common action
46: try {
47: workflow.doAction(id, 100, null);
48: fail("Should not be able to call non-explicitly specified common-action");
49: } catch (InvalidActionException e) {
50: }
51:
52: //now test -1 stepId stuff.
53: workflow.doAction(id, 101, null);
54: historySteps = workflow.getHistorySteps(id);
55: historyStep = (Step) historySteps.get(0);
56: assertEquals("Unexpected old status set", "Finished",
57: historyStep.getStatus());
58: }
59:
60: public void testBasicGlobalAction() throws Exception {
61: URL url = getClass().getResource("/samples/global-actions.xml");
62: long id = workflow.initialize(url.toString(), 50, null);
63:
64: int[] availableActions = workflow.getAvailableActions(id, null);
65: Object[] list = new Object[availableActions.length];
66:
67: for (int i = 0; i < availableActions.length; i++) {
68: list[i] = new Integer(availableActions[i]);
69: }
70:
71: assertTrue("Unexpected available actions "
72: + Arrays.asList(list), Arrays.equals(new int[] { 100,
73: 101, 1 }, availableActions));
74:
75: //verify that a global action can be called
76: workflow.doAction(id, 100, null);
77:
78: List historySteps = workflow.getHistorySteps(id);
79: Step historyStep = (Step) historySteps.get(0);
80: assertEquals("Unexpected old status set", "Restarted",
81: historyStep.getStatus());
82:
83: //now let's move to step 2
84: workflow.doAction(id, 1, null);
85:
86: //now test -1 stepId stuff.
87: workflow.doAction(id, 101, null);
88: historySteps = workflow.getHistorySteps(id);
89: historyStep = (Step) historySteps.get(0);
90: assertEquals("Unexpected old status set", "Finished",
91: historyStep.getStatus());
92: }
93:
94: protected void setUp() throws Exception {
95: workflow = new BasicWorkflow("test");
96: }
97: }
|