Search in sources :

Example 71 with WorkItemManager

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);
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) 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 72 with WorkItemManager

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));
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) 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 73 with WorkItemManager

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)));
    }
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) 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 74 with WorkItemManager

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);
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 75 with WorkItemManager

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);
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) 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