1 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 ; 14 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 19 22 public class CommonAndGlobalActionsTestCase extends TestCase { 23 25 private Workflow workflow; 26 27 29 public void testBasicCommonAction() throws Exception { 30 URL 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 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", historyStep.getStatus()); 40 41 workflow.doAction(id, 1, null); 43 44 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 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 { 59 URL 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 [] list = new Object [availableActions.length]; 64 65 for (int i = 0; i < availableActions.length; i++) { 66 list[i] = new Integer (availableActions[i]); 67 } 68 69 assertTrue("Unexpected available actions " + Arrays.asList(list), Arrays.equals(new int[] { 70 100, 101, 1 71 }, availableActions)); 72 73 workflow.doAction(id, 100, null); 75 76 List historySteps = workflow.getHistorySteps(id); 77 Step historyStep = (Step) historySteps.get(0); 78 assertEquals("Unexpected old status set", "Restarted", historyStep.getStatus()); 79 80 workflow.doAction(id, 1, null); 82 83 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 { 91 workflow = new BasicWorkflow("test"); 92 } 93 } 94 | Popular Tags |