Search in sources :

Example 21 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.

@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
    // prepare listener to assert results
    Properties properties = new Properties();
    properties.setProperty("mary", "HR");
    properties.setProperty("john", "HR");
    UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    long ksessionId = ksession.getIdentifier();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "R3/PT1S");
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    // get tasks
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    runtime.getTaskService().start(task.getId(), "john");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    try {
        ut.begin();
        runtime.getTaskService().complete(task.getId(), "john", null);
    } finally {
        ut.rollback();
    }
    processInstance = ksession.getProcessInstance(processInstance.getId());
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
    TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
    assertNotNull(timerInstances);
    assertEquals(0, timerInstances.size());
    // clean up
    ksession.abortProcessInstance(processInstance.getId());
    manager.disposeRuntimeEngine(runtime);
}
Also used : Status(org.kie.api.task.model.Status) UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) TimerService(org.drools.core.time.TimerService) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 22 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.

the class ServiceTaskHandlerTest method assertServiceTaskCompleted.

private void assertServiceTaskCompleted(String processName, int jbpmmodule) throws Exception {
    if (jbpmmodule == BPMN2) {
        ksession.getWorkItemManager().registerWorkItemHandler("Service Task", bpmn2Handler);
    } else if (jbpmmodule == WORKITEMS) {
        ksession.getWorkItemManager().registerWorkItemHandler("Service Task", workitemsHandler);
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("IntegerVar", new Integer(12345));
    params.put("DateVar", new Date());
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess(processName.replace("-", ""), params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertEquals(Integer.valueOf(1), processInstance.getVariable("IntegerVar"));
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance)

Example 23 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.

the class EventSubprocessTest method testErrorCodeException.

@Test
@BZ("1082111")
public void testErrorCodeException() {
    KieSession ksession = createKSession(ERROR_CODE_EXCEPTION);
    ksession.getWorkItemManager().registerWorkItemHandler("Request Handler", new SignallingTaskHandlerDecorator(ExceptionOnPurposeHandler.class, "Error-90277"));
    ksession.getWorkItemManager().registerWorkItemHandler("Error Handler", new SystemOutWorkItemHandler());
    try {
        ProcessInstance processInstance = ksession.startProcess(ERROR_CODE_EXCEPTION_ID);
        assertProcessInstanceNotActive(processInstance.getId(), ksession);
        Assertions.assertThat(((WorkflowProcessInstance) processInstance).getOutcome()).isEqualTo("90277");
    } catch (WorkflowRuntimeException e) {
        fail("Error code exceptions in subprocess does not work.");
    }
}
Also used : SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 24 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testXStreamUnmarshalCustomObject.

@Test
public void testXStreamUnmarshalCustomObject() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "xstream-test", VERSION);
    File kjar = new File("src/test/resources/kjar/jbpm-module.jar");
    File pom = new File("src/test/resources/kjar/pom.xml");
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kjar, pom);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("Rest", new WorkItemHandler() {

                @Override
                public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                    Map<String, Object> results = new HashMap<String, Object>();
                    results.put("Result", "<pv207.finepayment.Client><exists>true</exists><name>Pavel</name></pv207.finepayment.Client>");
                    manager.completeWorkItem(workItem.getId(), results);
                }

                @Override
                public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
                }
            });
            return handlers;
        }
    }).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("RESTTask.RestProcess", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    Object processClient = ((WorkflowProcessInstance) processInstance).getVariable("processClient");
    assertNotNull(processClient);
    assertEquals("pv207.finepayment.Client", processClient.getClass().getName());
    assertEquals("Pavel", valueOf(processClient, "name"));
    assertEquals("true", valueOf(processClient, "exists"));
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)24 HashMap (java.util.HashMap)16 Test (org.junit.Test)15 KieSession (org.kie.api.runtime.KieSession)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 Date (java.util.Date)6 RegistryContext (org.drools.core.command.impl.RegistryContext)5 Context (org.kie.api.runtime.Context)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)3 NodeInstance (org.kie.api.runtime.process.NodeInstance)3 Matcher (java.util.regex.Matcher)2 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)2 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2