Search in sources :

Example 6 with Person

use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.

the class ProcessSubProcessTest method testDynamicSubProcess.

@Test
public void testDynamicSubProcess() throws Exception {
    KieBase kbase = readDynamicSubProcess();
    KieSession workingMemory = kbase.newKieSession();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "subflow");
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("com.sample.ruleflow", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(2, workingMemory.getProcessInstances().size());
    workingMemory.insert(new Person());
    workingMemory.fireAllRules();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertEquals(0, workingMemory.getProcessInstances().size());
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.integrationtests.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 7 with Person

use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.

the class ProcessSubProcessTest method testVariableMapping.

@Test
public void testVariableMapping() throws Exception {
    KieSession workingMemory = createStatefulKnowledgeSessionFromRule(true);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("x", "x-value");
    org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) workingMemory.startProcess("com.sample.ruleflow", map);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(2, workingMemory.getProcessInstances().size());
    for (ProcessInstance p : workingMemory.getProcessInstances()) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) p).getContextInstance(VariableScope.VARIABLE_SCOPE);
        if ("com.sample.ruleflow".equals(p.getProcessId())) {
            assertEquals("x-value", variableScopeInstance.getVariable("x"));
        } else if ("com.sample.subflow".equals(p.getProcessId())) {
            assertEquals("x-value", variableScopeInstance.getVariable("y"));
            assertEquals("z-value", variableScopeInstance.getVariable("z"));
            assertEquals(7, variableScopeInstance.getVariable("n"));
            assertEquals(10, variableScopeInstance.getVariable("o"));
        }
    }
    workingMemory.insert(new Person());
    workingMemory.fireAllRules();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
    assertEquals("z-value", variableScopeInstance.getVariable("x"));
    assertEquals(10, variableScopeInstance.getVariable("m"));
    assertEquals(0, workingMemory.getProcessInstances().size());
}
Also used : HashMap(java.util.HashMap) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.integrationtests.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 8 with Person

use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.

the class ProcessUpgradeTest method testMappingUpgrade.

