Search in sources :

Example 96 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class RestWorkItemHandlerTest method testPOSTOperationWithPathParamAndNoContent.

@Test
public void testPOSTOperationWithPathParamAndNoContent() {
    RESTWorkItemHandler handler = new RESTWorkItemHandler();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Url", serverURL + "/john");
    workItem.setParameter("Method", "POST");
    WorkItemManager manager = new TestWorkItemManager();
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    String result = (String) results.get(PARAM_RESULT);
    assertNotNull("result cannot be null", result);
    assertEquals("Created resource with name john", result);
    int responseCode = (Integer) results.get(PARAM_STATUS);
    assertNotNull(responseCode);
    assertEquals(200, responseCode);
    String responseMsg = (String) results.get(PARAM_STATUS_MSG);
    assertNotNull(responseMsg);
    assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) Test(org.junit.Test)

Example 97 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class RestWorkItemHandlerTest method testPUTOperation.

@Test
public void testPUTOperation() {
    RESTWorkItemHandler handler = new RESTWorkItemHandler();
    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", serverURL + "/xml");
    workItem.setParameter("Method", "PUT");
    workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml");
    workItem.setParameter(contentParamName, "<person><name>john</name><age>25</age></person>");
    WorkItemManager manager = new TestWorkItemManager();
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    String result = (String) results.get(PARAM_RESULT);
    assertNotNull("result cannot be null", result);
    assertEquals(expected, result);
    int responseCode = (Integer) results.get(PARAM_STATUS);
    assertNotNull(responseCode);
    assertEquals(200, responseCode);
    String responseMsg = (String) results.get(PARAM_STATUS_MSG);
    assertNotNull(responseMsg);
    assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) Test(org.junit.Test)

Example 98 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class RestWorkItemHandlerTest method testPUTOperationWithXmlTransformation.

@Test
public void testPUTOperationWithXmlTransformation() {
    RESTWorkItemHandler handler = new RESTWorkItemHandler();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Url", serverURL + "/xml");
    workItem.setParameter("Method", "PUT");
    workItem.setParameter(PARAM_CONTENT_TYPE, "Application/Xml;charset=utf-8");
    workItem.setParameter(contentParamName, "<person><name>john</name><age>25</age></person>");
    workItem.setParameter("ResultClass", Person.class.getName());
    WorkItemManager manager = new TestWorkItemManager();
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    Person result = (Person) results.get(PARAM_RESULT);
    assertNotNull("result cannot be null", result);
    assertEquals("Put john", result.getName());
    assertEquals(25, result.getAge().intValue());
    int responseCode = (Integer) results.get(PARAM_STATUS);
    assertNotNull(responseCode);
    assertEquals(200, responseCode);
    String responseMsg = (String) results.get(PARAM_STATUS_MSG);
    assertNotNull(responseMsg);
    assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) Test(org.junit.Test)

Example 99 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class RestWorkitemHandlerClientCreationTest method testPooledClientCreationWithSetTimeouts.

@Test
public void testPooledClientCreationWithSetTimeouts() {
    RESTWorkItemHandler handler = spy(RESTWorkItemHandler.class);
    when(handler.getDoCacheClient()).thenReturn(true);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Url", serverURL);
    workItem.setParameter("Method", "GET");
    workItem.setParameter("ConnectTimeout", "4000");
    workItem.setParameter("ReadTimeout", "3000");
    WorkItemManager manager = new TestWorkItemManager();
    handler.executeWorkItem(workItem, manager);
    // second call to executeWorkItem
    handler.executeWorkItem(workItem, manager);
    verify(handler, times(2)).getHttpClient(anyInt(), anyInt());
    // should use existing already since cached
    verify(handler, times(0)).getNewPooledHttpClient(anyInt(), anyInt());
    assertNotNull(handler.cachedClient);
    assertTrue(handler.cachedClient instanceof CloseableHttpClient);
    assertNotNull(handler.cachedClient.getConnectionManager());
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) Test(org.junit.Test)

Example 100 with WorkItemManager

use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.

the class RestWorkitemHandlerClientCreationTest method testPooledClientCreationWithDefaultTimeouts.

@Test
public void testPooledClientCreationWithDefaultTimeouts() {
    RESTWorkItemHandler handler = spy(RESTWorkItemHandler.class);
    when(handler.getDoCacheClient()).thenReturn(true);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Url", serverURL);
    workItem.setParameter("Method", "GET");
    WorkItemManager manager = new TestWorkItemManager();
    handler.executeWorkItem(workItem, manager);
    // second call to executeWorkItem
    handler.executeWorkItem(workItem, manager);
    verify(handler, times(2)).getHttpClient(anyInt(), anyInt());
    verify(handler, times(1)).getNewPooledHttpClient(anyInt(), anyInt());
    assertNotNull(handler.cachedClient);
    assertTrue(handler.cachedClient instanceof CloseableHttpClient);
    assertNotNull(handler.cachedClient.getConnectionManager());
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) 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