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.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 21 28 public class ActionsTestCase extends TestCase { 29 31 public String myvar; 33 private AbstractWorkflow workflow; 34 35 37 public ActionsTestCase(String s) { 38 super(s); 39 } 40 41 43 public void testAutoWithSplit() throws Exception { 44 URL url = getClass().getResource("/samples/auto-split.xml"); 45 long id = workflow.initialize(url.toString(), 1, null); 46 List currentSteps = workflow.getCurrentSteps(id); 47 assertEquals("Unexpected number of current steps", 2, currentSteps.size()); 48 } 49 50 public void testConditionCheck() throws Exception { 51 long id = workflow.initialize(getClass().getResource("/samples/auto4.xml").toString(), 1, null); 52 List currentSteps = workflow.getCurrentSteps(id); 53 assertEquals("Unexpected number of current steps", 1, currentSteps.size()); 54 assertEquals("Unexpected current step", 3, ((Step) currentSteps.get(0)).getStepId()); 55 } 56 57 public void testExecOnlyOne() throws Exception { 58 long id = workflow.initialize(getClass().getResource("/samples/auto2.xml").toString(), 1, null); 59 List currentSteps = workflow.getCurrentSteps(id); 60 assertEquals("Unexpected number of current steps", 1, currentSteps.size()); 61 assertEquals("Unexpected current step", 4, ((Step) currentSteps.get(0)).getStepId()); 62 63 List history = workflow.getHistorySteps(id); 64 assertEquals("Expected to have one history step", 1, history.size()); 65 assertEquals("Unexpected history step", 2, ((Step) history.get(0)).getStepId()); 66 } 67 68 public void testExecTwoActions() throws Exception { 69 long id = workflow.initialize(getClass().getResource("/samples/auto3.xml").toString(), 1, null); 70 List currentSteps = workflow.getCurrentSteps(id); 71 assertEquals("Unexpected number of current steps", 1, currentSteps.size()); 72 assertEquals("Unexpected current step", 3, ((Step) currentSteps.get(0)).getStepId()); 73 74 List history = workflow.getHistorySteps(id); 75 assertEquals("Expected to have two history steps", 2, history.size()); 76 assertEquals("Unexpected first history step", 1, ((Step) history.get(0)).getStepId()); 77 assertEquals("Unexpected second history step", 2, ((Step) history.get(1)).getStepId()); 78 } 79 80 public void testPropertySetCreated() throws Exception { 81 Map inputs = new HashMap (); 82 List list = new ArrayList (); 83 inputs.put("list", list); 84 85 long id = workflow.initialize(getClass().getResource("/samples/propertyset-create.xml").toString(), 1, inputs); 86 String value = (String ) list.get(0); 87 assertEquals("Unexpected property set value for key myvar", "anything", value); 88 89 List currentSteps = workflow.getCurrentSteps(id); 90 assertEquals("Unexpected number of current steps", 1, currentSteps.size()); 91 assertEquals("Unexpected current step", 1, ((Step) currentSteps.get(0)).getStepId()); 92 } 93 94 public void testSimpleAuto() throws Exception { 95 long id = workflow.initialize(getClass().getResource("/samples/auto1.xml").toString(), 1, null); 96 List currentSteps = workflow.getCurrentSteps(id); 97 assertEquals("Unexpected number of current steps", 1, currentSteps.size()); 98 assertEquals("Unexpected current step", 2, ((Step) currentSteps.get(0)).getStepId()); 99 } 100 101 public void testSimpleFinish() throws Exception { 102 long id = workflow.initialize(getClass().getResource("/samples/finish1.xml").toString(), 1, null); 103 workflow.doAction(id, 1, null); 104 assertTrue("Finished workflow should have no current actions", workflow.getCurrentSteps(id).size() == 0); 105 assertEquals("Unexpected workflow entry state", WorkflowEntry.COMPLETED, workflow.getEntryState(id)); 106 107 List historySteps = workflow.getHistorySteps(id); 108 109 assertEquals("Unexpected status of last history step", "LastFinished", ((Step) historySteps.get(historySteps.size() - 1)).getStatus()); 111 } 112 113 protected void setUp() throws Exception { 114 workflow = new BasicWorkflow("testuser"); 115 } 116 } 117 | Popular Tags |