jbpm51介绍(8)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

jbpm5.1介绍(8)Junit测试或流程下面的示例中使用的是或流程,看如下流程图判断节点的值是大于0,大于10还是大于20看测试程序?传入的值是15,那么执行结果应该是path1和path2,因为两个节点都满足条件看输出结果LoadingprocessBPMN2-InclusiveSplit.bpmn2path1path2可以再使用其它值进行测试Junit测试或流程2这个示例同上,但是不同的是当执行流程结点如果没有发现符合条件的节点那么自动执行默认的流程测试程序?publicvoidtestInclusiveSplitDefault()throwsException{KnowledgeBasekbase=createKnowledgeBase(BPMN2-InclusiveSplitDefault.bpmn2);StatefulKnowledgeSessionksession=createKnowledgeSession(kbase);MapString,Objectparams=newHashMapString,Object();params.put(x,-5);ProcessInstanceprocessInstance=ksession.startProcess(com.sample.test,params);assertTrue(processInstance.getState()==ProcessInstance.STATE_COMPLETED);}执行结果如下publicvoidtestInclusiveSplit()throwsException{KnowledgeBasekbase=createKnowledgeBase(BPMN2-InclusiveSplit.bpmn2);StatefulKnowledgeSessionksession=createKnowledgeSession(kbase);MapString,Objectparams=newHashMapString,Object();params.put(x,15);ProcessInstanceprocessInstance=ksession.startProcess(com.sample.test,params);assertTrue(processInstance.getState()==ProcessInstance.STATE_COMPLETED);}LoadingprocessBPMN2-InclusiveSplitDefault.bpmn2path3Junit测试触发事件这个示例是演示在执行流程的过程中触发事件的示例,当执行到什么的时候触发什么样的流程其中加入了两个事件,触发条件是YES或者No,然后在下面的程序中分别触发?publicvoidtestEventBasedSplit()throwsException{KnowledgeBasekbase=createKnowledgeBase(BPMN2-EventBasedSplit.bpmn2);StatefulKnowledgeSessionksession=createKnowledgeSession(kbase);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());//YesProcessInstanceprocessInstance=ksession.startProcess(com.sample.test);assertTrue(processInstance.getState()==ProcessInstance.STATE_ACTIVE);ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());ksession.signalEvent(Yes,YesValue,processInstance.getId());assertProcessInstanceCompleted(processInstance.getId(),ksession);//NoprocessInstance=ksession.startProcess(com.sample.test);assertTrue(processInstance.getState()==ProcessInstance.STATE_ACTIVE);ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());ksession.signalEvent(No,NoValue,processInstance.getId());assertProcessInstanceCompleted(processInstance.getId(),ksession);}分别触发,得到的执行结果是LoadingprocessBPMN2-EventBasedSplit.bpmn2ExecutingworkitemWorkItem1[name=Email1,state=0,processInstanceId=1,parameters{}]ExecutingYesx=YesValueExecutingworkitemWorkItem2[name=Email2,state=0,processInstanceId=1,parameters{}]ExecutingworkitemWorkItem3[name=Email1,state=0,processInstanceId=2,parameters{}]ExecutingNox=NoValueExecutingworkitemWorkItem4[name=Email2,state=0,processInstanceId=2,parameters{}]Junit测试触发时间事件这个示例是演示运行的过程中如果触发时间事件将执行什么样的结果流程图如下所示在执行的过程中在执行到时间节点后会看到有一个延时我们这里设置的是500ms测试程序如下:?publicvoidtestEventBasedSplit2()throwsException{KnowledgeBasekbase=createKnowledgeBase(BPMN2-EventBasedSplit2.bpmn2);StatefulKnowledgeSessionksession=createKnowledgeSession(kbase);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());//YesProcessInstanceprocessInstance=ksession.startProcess(com.sample.test);assertTrue(processInstance.getState()==ProcessInstance.STATE_ACTIVE);ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());ksession.signalEvent(Yes,YesValue,processInstance.getId());assertProcessInstanceCompleted(processInstance.getId(),ksession);Thread.sleep(800);ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());ksession.fireAllRules();ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());//TimerprocessInstance=ksession.startProcess(com.sample.test);assertTrue(processInstance.getState()==ProcessInstance.STATE_ACTIVE);Thread.sleep(800);ksession=restoreSession(ksession,true);ksession.getWorkItemManager().registerWorkItemHandler(Email1,newSystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler(Email2,newSystemOutWorkItemHandler());ksession.fireAllRules();assertProcessInstanceCompleted(processInstance.getId(),ksession);}测试结果LoadingprocessBPMN2-EventBasedSplit2.bpmn2ExecutingworkitemWorkItem1[name=Email1,state=0,processInstanceId=1,parameters{}]ExecutingYesx=YesValueExecutingworkitemWor

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功