标签:jbpm nts equal back object throws ble factor tom
<persistence
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<mapping-file>META-INF/TaskAuditorm.xml</mapping-file>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<!-- manager -->
<class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
<class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
<class>org.jbpm.services.task.impl.model.ContentImpl</class>
<class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.DelegationImpl</class>
<class>org.jbpm.services.task.impl.model.EscalationImpl</class>
<class>org.jbpm.services.task.impl.model.GroupImpl</class>
<class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
<class>org.jbpm.services.task.impl.model.NotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
<class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class>
<class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
<class>org.jbpm.services.task.impl.model.TaskImpl</class>
<class>org.jbpm.services.task.impl.model.TaskDataImpl</class>
<class>org.jbpm.services.task.impl.model.UserImpl</class>
<!--BAM for task service -->
<class>org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl</class>
<!-- Event Classes -->
<class>org.jbpm.services.task.audit.impl.model.TaskEventImpl</class>
<!-- Task Audit Classes -->
<class>org.jbpm.services.task.audit.impl.model.AuditTaskImpl</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.show_sql" value="true" />
<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform" />
</properties>
</persistence-unit>
</persistence>
package com.chenwd.jbpm.test.base;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.jbpm.process.audit.strategy.StandaloneJtaStrategy;
import org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder;
import org.jbpm.services.task.identity.JBossUserGroupCallbackImpl;
import org.junit.After;
import org.junit.Before;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.manager.RuntimeEnvironment;
import org.kie.api.runtime.manager.RuntimeManager;
import org.kie.api.runtime.manager.RuntimeManagerFactory;
import org.kie.api.task.UserGroupCallback;
import org.kie.internal.io.ResourceFactory;
import bitronix.tm.resource.jdbc.PoolingDataSource;
public class jbpmTestBase {
protected static EntityManagerFactory emf;
protected static StandaloneJtaStrategy persistenceStrategy;
protected static EntityManager em;
private static PoolingDataSource ds;
@Before
public void setup() {
ds = setupDataSource();
Map configOverrides = new HashMap();
configOverrides.put("hibernate.hbm2ddl.auto", "none");
configOverrides.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa", configOverrides);
if(emf != null){
persistenceStrategy = new StandaloneJtaStrategy(emf);
em = persistenceStrategy.getEntityManager();
}
}
@After
public void teardown() {
if (ds != null) {
ds.close();
}
}
protected static void out(Object o){
System.out.println(String.valueOf(o));
}
private static RuntimeManager getRuntimeManager(String process) {
Properties properties = new Properties();
properties.setProperty("krisv", "");
properties.setProperty("mary", "");
properties.setProperty("john", "");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault().persistence(true)
.entityManagerFactory(emf).userGroupCallback(userGroupCallback)
.addAsset(ResourceFactory.newClassPathResource(process), ResourceType.BPMN2)
.get();
return RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
}
private static PoolingDataSource setupDataSource() {
PoolingDataSource pds = new PoolingDataSource();
pds.setUniqueName("jdbc/jbpm-ds");
pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
pds.setMaxPoolSize(5);
pds.setAllowLocalTransactions(true);
pds.getDriverProperties().put("user", "root");
pds.getDriverProperties().put("password", "root");
pds.getDriverProperties().put("url", "jdbc:mysql://localhost:3306/jbpm2");
pds.getDriverProperties().put("driverClassName", "com.mysql.jdbc.Driver");
pds.init();
return pds;
}
}
private static RuntimeManager getRuntimeManager(String process) {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault().persistence(true)
.entityManagerFactory(emf).userGroupCallback(new UserGroupCallback() {
public List<String> getGroupsForUser(String userId, List<String> groupIds, List<String> allExistingGroupIds) {
List<String> result = new ArrayList<String>();
if ("chenwd".equals(userId)) {
result.add("group1");
}
return result;
}
public boolean existsUser(String arg0) {
return true;
}
public boolean existsGroup(String arg0) {
return true;
}
})
.addAsset(ResourceFactory.newClassPathResource(process), ResourceType.BPMN2)
.get();
return RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
}
之后我们的详细測试类能够继承这个类。获取kieSession和taskServcie进行流程发起和task处理。示比例如以下所看到的。
public class JbpmTest extends JbpmTestBase{
@Test
public void testStartProcess() throws Exception {
try {
RuntimeManager manager = getRuntimeManager("sample.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
//设置流程variables。发起流程
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
manager.disposeRuntimeEngine(runtime);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
标签:jbpm nts equal back object throws ble factor tom
原文地址:http://www.cnblogs.com/yangykaifa/p/7071664.html