Search in sources :

Example 1 with NonSerializableClass

use of org.jbpm.persistence.processinstance.objects.NonSerializableClass in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method testWithDatabaseAndStartProcess.

@Test
public void testWithDatabaseAndStartProcess() throws Exception {
    // Create variable
    Map<String, Object> params = new HashMap<String, Object>();
    NonSerializableClass processVar = new NonSerializableClass();
    processVar.setString("1234567890");
    params.put(VAR_NAME, processVar);
    // Persist variable
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    EntityManagerFactory emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
    EntityManager em = emf.createEntityManager();
    em.setFlushMode(FlushModeType.COMMIT);
    em.joinTransaction();
    em.persist(processVar);
    em.close();
    ut.commit();
    // Generate, insert, and start process
    ProcessInstance processInstance = ksession.startProcess(PROCESS_ID, params);
    // Test resuls
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    processVar = (NonSerializableClass) ((WorkflowProcessInstance) processInstance).getVariable(VAR_NAME);
    Assert.assertNotNull(processVar);
}
Also used : UserTransaction(javax.transaction.UserTransaction) NonSerializableClass(org.jbpm.persistence.processinstance.objects.NonSerializableClass) EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) InitialContext(javax.naming.InitialContext) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with NonSerializableClass

use of org.jbpm.persistence.processinstance.objects.NonSerializableClass in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method testWithDatabaseAndStartProcessInstance.

@Test
public void testWithDatabaseAndStartProcessInstance() throws Exception {
    // Create variable
    Map<String, Object> params = new HashMap<String, Object>();
    NonSerializableClass processVar = new NonSerializableClass();
    processVar.setString("1234567890");
    params.put(VAR_NAME, processVar);
    // Persist variable
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    EntityManagerFactory emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
    EntityManager em = emf.createEntityManager();
    em.setFlushMode(FlushModeType.COMMIT);
    em.joinTransaction();
    em.persist(processVar);
    em.close();
    ut.commit();
    // Create process,
    ProcessInstance processInstance = ksession.createProcessInstance(PROCESS_ID, params);
    long processInstanceId = processInstance.getId();
    Assert.assertTrue(processInstanceId > 0);
    Assert.assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    // insert process,
    ksession.insert(processInstance);
    // and start process
    ksession.startProcessInstance(processInstanceId);
    ksession.fireAllRules();
    // Test results
    processInstance = ksession.getProcessInstance(processInstanceId);
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    processVar = (NonSerializableClass) ((WorkflowProcessInstance) processInstance).getVariable(VAR_NAME);
    Assert.assertNotNull(processVar);
}
Also used : UserTransaction(javax.transaction.UserTransaction) NonSerializableClass(org.jbpm.persistence.processinstance.objects.NonSerializableClass) EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) InitialContext(javax.naming.InitialContext) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

HashMap (java.util.HashMap)2 InitialContext (javax.naming.InitialContext)2 EntityManager (javax.persistence.EntityManager)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 UserTransaction (javax.transaction.UserTransaction)2 NonSerializableClass (org.jbpm.persistence.processinstance.objects.NonSerializableClass)2 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)2 Test (org.junit.Test)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2