1 5 6 package org.exoplatform.services.workflow.test; 7 8 import org.exoplatform.services.exception.ExoServiceException; 9 import org.exoplatform.services.workflow.WorkflowExecutionService; 10 import org.jbpm.ExecutionException; 11 import org.jbpm.JpdlException; 12 import org.jbpm.model.definition.Definition; 13 import org.jbpm.model.execution.Token; 14 import org.jbpm.model.log.InvocationLog; 15 16 import java.io.IOException ; 17 import java.util.Collection ; 18 import java.util.Date ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 23 28 public class TestHolidayProcess extends BaseTest{ 29 30 private static final String PROCESS_FILE = "holidays.xml"; 31 32 public TestHolidayProcess(String name) { 33 super(name); 34 } 35 36 protected String getDescription() { 37 return "test holiday process"; 38 } 39 40 public void setUp() { 41 super.setUp(); 42 try { 43 deployProcess(PROCESS_FILE, null); 44 } catch (IOException e) { 45 e.printStackTrace(); 46 } catch (JpdlException e) { 47 e.printStackTrace(); 48 } catch (ExoServiceException e) { 49 e.printStackTrace(); 50 } 51 } 52 53 public void testProcessRegistration() { 54 WorkflowExecutionService executionService = workflowServiceContainer. 55 createWorkflowExecutionService(); 56 Definition definition = (Definition) executionService.getAllDefinitions().get(0); 57 assertEquals("holiday process", definition.getName()); 58 assertEquals(1, definition.getVersion().intValue()); 59 assertEquals("request", definition.getStartState().getName()); 60 61 Collection latestDefinitions = executionService.getLatestDefinitions(); 62 definition = (Definition) latestDefinitions.iterator().next(); 63 assertEquals("holiday process", definition.getName()); 64 assertEquals(1, definition.getVersion().intValue()); 65 assertEquals("request", definition.getStartState().getName()); 66 executionService.close(); 67 } 68 69 public void testProcessStart() throws ExecutionException { 70 WorkflowExecutionService executionService = workflowServiceContainer. 71 createWorkflowExecutionService(); 72 Collection latestDefinitions = executionService.getLatestDefinitions(); 73 Definition definition = (Definition) latestDefinitions.iterator().next(); 74 Map variables = new HashMap (); 75 Date start = new Date (); 76 variables.put("start.date", start); 77 variables.put("end.date", new Date (start.getTime() + 24*3600)); 78 79 InvocationLog iL = executionService.startProcessInstance("benj", definition.getId(), variables); 80 assertEquals("benj", iL.getActorId()); 81 82 Token token = (Token) executionService.getTaskList("bossOfBenj", null).iterator().next(); 83 assertNotNull(token); 84 assertEquals("bossOfBenj", token.getActorId()); 85 assertEquals("evaluation", token.getState().getName()); 86 iL = executionService.endOfState("bossOfBenj", token.getId(), variables, "approve"); 87 88 token = (Token) executionService.getTaskList("bossOfBenj", null).iterator().next(); 89 assertNotNull(token); 90 assertEquals("bossOfBenj", token.getActorId()); 91 assertEquals("assign replacement", token.getState().getName()); 92 executionService.endOfState("bossOfBenj", token.getId(), variables); 93 94 token = (Token) executionService.getTaskList("Hrofbenj", null).iterator().next(); 95 assertNotNull(token); 96 assertEquals("Hrofbenj", token.getActorId()); 97 assertEquals("hr acknowledgement", token.getState().getName()); 98 executionService.endOfState("Hrofbenj", token.getId(), variables); 99 executionService.close(); 100 } 101 102 } 103 | Popular Tags |