1 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 ; 13 14 import java.util.*; 15 16 17 22 public class StepsTestCase extends TestCase { 23 25 private AbstractWorkflow workflow; 26 27 29 public StepsTestCase(String s) { 30 super(s); 31 } 32 33 35 public void testEarlyJoin() throws Exception { 36 URL 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 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 { 51 URL 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 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 { 73 URL 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 { 80 URL 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 { 86 workflow = new BasicWorkflow("testuser"); 87 } 88 } 89 | Popular Tags |