|
工作流模拟程序员面试过程情景如下: 1.开发知识面试或者笔试 2.人事面试 流程图: 
流程配置: - <?xmlversion="1.0"encoding="UTF-8"?>
- <definitionsxmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:activiti="http://activiti.org/bpmn"xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"typeLanguage="http://www.w3.org/2001/XMLSchema"expressionLanguage="http://www.w3.org/1999/XPath"targetNamespace="http://www.activiti.org/test">
- <processid="DeveloperWorkExam"name="DeveloperWorkExam">
- <startEventid="startevent1"name="准备面试"></startEvent>
- <endEventid="endevent1"name="面试通过"></endEvent>
- <receiveTaskid="receivetask1"name="笔试以及面试通过">
- <extensionElements>
- <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.DeveloperKnowledgeExamListener"></activiti:executionListener>
- </extensionElements>
- </receiveTask>
- <receiveTaskid="receivetask2"name="人事面试">
- <extensionElements>
- <activiti:executionListenerevent="start"class="com.easyway.workflow.activiti.exam.HumanResourceExamListener"></activiti:executionListener>
- </extensionElements>
- </receiveTask>
- <sequenceFlowid="flow1"name=""sourceRef="startevent1"targetRef="receivetask1"></sequenceFlow>
- <sequenceFlowid="flow2"name=""sourceRef="receivetask1"targetRef="receivetask2"></sequenceFlow>
- <sequenceFlowid="flow3"name=""sourceRef="receivetask2"targetRef="endevent1"></sequenceFlow>
- <sequenceFlowid="flow4"name=""sourceRef="receivetask1"targetRef="endevent1"></sequenceFlow>
- </process>
- </definitions>
spring配置application-context-standalone.xml如下: - <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
- <beanid="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
- <propertyname="driverClass"value="org.h2.Driver"/>
- <propertyname="url"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
- <propertyname="username"value="sa"/>
- <propertyname="password"value=""/>
- </bean>
- <beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <propertyname="dataSource"ref="dataSource"/>
- </bean>
- <beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
- <propertyname="dataSource"ref="dataSource"/>
- <propertyname="transactionManager"ref="transactionManager"/>
- <propertyname="databaseSchemaUpdate"value="true"/>
- <propertyname="mailServerHost"value="localhost"/>
- <propertyname="mailServerPort"value="5025"/>
- <propertyname="jpaHandleTransaction"value="true"/>
- <propertyname="jpaCloseEntityManager"value="true"/>
- <propertyname="jobExecutorActivate"value="false"/>
- </bean>
- <beanid="processEngine"class="org.activiti.spring.ProcessEngineFactoryBean">
- <propertyname="processEngineConfiguration"ref="processEngineConfiguration"/>
- </bean>
- <beanid="identityService"factory-bean="processEngine"factory-method="getIdentityService"/>
- <beanid="formService"factory-bean="processEngine"factory-method="getFormService"/>
- <beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/>
- <beanid="runtimeService"factory-bean="processEngine"factory-method="getRuntimeService"/>
- <beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/>
- <beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/>
- <beanid="managementService"factory-bean="processEngine"factory-method="getManagementService"/>
- </beans>
application-context.xml - <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
- <beanid="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
- <propertyname="driverClass"value="org.h2.Driver"/>
- <propertyname="url"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
- <propertyname="username"value="sa"/>
- <propertyname="password"value=""/>
- </bean>
- <beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <propertyname="dataSource"ref="dataSource"/>
- </bean>
- <beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
- <propertyname="dataSource"ref="dataSource"/>
- <propertyname="transactionManager"ref="transactionManager"/>
- <propertyname="databaseSchemaUpdate"value="true"/>
- <propertyname="mailServerHost"value="localhost"/>
- <propertyname="mailServerPort"value="5025"/>
- <propertyname="jpaHandleTransaction"value="true"/>
- <propertyname="jpaCloseEntityManager"value="true"/>
- <propertyname="jobExecutorActivate"value="false"/>
- <propertyname="deploymentResources"value="classpath*:diagrams/*.bpmn20.xml"/>
- </bean>
- <beanid="processEngine"class="org.activiti.spring.ProcessEngineFactoryBean">
- <propertyname="processEngineConfiguration"ref="processEngineConfiguration"/>
- </bean>
- <beanid="identityService"factory-bean="processEngine"factory-method="getIdentityService"/>
- <beanid="formService"factory-bean="processEngine"factory-method="getFormService"/>
- <beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/>
- <beanid="runtimeService"factory-bean="processEngine"factory-method="getRuntimeService"/>
- <beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/>
- <beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/>
- <beanid="managementService"factory-bean="processEngine"factory-method="getManagementService"/>
- </beans>
代码实现: - publicclassDeveloperKnowledgeExamListenerimplementsJavaDelegate{
- privateLoggerlogger=Logger.getLogger(DeveloperKnowledgeExamListener.class.getName());
- @Override
- publicvoidexecute(DelegateExecutionexecute)throwsException{
- logger.info("开始开发知识面试了....");
- Map<String,Object>variables=execute.getVariables();
- Set<Entry<String,Object>>infos=variables.entrySet();
- for(Entry<String,Object>entry:infos){
- logger.info(entry.getKey()+""+entry.getValue());
- }
- logger.info("开始开发知识面试了....");
- execute.setVariable("result","该考生开发知识面试通过了....");
- }
- }
- publicclassHumanResourceExamListenerimplementsJavaDelegate{
- privateLoggerlogger=Logger.getLogger(HumanResourceExamListener.class.getName());
- @Override
- publicvoidexecute(DelegateExecutionexecute)throwsException{
- logger.info("检查该考试是否通过开发知识考试....");
- Map<String,Object>variables=execute.getVariables();
- Stringreuslt=variables.get("result").toString();
- logger.info("开发知识面试结果"+reuslt);
- logger.info("开始人事面试了....");
- execute.setVariable("result","该考生开发知识面试通过了....");
- logger.info("人事面试完毕....等候通知....");
- }
- }
- @ContextConfiguration("classpath:application-context-standalone.xml")
- publicabstractclassAbstractSpringTestextendsAbstractTransactionalJUnit4SpringContextTests{
- @SuppressWarnings("unused")
- privatefinalLoggerlog=Logger.getLogger(AbstractSpringTest.class.getName());
- @SuppressWarnings("unused")
- @Autowired
- privateProcessEngineprocessEngine;
- @Autowired
- protectedRepositoryServicerepositoryService;
- @Autowired
- protectedRuntimeServiceruntimeService;
- @Autowired
- protectedTaskServicetaskService;
- @Autowired
- protectedHistoryServicehistoryService;
- @Autowired
- protectedManagementServicemanagementService;
- protectedStringdeploymentId;
- publicAbstractSpringTest(){
- super();
- }
- @Before
- publicvoidinitialize()throwsException{
- beforeTest();
- }
- @After
- publicvoidclean()throwsException{
- afterTest();
- }
- protectedabstractvoidbeforeTest()throwsException;
- protectedabstractvoidafterTest()throwsException;
- }
- @ContextConfiguration("classpath:application-context-standalone.xml")
- publicclassActivitiWithSpringStandaloneTestextendsAbstractSpringTest{
- @Override
- protectedvoidbeforeTest()throwsException{
- Deploymentdeployment=repositoryService
- .createDeployment()
- .addClasspathResource(
- "diagrams/SprintActiviti56.bpmn20.xml")
- .deploy();
- deploymentId=deployment.getId();
- }
- @Override
- protectedvoidafterTest()throwsException{
- repositoryService.deleteDeployment(deploymentId,true);
- }
- @Test
- publicvoidtriggerMyProcess(){
- Map<String,Object>variables=newHashMap<String,Object>();
- variables.put("姓名","程序员");
- variables.put("职务","高级软件工程师");
- variables.put("语言","Java/C#");
- variables.put("操作系统","Window,Linux,unix,Aix");
- variables.put("工作地点","苏州高新技术软件园");
- ProcessInstancepi=runtimeService.startProcessInstanceByKey("DeveloperWorkExam",variables);
- assert(pi!=null);
- List<Execution>executions=runtimeService.createExecutionQuery().list();
- assert(executions.size()==1);
- Executionexecution=runtimeService.createExecutionQuery().singleResult();
- runtimeService.setVariable(execution.getId(),"type","receiveTask");
- runtimeService.signal(execution.getId());
- executions=runtimeService.createExecutionQuery().list();
- assert(executions.size()==1);
- execution=executions.get(0);
- runtimeService.setVariable(execution.getId(),"oper","录用此人....");
- runtimeService.signal(execution.getId());
- }
- }
自动部署测试: - @ContextConfiguration("classpath:application-context.xml")
- publicclassActivitiWithSpringTestextendsAbstractTransactionalJUnit4SpringContextTests{
- @Autowired
- privateRuntimeServiceruntimeService;
- @Autowired
- privateTaskServicetaskService;
- @Autowired
- privateManagementServicemanagerService;
- @Autowired
- privateIdentityServiceidentityService;
- @Autowired
- privateFormServiceformService;
- @Test
- publicvoidtriggerMyProcess(){
- Map<String,Object>variables=newHashMap<String,Object>();
- variables.put("姓名","程序员");
- variables.put("职务","高级软件工程师");
- variables.put("语言","Java/C#");
- variables.put("操作系统","Window,Linux,unix,Aix");
- variables.put("工作地点","苏州高新技术软件园");
- ProcessInstancepi=runtimeService.startProcessInstanceByKey("DeveloperWorkExam",variables);
- assert(pi!=null);
- List<Execution>executions=runtimeService.createExecutionQuery().list();
- assert(executions.size()==1);
- Executionexecution=runtimeService.createExecutionQuery().singleResult();
- runtimeService.setVariable(execution.getId(),"type","receiveTask");
- runtimeService.signal(execution.getId());
- executions=runtimeService.createExecutionQuery().list();
- assert(executions.size()==1);
- execution=executions.get(0);
- runtimeService.setVariable(execution.getId(),"oper","录用此人....");
- runtimeService.signal(execution.getId());
- }
- }
|