use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testEmailWithTemplate.
@Test
public void testEmailWithTemplate() 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("Template", "basic-email");
workItem.setParameter("Name", "John Doe");
String expectedBody = "<html><body>Hello John Doe</body></html>";
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(expectedBody, 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 BasicAuthRestWorkItemHandlerTest method testGETOperationWithQueryParam.
@Test
public void testGETOperationWithQueryParam() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "?param=test");
workItem.setParameter("Method", "GET");
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 test", 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 testGETOperationWithInvalidTimeout.
@Test
public void testGETOperationWithInvalidTimeout() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL);
workItem.setParameter("Method", "GET");
workItem.setParameter("ConnectTimeout", "");
workItem.setParameter("ReadTimeout", "");
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);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testPUTOperation.
@Test
public void testPUTOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>25</age><name>Put john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/xml");
workItem.setParameter("Method", "PUT");
workItem.setParameter("ContentType", "application/xml");
workItem.setParameter("Content", "<person><name>john</name><age>25</age></person>");
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 testGETOperation.
@Test
public void testGETOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL);
workItem.setParameter("Method", "GET");
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