use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class VariablePersistenceStrategyTest method testPersistenceVariablesWithTypeChange.
@Test
public void testPersistenceVariablesWithTypeChange() throws NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
MyEntityMethods myEntityMethods = new MyEntityMethods("This is a test Entity with annotations in methods");
MyEntityOnlyFields myEntityOnlyFields = new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods");
MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
EntityManager em = emf.createEntityManager();
UserTransaction utx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
int s = utx.getStatus();
if (utx.getStatus() == Status.STATUS_NO_TRANSACTION) {
utx.begin();
}
em.joinTransaction();
em.persist(myEntity);
em.persist(myEntityMethods);
em.persist(myEntityOnlyFields);
if (utx.getStatus() == Status.STATUS_ACTIVE) {
utx.commit();
}
em.close();
Environment env = createEnvironment();
KieBase kbase = createKnowledgeBase("VariablePersistenceStrategyProcessTypeChange.rf");
KieSession ksession = createSession(kbase, env);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("x", "SomeString");
parameters.put("y", myEntity);
parameters.put("m", myEntityMethods);
parameters.put("f", myEntityOnlyFields);
parameters.put("z", myVariableSerializable);
long processInstanceId = ksession.startProcess("com.sample.ruleflow", parameters).getId();
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession = reloadSession(ksession, kbase, env);
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
assertNotNull(processInstance);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession = reloadSession(ksession, kbase, env);
processInstance = ksession.getProcessInstance(processInstanceId);
assertNotNull(processInstance);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNull(workItem);
ksession = reloadSession(ksession, kbase, env);
processInstance = ksession.getProcessInstance(processInstanceId);
assertNull(processInstance);
}
Aggregations