Search in sources :

Example 1 with TestWorkItemHandler

use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class PersistentStatefulSessionTest method testPersistenceWorkItems.

@Test
public void testPersistenceWorkItems() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    int origNumObjects = ksession.getObjects().size();
    long id = ksession.getIdentifier();
    ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
    ksession.insert("TestString");
    logger.debug("Started process instance {}", processInstance.getId());
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertEquals(origNumObjects + 1, ksession.getObjects().size());
    for (Object o : ksession.getObjects()) {
        logger.debug(o.toString());
    }
    assertNull(processInstance);
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with TestWorkItemHandler

use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class PersistentStatefulSessionTest method testPersistenceSubProcess.

@Test
public void testPersistenceSubProcess() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("SuperProcess.rf"), ResourceType.DRF);
    kbuilder.add(new ClassPathResource("SubProcess.rf"), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    long id = ksession.getIdentifier();
    ProcessInstance processInstance = ksession.startProcess("com.sample.SuperProcess");
    logger.debug("Started process instance {}", processInstance.getId());
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull("Process did not complete.", processInstance);
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with TestWorkItemHandler

use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class PersistentStatefulSessionTest method testPersistenceWorkItems2.

@Test
public void testPersistenceWorkItems2() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    long id = ksession.getIdentifier();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
    ksession.insert("TestString");
    logger.debug("Started process instance {}", processInstance.getId());
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ut.commit();
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    workItem = handler.getWorkItem();
    assertNull(workItem);
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertEquals(1, ksession.getObjects().size());
    for (Object o : ksession.getObjects()) {
        logger.debug(o.toString());
    }
    assertNull(processInstance);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InitialContext(javax.naming.InitialContext) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with TestWorkItemHandler

use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceWorkItemsUserTransaction.

@Test
public void testPersistenceWorkItemsUserTransaction() throws Exception {
    setUp();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Collection<KiePackage> kpkgs = getProcessWorkItems();
    kbase.addPackages(kpkgs);
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    PersistableRunner service = new PersistableRunner(kbase, config, env);
    Long sessionId = service.getSessionId();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    ProcessInstance processInstance = service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    ut.commit();
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    ut.commit();
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNull(processInstance);
    service.dispose();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) InitialContext(javax.naming.InitialContext) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) SessionConfiguration(org.drools.core.SessionConfiguration) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 5 with TestWorkItemHandler

use of org.jbpm.persistence.session.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceWorkItems.

@Test
public void testPersistenceWorkItems() throws Exception {
    setUp();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Collection<KiePackage> kpkgs = getProcessWorkItems();
    kbase.addPackages(kpkgs);
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    PersistableRunner service = new PersistableRunner(kbase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    ProcessInstance processInstance = service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
    service.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) SessionConfiguration(org.drools.core.SessionConfiguration) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) 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