Search in sources :

Example 16 with TestWorkItemHandler

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);
}
Also used : MyEntity(org.jbpm.persistence.session.objects.MyEntity) UserTransaction(javax.transaction.UserTransaction) TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) InitialContext(javax.naming.InitialContext) MyEntityOnlyFields(org.jbpm.persistence.session.objects.MyEntityOnlyFields) EntityManager(javax.persistence.EntityManager) MyEntityMethods(org.jbpm.persistence.session.objects.MyEntityMethods) KieBase(org.kie.api.KieBase) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) MyVariableSerializable(org.jbpm.persistence.session.objects.MyVariableSerializable) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)16 Test (org.junit.Test)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)13 WorkItem (org.kie.api.runtime.process.WorkItem)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)8 KieBase (org.kie.api.KieBase)8 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)8 InitialContext (javax.naming.InitialContext)7 UserTransaction (javax.transaction.UserTransaction)7 HashMap (java.util.HashMap)6 EntityManager (javax.persistence.EntityManager)5 ClassPathResource (org.drools.core.io.impl.ClassPathResource)5 MyEntity (org.jbpm.persistence.session.objects.MyEntity)5 MyVariableSerializable (org.jbpm.persistence.session.objects.MyVariableSerializable)5 Environment (org.kie.api.runtime.Environment)5 KieSession (org.kie.api.runtime.KieSession)5 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)5 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)5 Properties (java.util.Properties)3