@Test
public void testMappingUpgrade() throws Exception {
    String rule = "package org.test;\n";
    rule += "import org.jbpm.integrationtests.test.Person\n";
    rule += "global java.util.List list\n";
    rule += "rule \"Rule 1\"\n";
    rule += "  ruleflow-group \"hello\"\n";
    rule += "when\n";
    rule += "    $p : Person( ) \n";
    rule += "then\n";
    rule += "    list.add( $p );\n";
    rule += "end";
    KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    builder.add(new ReaderResource(new StringReader(rule)), ResourceType.DRL);
    String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "    xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "    type=\"RuleFlow\" name=\"ruleflow\" id=\"org.test.ruleflow\" package-name=\"org.test\" >\n" + "  <header>\n" + "  </header>\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <workItem id=\"2\" name=\"Hello\" >\n" + "      <work name=\"Human Task\" >\n" + "      </work>\n" + "    </workItem>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\"/>\n" + "    <connection from=\"2\" to=\"3\"/>\n" + "  </connections>\n" + "</process>";
    builder.add(new ReaderResource(new StringReader(process)), ResourceType.DRF);
    // RuleBaseConfiguration config = new RuleBaseConfiguration();
    // config.setRuleBaseUpdateHandler(null);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(builder.getKnowledgePackages());
    KieSession session = kbase.newKieSession();
    TestWorkItemHandler handler = new TestWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    List<String> list = new ArrayList<String>();
    session.setGlobal("list", list);
    Person p = new Person("bobba fet", 32);
    session.insert(p);
    ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.test.ruleflow");
    assertEquals(1, session.getProcessInstances().size());
    String process2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "    xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "    type=\"RuleFlow\" name=\"ruleflow\" id=\"org.test.ruleflow2\" package-name=\"org.test\" >\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"list\" type=\"java.util.List\" />\n" + "    </globals>\n" + "  </header>\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <workItem id=\"102\" name=\"Hello\" >\n" + "      <work name=\"Human Task\" >\n" + "      </work>\n" + "    </workItem>\n" + "    <actionNode id=\"4\" name=\"Action\" >" + "      <action type=\"expression\" dialect=\"java\">System.out.println();\n" + "list.add(\"Executed\");</action>\n" + "    </actionNode>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"102\"/>\n" + "    <connection from=\"102\" to=\"4\"/>\n" + "    <connection from=\"4\" to=\"3\"/>\n" + "  </connections>\n" + "</process>";
    builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    builder.add(new ReaderResource(new StringReader(process2)), ResourceType.DRF);
    kbase.addPackages(builder.getKnowledgePackages());
    Map<String, Long> mapping = new HashMap<String, Long>();
    mapping.put("2", 102L);
    WorkflowProcessInstanceUpgrader.upgradeProcessInstance(session, processInstance.getId(), "org.test.ruleflow2", mapping);
    assertEquals("org.test.ruleflow2", processInstance.getProcessId());
    session.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertEquals(1, list.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(org.jbpm.integrationtests.handler.TestWorkItemHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ReaderResource(org.drools.core.io.impl.ReaderResource) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Person(org.jbpm.integrationtests.test.Person) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 9 with Person

use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.

the class XMLPersistenceTest method testPersistenceOfFullNodes.

@Test
public void testPersistenceOfFullNodes() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess() {

        private static final long serialVersionUID = 510l;

        int id = 0;

        public void addNode(org.kie.api.definition.process.Node node) {
            ((Node) node).setId(++id);
            super.addNode(node);
        }
    };
    process.setMetaData("routerLayout", 1);
    Set<String> imports = new HashSet<String>();
    imports.add("import1");
    imports.add("import2");
    process.setImports(imports);
    Map<String, String> globals = new HashMap<String, String>();
    globals.put("name1", "type1");
    globals.put("name2", "type2");
    process.setGlobals(globals);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("variable1");
    variable.setType(new StringDataType());
    variable.setValue("value");
    variables.add(variable);
    variable = new Variable();
    variable.setName("variable2");
    variable.setType(new IntegerDataType());
    variable.setValue(2);
    variables.add(variable);
    variable = new Variable();
    variable.setName("variable3");
    variable.setType(new ObjectDataType("org.jbpm.integrationtests.test.Person"));
    Person person = new Person();
    person.setName("John");
    variable.setValue(person);
    variables.add(variable);
    variable = new Variable();
    variable.setName("variable4");
    ListDataType listDataType = new ListDataType();
    listDataType.setType(new ObjectDataType("java.lang.Integer"));
    variable.setType(listDataType);
    List<Integer> list = new ArrayList<Integer>();
    list.add(10);
    list.add(20);
    variable.setValue(list);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    Swimlane swimlane = new Swimlane();
    swimlane.setName("actor1");
    process.getSwimlaneContext().addSwimlane(swimlane);
    swimlane = new Swimlane();
    swimlane.setName("actor2");
    process.getSwimlaneContext().addSwimlane(swimlane);
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setFaultVariable("faultVariable");
    DroolsConsequenceAction action = new DroolsConsequenceAction("dialect", "consequence");
    exceptionHandler.setAction(action);
    process.getExceptionScope().setExceptionHandler("myFault", exceptionHandler);
    exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setFaultVariable("faultVariable2");
    action = new DroolsConsequenceAction("dialect2", "consequence2");
    exceptionHandler.setAction(action);
    process.getExceptionScope().setExceptionHandler("myFault2", exceptionHandler);
    StartNode startNode = new StartNode();
    startNode.setName("start");
    startNode.setMetaData("x", 1);
    startNode.setMetaData("y", 2);
    startNode.setMetaData("width", 3);
    startNode.setMetaData("height", 4);
    startNode.setMetaData("meta1", "someValue");
    startNode.setMetaData("meta2", "someOtherValue");
    ConstraintTrigger constraintTrigger = new ConstraintTrigger();
    constraintTrigger.setConstraint("constraint");
    Map<String, String> inMapping = new HashMap<String, String>();
    inMapping.put("key", "value");
    inMapping.put("key2", "value2");
    constraintTrigger.setInMappings(inMapping);
    startNode.addTrigger(constraintTrigger);
    EventTrigger eventTrigger = new EventTrigger();
    EventTypeFilter eventTypeFilter = new EventTypeFilter();
    eventTypeFilter.setType("eventType");
    eventTrigger.addEventFilter(eventTypeFilter);
    inMapping = new HashMap<String, String>();
    inMapping.put("key", "value");
    inMapping.put("key2", "value2");
    eventTrigger.setInMappings(inMapping);
    startNode.addTrigger(eventTrigger);
    process.addNode(startNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("action");
    actionNode.setMetaData("x", 1);
    actionNode.setMetaData("y", 2);
    actionNode.setMetaData("width", 3);
    actionNode.setMetaData("height", 4);
    action = new DroolsConsequenceAction("dialect", "consequence");
    actionNode.setAction(action);
    process.addNode(actionNode);
    RuleSetNode ruleSetNode = new RuleSetNode();
    ruleSetNode.setName("action");
    ruleSetNode.setMetaData("x", 1);
    ruleSetNode.setMetaData("y", 2);
    ruleSetNode.setMetaData("width", 3);
    ruleSetNode.setMetaData("height", 4);
    ruleSetNode.setRuleFlowGroup("ruleFlowGroup");
    Timer timer = new Timer();
    timer.setDelay("100");
    timer.setPeriod("100");
    action = new DroolsConsequenceAction("dialect", "consequence");
    ruleSetNode.addTimer(timer, action);
    timer = new Timer();
    timer.setDelay("200");
    timer.setPeriod("200");
    action = new DroolsConsequenceAction("dialect", "consequence");
    ruleSetNode.addTimer(timer, action);
    process.addNode(ruleSetNode);
    FaultNode faultNode = new FaultNode();
    faultNode.setName("action");
    faultNode.setMetaData("x", 1);
    faultNode.setMetaData("y", 2);
    faultNode.setMetaData("width", 3);
    faultNode.setMetaData("height", 4);
    faultNode.setFaultName("faultName");
    faultNode.setFaultVariable("faultVariable");
    process.addNode(faultNode);
    Split split = new Split();
    split.setName("split");
    split.setMetaData("x", 1);
    split.setMetaData("y", 2);
    split.setMetaData("width", 3);
    split.setMetaData("height", 4);
    split.setType(Split.TYPE_XOR);
    Connection connection = new ConnectionImpl(split, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    Constraint constraint = new ConstraintImpl();
    constraint.setName("constraint1 ><&&");
    constraint.setPriority(1);
    constraint.setDialect("dialect1");
    constraint.setType("type1");
    constraint.setConstraint("constraint-text1");
    split.setConstraint(connection, constraint);
    connection = new ConnectionImpl(split, Node.CONNECTION_DEFAULT_TYPE, ruleSetNode, Node.CONNECTION_DEFAULT_TYPE);
    constraint = new ConstraintImpl();
    constraint.setName("constraint2");
    constraint.setPriority(2);
    constraint.setDialect("dialect2");
    constraint.setType("type2");
    constraint.setConstraint("constraint-text2");
    split.setConstraint(connection, constraint);
    process.addNode(split);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, split, Node.CONNECTION_DEFAULT_TYPE);
    EventNode eventNode = new EventNode();
    eventNode.setName("action");
    eventNode.setMetaData("x", 1);
    eventNode.setMetaData("y", 2);
    eventNode.setMetaData("width", 3);
    eventNode.setMetaData("height", 4);
    eventNode.setVariableName("eventVariable");
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType("eventType");
    eventNode.addEventFilter(eventFilter);
    process.addNode(eventNode);
    Join join = new Join();
    join.setName("join");
    join.setMetaData("x", 1);
    join.setMetaData("y", 2);
    join.setMetaData("width", 3);
    join.setMetaData("height", 4);
    join.setType(Join.TYPE_N_OF_M);
    join.setN("#{var1}");
    process.addNode(join);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(ruleSetNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
    MilestoneNode milestone = new MilestoneNode();
    milestone.setName("milestone");
    milestone.setMetaData("x", 1);
    milestone.setMetaData("y", 2);
    milestone.setMetaData("width", 3);
    milestone.setMetaData("height", 4);
    milestone.setConstraint("constraint");
    timer = new Timer();
    timer.setDelay("100");
    timer.setPeriod("100");
    action = new DroolsConsequenceAction("dialect", "consequence");
    milestone.addTimer(timer, action);
    timer = new Timer();
    timer.setDelay("200");
    timer.setPeriod("200");
    action = new DroolsConsequenceAction("dialect", "consequence");
    milestone.addTimer(timer, action);
    List<DroolsAction> actions = new ArrayList<DroolsAction>();
    DroolsAction action1 = new DroolsConsequenceAction("java", "System.out.println(\"action1\");");
    actions.add(action1);
    DroolsAction action2 = new DroolsConsequenceAction("java", "System.out.println(\"action2\");");
    actions.add(action2);
    milestone.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
    milestone.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
    process.addNode(milestone);
    connection = new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, milestone, Node.CONNECTION_DEFAULT_TYPE);
    connection.setMetaData("bendpoints", "[10,10;20,20]");
    SubProcessNode subProcess = new SubProcessNode();
    subProcess.setName("subProcess");
    subProcess.setMetaData("x", 1);
    subProcess.setMetaData("y", 2);
    subProcess.setMetaData("width", 3);
    subProcess.setMetaData("height", 4);
    subProcess.setProcessId("processId");
    subProcess.setWaitForCompletion(false);
    subProcess.setIndependent(false);
    subProcess.addInMapping("subvar1", "var1");
    subProcess.addOutMapping("subvar2", "var2");
    timer = new Timer();
    timer.setDelay("100");
    timer.setPeriod("100");
    action = new DroolsConsequenceAction("dialect", "consequence");
    subProcess.addTimer(timer, action);
    timer = new Timer();
    timer.setDelay("200");
    timer.setPeriod("200");
    action = new DroolsConsequenceAction("dialect", "consequence");
    subProcess.addTimer(timer, action);
    subProcess.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
    subProcess.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
    process.addNode(subProcess);
    connection = new ConnectionImpl(milestone, Node.CONNECTION_DEFAULT_TYPE, subProcess, Node.CONNECTION_DEFAULT_TYPE);
    connection.setMetaData("bendpoints", "[10,10]");
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("WorkItem");
    Work work = new WorkImpl();
    work.setName("workname");
    Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("param1", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("param2", new IntegerDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("param1", "value1");
    work.setParameter("param2", 1);
    workItemNode.setWork(work);
    workItemNode.setWaitForCompletion(false);
    workItemNode.addInMapping("param1", "var1");
    workItemNode.addOutMapping("param2", "var2");
    timer = new Timer();
    timer.setDelay("100");
    timer.setPeriod("100");
    action = new DroolsConsequenceAction("dialect", "consequence");
    workItemNode.addTimer(timer, action);
    timer = new Timer();
    timer.setDelay("200");
    timer.setPeriod("200");
    action = new DroolsConsequenceAction("dialect", "consequence");
    workItemNode.addTimer(timer, action);
    workItemNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
    workItemNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
    process.addNode(workItemNode);
    connection = new ConnectionImpl(subProcess, Node.CONNECTION_DEFAULT_TYPE, workItemNode, Node.CONNECTION_DEFAULT_TYPE);
    connection.setMetaData("bendpoints", "[]");
    HumanTaskNode humanTaskNode = new HumanTaskNode();
    humanTaskNode.setName("Human Task");
    work = humanTaskNode.getWork();
    parameterDefinitions = new HashSet<ParameterDefinition>();
    parameterDefinition = new ParameterDefinitionImpl("TaskName", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Priority", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("TaskName", "Do something");
    work.setParameter("ActorId", "John Doe");
    humanTaskNode.setWaitForCompletion(false);
    humanTaskNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
    humanTaskNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
    process.addNode(humanTaskNode);
    connection = new ConnectionImpl(workItemNode, Node.CONNECTION_DEFAULT_TYPE, humanTaskNode, Node.CONNECTION_DEFAULT_TYPE);
    TimerNode timerNode = new TimerNode();
    timerNode.setName("timer");
    timerNode.setMetaData("x", 1);
    timerNode.setMetaData("y", 2);
    timerNode.setMetaData("width", 3);
    timerNode.setMetaData("height", 4);
    timer = new Timer();
    timer.setDelay("1000");
    timer.setPeriod("1000");
    timerNode.setTimer(timer);
    process.addNode(timerNode);
    new ConnectionImpl(humanTaskNode, Node.CONNECTION_DEFAULT_TYPE, timerNode, Node.CONNECTION_DEFAULT_TYPE);
    ForEachNode forEachNode = new ForEachNode();
    forEachNode.setName("ForEach");
    forEachNode.setCollectionExpression("collection");
    forEachNode.setVariable("variableName", new ObjectDataType());
    forEachNode.setWaitForCompletion(false);
    ActionNode subActionNode1 = new ActionNode();
    forEachNode.getCompositeNode().addNode(subActionNode1);
    ActionNode subActionNode2 = new ActionNode();
    forEachNode.getCompositeNode().addNode(subActionNode2);
    new ConnectionImpl(subActionNode1, Node.CONNECTION_DEFAULT_TYPE, subActionNode2, Node.CONNECTION_DEFAULT_TYPE);
    forEachNode.getCompositeNode().linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, subActionNode1.getId(), Node.CONNECTION_DEFAULT_TYPE);
    forEachNode.getCompositeNode().linkOutgoingConnections(subActionNode2.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(forEachNode);
    new ConnectionImpl(timerNode, Node.CONNECTION_DEFAULT_TYPE, forEachNode, Node.CONNECTION_DEFAULT_TYPE);
    CompositeContextNode compositeNode = new CompositeContextNode();
    compositeNode.setName("Composite");
    VariableScope variableScope = new VariableScope();
    compositeNode.addContext(variableScope);
    compositeNode.setDefaultContext(variableScope);
    variableScope.setVariables(variables);
    ExceptionScope exceptionScope = new ExceptionScope();
    compositeNode.addContext(exceptionScope);
    compositeNode.setDefaultContext(exceptionScope);
    exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setFaultVariable("faultVariable");
    action = new DroolsConsequenceAction("dialect", "consequence");
    exceptionHandler.setAction(action);
    exceptionScope.setExceptionHandler("MyFault", exceptionHandler);
    exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setFaultVariable("faultVariable2");
    action = new DroolsConsequenceAction("dialect2", "consequence2");
    exceptionHandler.setAction(action);
    exceptionScope.setExceptionHandler("MyFault2", exceptionHandler);
    subActionNode1 = new ActionNode();
    compositeNode.addNode(subActionNode1);
    subActionNode2 = new ActionNode();
    compositeNode.addNode(subActionNode2);
    new ConnectionImpl(subActionNode1, Node.CONNECTION_DEFAULT_TYPE, subActionNode2, Node.CONNECTION_DEFAULT_TYPE);
    compositeNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, subActionNode1.getId(), Node.CONNECTION_DEFAULT_TYPE);
    compositeNode.linkOutgoingConnections(subActionNode2.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(compositeNode);
    new ConnectionImpl(forEachNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode endNode = new EndNode();
    endNode.setName("end");
    endNode.setTerminate(false);
    endNode.setMetaData("x", 1);
    endNode.setMetaData("y", 2);
    endNode.setMetaData("width", 3);
    endNode.setMetaData("height", 4);
    process.addNode(endNode);
    StateNode stateNode = new StateNode();
    stateNode.setName("state");
    stateNode.setMetaData("x", 1);
    stateNode.setMetaData("y", 2);
    stateNode.setMetaData("width", 3);
    stateNode.setMetaData("height", 4);
    timer = new Timer();
    timer.setDelay("100");
    timer.setPeriod("100");
    action = new DroolsConsequenceAction("dialect", "consequence");
    stateNode.addTimer(timer, action);
    timer = new Timer();
    timer.setDelay("200");
    timer.setPeriod("200");
    action = new DroolsConsequenceAction("dialect", "consequence");
    stateNode.addTimer(timer, action);
    actions = new ArrayList<DroolsAction>();
    action1 = new DroolsConsequenceAction("java", "System.out.println(\"action1\");");
    actions.add(action1);
    action2 = new DroolsConsequenceAction("java", "System.out.println(\"action2\");");
    actions.add(action2);
    stateNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
    stateNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
    new ConnectionImpl(compositeNode, Node.CONNECTION_DEFAULT_TYPE, stateNode, Node.CONNECTION_DEFAULT_TYPE);
    connection = new ConnectionImpl(stateNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
    constraint = new ConstraintImpl();
    constraint.setName("constraint1 ><&&");
    constraint.setPriority(1);
    constraint.setDialect("dialect1");
    constraint.setType("type1");
    constraint.setConstraint("constraint-text1 %&<>");
    stateNode.setConstraint(connection, constraint);
    connection = new ConnectionImpl(stateNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    constraint = new ConstraintImpl();
    constraint.setName("constraint2");
    constraint.setPriority(2);
    constraint.setDialect("dialect2");
    constraint.setType("type2");
    constraint.setConstraint("constraint-text2");
    stateNode.setConstraint(connection, constraint);
    process.addNode(stateNode);
    String xml = XmlRuleFlowProcessDumper.INSTANCE.dump(process, true);
    if (xml == null) {
        throw new IllegalArgumentException("Failed to persist full nodes!");
    }
    SemanticModules modules = new SemanticModules();
    modules.addSemanticModule(new ProcessSemanticModule());
    XmlProcessReader reader = new XmlProcessReader(modules, getClass().getClassLoader());
    List<Process> processes = reader.read(new StringReader(xml));
    assertNotNull(processes);
    process = (RuleFlowProcess) processes.get(0);
    if (process == null) {
        throw new IllegalArgumentException("Failed to reload process!");
    }
    assertEquals(16, process.getNodes().length);
    assertEquals(2, process.getImports().size());
    assertEquals(2, process.getGlobals().size());
    assertEquals(4, process.getVariableScope().getVariables().size());
    assertEquals(2, process.getSwimlaneContext().getSwimlanes().size());
    assertEquals(2, process.getExceptionScope().getExceptionHandlers().size());
    String xml2 = XmlRuleFlowProcessDumper.INSTANCE.dump(process, true);
    if (xml2 == null) {
        throw new IllegalArgumentException("Failed to persist empty nodes!");
    }
    Document control = XMLUnit.buildDocument(XMLUnit.newControlParser(), new StringReader(xml));
    Document test = XMLUnit.buildDocument(XMLUnit.newTestParser(), new StringReader(xml2));
    Diff diff = new Diff(control, test, null, new ElementNameAndAttributeQualifier("name"));
    assertTrue(diff.toString(), diff.similar());
// test serialization of process elements
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) HashMap(java.util.HashMap) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) Constraint(org.jbpm.workflow.core.Constraint) Diff(org.custommonkey.xmlunit.Diff) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) StateNode(org.jbpm.workflow.core.node.StateNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) TimerNode(org.jbpm.workflow.core.node.TimerNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) ArrayList(java.util.ArrayList) StateNode(org.jbpm.workflow.core.node.StateNode) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Document(org.w3c.dom.Document) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) SemanticModules(org.drools.core.xml.SemanticModules) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) HashSet(java.util.HashSet) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) DroolsAction(org.jbpm.workflow.core.DroolsAction) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) ParameterDefinitionImpl(org.jbpm.process.core.impl.ParameterDefinitionImpl) FaultNode(org.jbpm.workflow.core.node.FaultNode) EndNode(org.jbpm.workflow.core.node.EndNode) Split(org.jbpm.workflow.core.node.Split) Person(org.jbpm.integrationtests.test.Person) VariableScope(org.jbpm.process.core.context.variable.VariableScope) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) Variable(org.jbpm.process.core.context.variable.Variable) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) ProcessSemanticModule(org.jbpm.compiler.xml.ProcessSemanticModule) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EventNode(org.jbpm.workflow.core.node.EventNode) ElementNameAndAttributeQualifier(org.custommonkey.xmlunit.ElementNameAndAttributeQualifier) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) StringReader(java.io.StringReader) TimerNode(org.jbpm.workflow.core.node.TimerNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) StartNode(org.jbpm.workflow.core.node.StartNode) ListDataType(org.jbpm.process.core.datatype.impl.type.ListDataType) Connection(org.jbpm.workflow.core.Connection) Join(org.jbpm.workflow.core.node.Join) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane) Timer(org.jbpm.process.core.timer.Timer) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) Test(org.junit.Test)

