Search in sources :

Example 76 with TestWorkItemManager

use of org.jbpm.process.workitem.core.TestWorkItemManager 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 77 with TestWorkItemManager

use of org.jbpm.process.workitem.core.TestWorkItemManager 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 78 with TestWorkItemManager

use of org.jbpm.process.workitem.core.TestWorkItemManager 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)

Example 79 with TestWorkItemManager

use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.

the class BusinessRuleTaskHandlerTest method testDrlStatelessBusinessRuleTaskNoScanner.

@Test
public void testDrlStatelessBusinessRuleTaskNoScanner() {
    TestWorkItemManager manager = new TestWorkItemManager();
    BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(999);
    Person person = new Person("john");
    workItem.setParameter("person", person);
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(35, ((Person) results.get("person")).getAge().intValue());
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Person(org.jbpm.process.workitem.bpmn2.objects.Person) Test(org.junit.Test)

Example 80 with TestWorkItemManager

use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.

the class WebServiceWorkItemHandlerTest method testExecuteSyncOperationWithBasicAuth.

@Test
public void testExecuteSyncOperationWithBasicAuth() throws Exception {
    HTTPConduit http = Mockito.mock(HTTPConduit.class, Mockito.CALLS_REAL_METHODS);
    when(clients.containsKey(anyObject())).thenReturn(true);
    when(clients.get(anyObject())).thenReturn(client);
    when(client.getConduit()).thenReturn(http);
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Interface", "someInterface");
    workItem.setParameter("Operation", "someOperation");
    workItem.setParameter("Parameter", "myParam");
    workItem.setParameter("Mode", "SYNC");
    WebServiceWorkItemHandler handler = new WebServiceWorkItemHandler(kieSession, "testusername", "testpassword");
    handler.setClients(clients);
    handler.executeWorkItem(workItem, manager);
    assertNotNull(manager.getResults());
    assertEquals(1, manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
    assertNotNull(http.getAuthorization());
    AuthorizationPolicy authorizationPolicy = http.getAuthorization();
    assertEquals("Basic", authorizationPolicy.getAuthorizationType());
    assertEquals("testusername", authorizationPolicy.getUserName());
    assertEquals("testpassword", authorizationPolicy.getPassword());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Test(org.junit.Test)

Aggregations

WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)81 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)81 Test (org.junit.Test)79 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)36 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)19 Matchers.anyString (org.mockito.Matchers.anyString)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 List (java.util.List)7 DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)6 ArrayList (java.util.ArrayList)5 File (java.io.File)3 UserTransaction (javax.transaction.UserTransaction)3 Person (org.jbpm.process.workitem.bpmn2.objects.Person)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Document (org.jbpm.document.Document)2 StatusUpdate (twitter4j.StatusUpdate)2 CalendarList (com.google.api.services.calendar.model.CalendarList)1 TaskList (com.google.api.services.tasks.model.TaskList)1 XmlReader (com.sun.syndication.io.XmlReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1