Package org.jbpm.context.exe

Examples of org.jbpm.context.exe.ContextInstance


  public void testCreateInputMapWithOnlyWriteVariableAccesses() {
    ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    ContextInstance contextInstance = processInstance.getContextInstance();
    contextInstance.setVariable("a", new Integer(1) );
    contextInstance.setVariable("b", new Integer(1) );
    contextInstance.setVariable("c", new Integer(1) );
   
    Script script = new Script();
    script.addVariableAccess(new VariableAccess("a", "write", null));
    script.addVariableAccess(new VariableAccess("b", "write-required", null));
    Map inputMap = script.createInputMap(new ExecutionContext(token));
View Full Code Here


  public void testCreateInputMapWithOnlyReadVariableAccesses() {
    ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    ContextInstance contextInstance = processInstance.getContextInstance();
    contextInstance.setVariable("a", new Integer(1) );
    contextInstance.setVariable("b", new Integer(1) );
    contextInstance.setVariable("c", new Integer(1) );
   
    Script script = new Script();
    script.addVariableAccess(new VariableAccess("a", "read", null));
    Map inputMap = script.createInputMap(new ExecutionContext(token));
    assertEquals(new Integer(1), inputMap.get("a"));
View Full Code Here

  public void testMappedNameTest() {
    ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    ContextInstance contextInstance = processInstance.getContextInstance();
    contextInstance.setVariable("a", new Integer(1) );
   
    Script script = new Script();
    script.setExpression("AAA++;");
    script.addVariableAccess(new VariableAccess("a", "read-write", "AAA"));
    script.execute(new ExecutionContext(token));

    assertEquals(new Integer(2), contextInstance.getVariable("a"));
  }
View Full Code Here

      "</process-definition>"
    );
    session.save(processDefinition);
   
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    ContextInstance contextInstance = processInstance.getContextInstance();
    contextInstance.setVariable("myActionObject", new MyActionObject());
   
    processInstance = saveAndReload(processInstance);
    contextInstance = processInstance.getContextInstance();
   
    processInstance.signal();

    assertEquals("done", contextInstance.getVariable("getting started"));
    assertEquals("done", contextInstance.getVariable("half way there"));
    assertNull(contextInstance.getVariable("concluding"));

    processInstance = saveAndReload(processInstance);
   
    processInstance.signal();
   
    processInstance = saveAndReload(processInstance);
    contextInstance = processInstance.getContextInstance();
   
    assertEquals("done", contextInstance.getVariable("getting started"));
    assertEquals("done", contextInstance.getVariable("half way there"));
    assertEquals("done", contextInstance.getVariable("concluding"));
  }
View Full Code Here

    jbpmContext.deployProcessDefinition(processDefinition);
   
    newTransaction();
   
    ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("superprocess");
    ContextInstance contextInstance = processInstance.getContextInstance();
    contextInstance.setVariable("a", "1");
    contextInstance.setVariable("b", "1");
    contextInstance.setVariable("c", "1");
    processInstance.signal();
   
    newTransaction();

    long processInstanceId = processInstance.getId();
    long subProcessInstanceId = processInstance.getRootToken().getSubProcessInstance().getId();

    processInstance = jbpmContext.loadProcessInstance(processInstanceId);
    assertNotNull(processInstance.getRootToken().getSubProcessInstance());
    assertEquals("sub process state", processInstance.getRootToken().getNode().getName());
    contextInstance = processInstance.getContextInstance();
    assertEquals("1", contextInstance.getVariable("a") );
    assertEquals("1", contextInstance.getVariable("b") );
    assertEquals("1", contextInstance.getVariable("c") );

    ProcessInstance subProcessInstance = jbpmContext.loadProcessInstance(subProcessInstanceId);
    assertEquals("wait", subProcessInstance.getRootToken().getNode().getName());
    ContextInstance subContextInstance = subProcessInstance.getContextInstance();
    assertEquals("1", subContextInstance.getVariable("A") );
    assertEquals("1", subContextInstance.getVariable("B") );
    assertNull(subContextInstance.getVariable("C") );
   
    subContextInstance.setVariable("A", "2");
    subContextInstance.setVariable("B", "2");
    subContextInstance.setVariable("C", "2");
    subProcessInstance.signal();

    jbpmContext.save(subProcessInstance);

    newTransaction();
View Full Code Here

   */
  public void testExclusiveChoiceSituation1() {
    ProcessDefinition pd = exclusiveChoiceProcessDefinition;

    ProcessInstance pi = new ProcessInstance( pd );
    ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
    pi.signal();
    Token root = pi.getRootToken();

    assertSame( pd.getNode("a"), root.getNode() );
   
    ci.setVariable( "scenario", new Integer(1) );
    root.signal();
   
    assertSame( pd.getNode("b"), root.getNode() );
  }