Example 10 with Person

use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.

the class ProcessWorkItemTest method testWorkItemImmediateCompletion.

@Test
public void testWorkItemImmediateCompletion() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <variables>\n" + "      <variable name=\"UserName\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        <value>John Doe</value>\n" + "      </variable>\n" + "      <variable name=\"Person\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.test.Person\" />\n" + "      </variable>\n" + "      <variable name=\"MyObject\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "      </variable>\n" + "      <variable name=\"Number\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.IntegerDataType\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <workItem id=\"2\" name=\"HumanTask\" >\n" + "      <work name=\"Human Task\" >\n" + "        <parameter name=\"ActorId\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>#{UserName}</value>\n" + "        </parameter>\n" + "        <parameter name=\"Content\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>#{Person.name}</value>\n" + "        </parameter>\n" + "        <parameter name=\"TaskName\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>Do something</value>\n" + "        </parameter>\n" + "        <parameter name=\"Priority\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"Comment\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"Attachment\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "      </work>\n" + "      <mapping type=\"in\" from=\"MyObject\" to=\"Attachment\" />" + "      <mapping type=\"in\" from=\"Person.name\" to=\"Comment\" />" + "      <mapping type=\"out\" from=\"Result\" to=\"MyObject\" />" + "      <mapping type=\"out\" from=\"Result.length()\" to=\"Number\" />" + "    </workItem>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "  </connections>\n" + "\n" + "</process>");
    kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
    Collection<KiePackage> kpkgs = kbuilder.getKnowledgePackages();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kpkgs);
    KieSession ksession = kbase.newKieSession();
    ImmediateTestWorkItemHandler handler = new ImmediateTestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    Person person = new Person();
    person.setName("John Doe");
    parameters.put("Person", person);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : HashMap(java.util.HashMap) Reader(java.io.Reader) StringReader(java.io.StringReader) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KiePackage(org.kie.api.definition.KiePackage) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.integrationtests.test.Person) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

Person (org.jbpm.integrationtests.test.Person)24 Test (org.junit.Test)24 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)23 KieSession (org.kie.api.runtime.KieSession)23 StringReader (java.io.StringReader)21 Reader (java.io.Reader)14 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)11 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)7 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 TestWorkItemHandler (org.jbpm.integrationtests.handler.TestWorkItemHandler)6 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)6 ProcessInstance (org.jbpm.process.instance.ProcessInstance)5 KieBase (org.kie.api.KieBase)5 ReaderResource (org.drools.core.io.impl.ReaderResource)3 KiePackage (org.kie.api.definition.KiePackage)3 DroolsError (org.drools.compiler.compiler.DroolsError)2 Ignore (org.junit.Ignore)2