Search in sources :

Example 6 with WorkItemManager

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));
}
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 7 with WorkItemManager

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

Example 8 with WorkItemManager

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

Example 9 with WorkItemManager

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

Example 10 with WorkItemManager

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);
}
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)102 Test (org.junit.Test)86 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)56 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)25 KieBase (org.kie.api.KieBase)23 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 KieSession (org.kie.api.runtime.KieSession)15 Map (java.util.Map)9 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)8 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)8 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