View Full Code Here

   */
  public void testExclusiveChoiceSituation2() {
    ProcessDefinition pd = exclusiveChoiceProcessDefinition;

    ProcessInstance pi = new ProcessInstance( pd );
    ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
    pi.signal();
    Token root = pi.getRootToken();

    assertSame( pd.getNode("a"), root.getNode() );
   
    ci.setVariable( "scenario", new Integer(2) );
    root.signal();
   
    assertSame( pd.getNode("c"), root.getNode() );
  }
View Full Code Here

    // create the super process definition
    ProcessInstance superProcessInstance = new ProcessInstance(superProcessDefinition);
    Token superToken = superProcessInstance.getRootToken();
   
    // set some variableInstances in the super process
    ContextInstance superContextInstance = superProcessInstance.getContextInstance();
    superContextInstance.setVariable("a", "hello");
    superContextInstance.setVariable("b", new Integer(3));
   
    // start execution of the super process
    superProcessInstance.signal();

    // check if the variableInstances have been copied properly into the sub process
    ProcessInstance subProcessInstance = superToken.getSubProcessInstance();
    ContextInstance subContextInstance = subProcessInstance.getContextInstance();

    assertEquals("hello", subContextInstance.getVariable("aa"));
    assertEquals(new Integer(3), subContextInstance.getVariable("bb"));
    // update variable aa
    subContextInstance.setVariable("aa", "new hello");

    // end the subprocess
    subProcessInstance.signal();
   
    // now check if the subprocess variableInstances have been copied into the super process
View Full Code Here

    Token businessToken = businessProcessInstance.getRootToken();
    assertEquals("start biz proc", businessToken.getNode().getName());
   
    // we put the document somewhere in the process variables
    Document document = new Document("blablabla");
    ContextInstance contextInstance = businessProcessInstance.getContextInstance();
    contextInstance.setVariable("document", document);
   
    // let's kick the execution of the business process
    businessProcessInstance.signal();

    // so the execution should have arrived in the review document node
    assertEquals("review document", businessToken.getNode().getName());

    // there should be 1 task instance created in the business process
    Collection allTaskInstances = businessProcessInstance.getTaskMgmtInstance().getTaskInstances();
    assertNotNull(allTaskInstances);
    assertEquals(1, allTaskInstances.size());
    TaskInstance taskInstance = (TaskInstance) allTaskInstances.iterator().next();
    document = (Document) taskInstance.getVariable("document");
    assertEquals("blablabla", document.getText());

   
    // Now SEAM will handle the page flow that is specified here:
    ProcessDefinition pageFlowDefinition = ProcessDefinition.parseXmlString(
      "<process-definition name='approve document task'>" +
      "  <start-state name='start page flow'>" +
      "    <transition to='review' />" +
      "  </start-state>" +
      "  <page name='review' url='review.jsp'>" +
      "    <transition name='approve' to='approved' />" +
      "    <transition name='reject' to='rejected' />" +
      "  </page>" +
      "  <page name='approved' url='approved.jsp'>" +
      "    <conversation-end outcome='approveDocument' />" +
      "  </page>" +
      "  <page name='rejected' url='rejected.jsp'>" +
      "    <conversation-end outcome='rejectDocument' />" +
      "  </page>" +
      "</process-definition>"
    );
   
    // A new page flow process is started
    ProcessInstance pageFlowInstance = new ProcessInstance(pageFlowDefinition);
    Token pageFlowToken = pageFlowInstance.getRootToken();

    // This page flow is in the context of a specific user that
    // clicked an entry in his task list.  The task instance is
    // injected as a process context variable
    contextInstance = pageFlowInstance.getContextInstance();
    contextInstance.setVariable("taskInstance", taskInstance);

    // With the task instance information, the page flow process is started
    // and can now decide which is the first page to show the user
    pageFlowInstance.signal();

    // SEAM can expect that when a wait state is entered, the main
    // path of execution is positioned in a page.  That page
    // contains the url that SEAM should render.
    // In this simple page flow process, we always start with the
    // review page.
    Page page = (Page) pageFlowToken.getNode();
    assertNotNull(page);
    assertEquals("review", page.getName());
    assertEquals("review.jsp", page.getUrl());
   
    // so now, the SEAM page flow renders the review page.
    // in review.jsp, the EL expression "taskInstance[document].text" should resolve
    // to 'blablabla'
    taskInstance = (TaskInstance) contextInstance.getVariable("taskInstance");
    document = (Document) taskInstance.getVariable("document");
    assertEquals("blablabla", document.getText());
    assertEquals("business process review task", taskInstance.getName());

    // suppose the user presses the approve button
View Full Code Here

  }
 
  // protected ////////////////////////////////////////////////////////////////

  protected VariableContainer getParentVariableContainer() {
    ContextInstance contextInstance = getContextInstance();
    return (contextInstance!=null ? contextInstance.getOrCreateTokenVariableMap(token) : null);
  }
View Full Code Here

TOP

Related Classes of org.jbpm.context.exe.ContextInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.