Search in sources :

Example 66 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class AsyncTaskTest method testTaskErrorHandling.

@Test(timeout = 10000)
public void testTaskErrorHandling() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
    addProcessEventListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("command", USER_FAILING_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_ID, pm);
    assertNodeTriggered(pi.getId(), "Start", "Hello", "Task 1");
    assertNodeNotTriggered(pi.getId(), "Output");
    assertNodeNotTriggered(pi.getId(), "Runtime Error Handling");
    assertNodeNotTriggered(pi.getId(), "Illegal Argument Error Handling");
    // Wait for the 4 retries to fail
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNull(processInstance);
    assertNodeTriggered(pi.getId(), "Runtime Error Handling", "RuntimeErrorEnd");
    assertNodeNotTriggered(pi.getId(), "Output");
    assertNodeNotTriggered(pi.getId(), "Illegal Argument Error Handling");
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext())).hasSize(1);
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext()).get(0).getErrorInfo().get(0).getMessage()).isEqualTo("Internal Error");
    assertProcessInstanceCompleted(pi.getId());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 67 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class AsyncTaskTest method testTaskComplete.

@Test(timeout = 10000)
@BZ("1121027")
public void testTaskComplete() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Process async", 1);
    CountDownAsyncJobListener countDownJobListener = new CountDownAsyncJobListener(1);
    try {
        ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownJobListener);
        addProcessEventListener(countDownListener);
        KieSession ksession = createKSession(ASYNC_DATA_EXECUTOR);
        WorkItemManager wim = ksession.getWorkItemManager();
        wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
        Map<String, Object> pm = new HashMap<String, Object>();
        pm.put("command", USER_COMMAND);
        ProcessInstance pi = ksession.startProcess(ASYNC_DATA_EXECUTOR_ID, pm);
        assertNodeTriggered(pi.getId(), "StartProcess", "Set user info", "Process async");
        // Wait for the job to complete
        countDownListener.waitTillCompleted();
        ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
        assertNull(processInstance);
        assertNodeTriggered(pi.getId(), "Output", "EndProcess");
        countDownJobListener.waitTillCompleted();
        Assertions.assertThat(getExecutorService().getCompletedRequests(new QueryContext())).hasSize(1);
        assertProcessInstanceCompleted(pi.getId());
    } finally {
        ((ExecutorServiceImpl) getExecutorService()).removeAsyncJobListener(countDownJobListener);
    }
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 68 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class AsyncTaskTest method testTaskFail.

@Test(timeout = 10000)
public void testTaskFail() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(4);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_DATA_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("command", USER_FAILING_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_DATA_EXECUTOR_ID, pm);
    assertNodeTriggered(pi.getId(), "StartProcess", "Set user info", "Process async");
    assertNodeNotTriggered(pi.getId(), "Output");
    // Wait for the 4 retries to fail
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNotNull(processInstance);
    assertNodeNotTriggered(pi.getId(), "Output");
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext())).hasSize(1);
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext()).get(0).getErrorInfo()).hasSize(4);
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext()).get(0).getErrorInfo().get(0).getMessage()).isEqualTo("Internal Error");
    assertProcessInstanceActive(pi.getId());
    ksession.abortProcessInstance(pi.getId());
    assertProcessInstanceAborted(pi.getId());
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 69 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class EmailWorkItemHandlerTest method testMultipleToWithSingleCCAndBCC.

