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());
}
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);
}
}
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());
}
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());
}
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());
}
}
Aggregations