use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testFailedExecuteToHandleException.
@Test(expected = WorkItemHandlerRuntimeException.class)
public void testFailedExecuteToHandleException() throws Exception {
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, "123", null, null);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", "person1@domain.com");
workItem.setParameter("From", "person2@domain.com");
workItem.setParameter("Reply-To", "person3@domain.com");
workItem.setParameter("Subject", "Subject 1");
workItem.setParameter("Body", "Body 1");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testSingleTo.
@Test
public void testSingleTo() throws Exception {
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, null, null);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", "person1@domain.com");
workItem.setParameter("From", "person2@domain.com");
workItem.setParameter("Reply-To", "person3@domain.com");
workItem.setParameter("Subject", "Subject 1");
workItem.setParameter("Body", "Body 1");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
assertEquals(1, wiser.getMessages().size());
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
// Side effect of MIME encoding (I think.. ): \r\n..
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());
assertNull(msg.getRecipients(RecipientType.CC));
assertNull(msg.getRecipients(RecipientType.BCC));
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class SendHtmlTest method useEmailWorkItemHandlerWithAuthentication.
@Test
public void useEmailWorkItemHandlerWithAuthentication() throws Exception {
// Add authentication to Wiser SMTP server
wiser.getServer().setAuthenticationHandlerFactory(new TestAuthHandlerFactory());
// Input
String testMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String toAddress = "rgivens@yahoo.com";
String fromAddress = "rgivens@kty.us.gov";
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, authUsername, authPassword);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", toAddress);
workItem.setParameter("From", fromAddress);
workItem.setParameter("Reply-To", fromAddress);
workItem.setParameter("Subject", "Test mail for " + testMethodName);
workItem.setParameter("Body", "Don't forget to check on Boyd later today.");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
for (WiserMessage wiserMessage : messages) {
MimeMessage message = wiserMessage.getMimeMessage();
assertEquals(workItem.getParameter("Subject"), message.getSubject());
assertTrue(Arrays.equals(InternetAddress.parse(toAddress), message.getRecipients(RecipientType.TO)));
}
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testDELETEOperation.
@Test
public void testDELETEOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>-1</age><name>deleted john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/xml/john");
workItem.setParameter("Method", "DELETE");
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
String result = (String) workItem.getResult("Result");
assertNotNull("result cannot be null", result);
assertEquals(expected, result);
int responseCode = (Integer) workItem.getResult("Status");
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) workItem.getResult("StatusMsg");
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testGETOperationAuthTypeAsParam.
@Test
public void testGETOperationAuthTypeAsParam() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL);
workItem.setParameter("Method", "GET");
workItem.setParameter("AuthType", "BASIC");
workItem.setParameter("Username", USERNAME);
workItem.setParameter("Password", PASSWORD);
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
String result = (String) workItem.getResult("Result");
assertNotNull("result cannot be null", result);
assertEquals("Hello from REST", result);
int responseCode = (Integer) workItem.getResult("Status");
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) workItem.getResult("StatusMsg");
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
Aggregations