@Test
public void testMultipleToWithSingleCCAndBCC() throws Exception {
    EmailWorkItemHandler handler = new EmailWorkItemHandler();
    handler.setConnection(emailHost, emailPort, null, null);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("To", "person1@domain.com; person2@domain.com");
    workItem.setParameter("Cc", "person3@domain.com; person4@domain.com");
    workItem.setParameter("Bcc", "person5@domain.com; person6@domain.com");
    workItem.setParameter("From", "person4@domain.com");
    workItem.setParameter("Reply-To", "person5@domain.com");
    workItem.setParameter("Subject", "Subject 1");
    workItem.setParameter("Body", "Body 1");
    WorkItemManager manager = new DefaultWorkItemManager(null);
    handler.executeWorkItem(workItem, manager);
    assertEquals(6, wiser.getMessages().size());
    List<String> list = new ArrayList<String>(6);
    for (int i = 0; i < 6; ++i) {
        list.add(wiser.getMessages().get(i).getEnvelopeReceiver());
    }
    for (int i = 1; i < 7; ++i) {
        assertTrue(list.contains("person" + i + "@domain.com"));
    }
    // We know from previous test that all MimeMessages will be identical
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    assertEquals(workItem.getParameter("From"), wiser.getMessages().get(0).getEnvelopeSender());
    String content = ((String) msg.getContent()).replace("\r\n", "");
    assertEquals(workItem.getParameter("Body"), content);
    assertEquals(workItem.getParameter("Subject"), msg.getSubject());
    assertEquals(workItem.getParameter("From"), ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals(workItem.getParameter("Reply-To"), ((InternetAddress) msg.getReplyTo()[0]).getAddress());
    assertEquals(workItem.getParameter("To"), ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress() + "; " + ((InternetAddress) msg.getRecipients(RecipientType.TO)[1]).getAddress());
    assertEquals(workItem.getParameter("Cc"), ((InternetAddress) msg.getRecipients(RecipientType.CC)[0]).getAddress() + "; " + ((InternetAddress) msg.getRecipients(RecipientType.CC)[1]).getAddress());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 70 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class EmailWorkItemHandlerTest method testSingleToWithSingleCCAndBCC.

@Test
public void testSingleToWithSingleCCAndBCC() throws Exception {
    EmailWorkItemHandler handler = new EmailWorkItemHandler();
    handler.setConnection(emailHost, emailPort, null, null);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("To", "person1@domain.com");
    workItem.setParameter("Cc", "person2@domain.com");
    workItem.setParameter("Bcc", "person3@domain.com");
    workItem.setParameter("From", "person4@domain.com");
    workItem.setParameter("Reply-To", "person5@domain.com");
    workItem.setParameter("Subject", "Subject 1");
    workItem.setParameter("Body", "Body 1");
    WorkItemManager manager = new DefaultWorkItemManager(null);
    handler.executeWorkItem(workItem, manager);
    assertEquals(3, wiser.getMessages().size());
    List<String> list = new ArrayList<String>(3);
    list.add(wiser.getMessages().get(0).getEnvelopeReceiver());
    list.add(wiser.getMessages().get(1).getEnvelopeReceiver());
    list.add(wiser.getMessages().get(2).getEnvelopeReceiver());
    assertTrue(list.contains("person1@domain.com"));
    assertTrue(list.contains("person2@domain.com"));
    assertTrue(list.contains("person3@domain.com"));
    for (int i = 0; i < wiser.getMessages().size(); ++i) {
        MimeMessage msg = ((WiserMessage) wiser.getMessages().get(i)).getMimeMessage();
        assertEquals(workItem.getParameter("From"), wiser.getMessages().get(i).getEnvelopeSender());
        String content = ((String) msg.getContent()).replace("\r\n", "");
        assertEquals(workItem.getParameter("Body"), content);
        assertEquals(workItem.getParameter("Subject"), msg.getSubject());
        assertEquals(workItem.getParameter("From"), ((InternetAddress) msg.getFrom()[0]).getAddress());
        assertEquals(workItem.getParameter("Reply-To"), ((InternetAddress) msg.getReplyTo()[0]).getAddress());
        assertEquals(workItem.getParameter("To"), ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
        assertEquals(workItem.getParameter("Cc"), ((InternetAddress) msg.getRecipients(RecipientType.CC)[0]).getAddress());
    }
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Aggregations

WorkItemManager (org.kie.api.runtime.process.WorkItemManager)100 Test (org.junit.Test)84 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)55 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)36 WorkItem (org.kie.api.runtime.process.WorkItem)31 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)27 HashMap (java.util.HashMap)25 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)23 KieBase (org.kie.api.KieBase)21 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 KieSession (org.kie.api.runtime.KieSession)14 Map (java.util.Map)9 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)8 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)7 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)7 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)7 QueryContext (org.kie.api.runtime.query.QueryContext)6 Document (org.w3c.dom.Document)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5