Search in sources :

Example 56 with WorkItemManager

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

the class DataTest method testDataInputAssociationsWithXMLLiteral.

@Test
public void testDataInputAssociationsWithXMLLiteral() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations-xml-literal.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            assertEquals("id", ((org.w3c.dom.Node) workItem.getParameter("coId")).getNodeName());
            assertEquals("some text", ((org.w3c.dom.Node) workItem.getParameter("coId")).getFirstChild().getTextContent());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("process", null);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 57 with WorkItemManager

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

the class DataTest method testDataInputAssociations.

@Test
public void testDataInputAssociations() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            assertEquals("hello world", workItem.getParameter("coId"));
        }
    });
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("instanceMetadata", document.getFirstChild());
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Document(org.w3c.dom.Document) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 58 with WorkItemManager

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

the class ErrorEventTest method testEventSubprocessErrorThrowOnTask.

@Test
public void testEventSubprocessErrorThrowOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.bpmn2");
    final List<Long> executednodes = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            throw new MyError();
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
    assertProcessInstanceFinished(processInstance, ksession);
    assertProcessInstanceAborted(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertEquals(1, executednodes.size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 59 with WorkItemManager

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

the class ActivityTest method testServiceTaskNoInterfaceName.

@Test
public void testServiceTaskNoInterfaceName() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ServiceTask-web-service.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            assertEquals("SimpleService", workItem.getParameter("Interface"));
            assertEquals("hello", workItem.getParameter("Operation"));
            assertEquals("java.lang.String", workItem.getParameter("ParameterType"));
            assertEquals("##WebService", workItem.getParameter("implementation"));
            assertEquals("hello", workItem.getParameter("operationImplementationRef"));
            assertEquals("SimpleService", workItem.getParameter("interfaceImplementationRef"));
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.jboss.qa.jbpm.CallWS", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 60 with WorkItemManager

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

the class JPAWorkItemHandlerTest method getAllProducts.

private List<Product> getAllProducts() throws Exception {
    WorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter(JPAWorkItemHandler.P_ACTION, JPAWorkItemHandler.QUERY_ACTION);
    workItem.setParameter(JPAWorkItemHandler.P_QUERY, "SELECT p FROM Product p");
    UserTransaction ut = getUserTransaction();
    ut.begin();
    handler.executeWorkItem(workItem, manager);
    ut.commit();
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    @SuppressWarnings("unchecked") List<Product> products = (List<Product>) results.get(JPAWorkItemHandler.P_QUERY_RESULTS);
    return products;
}
Also used : UserTransaction(javax.transaction.UserTransaction) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) List(java.util.List) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager)

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