⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 superstateactionexecutiontest.java

📁 jbpm demo 是一款非常不错的开源工作流,简单易用,适合扩张开发!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    processInstance.signal();
    assertEquals(1, executedActions.size());
    ExecutedAction executedAction = (ExecutedAction) executedActions.get(0);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.getNode("superstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.getNode("superstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);
  }

  public void testNestedSuperStateLeave() {
    processDefinition = ProcessDefinition.parseXmlString(
      "<process-definition>" +
      "  <start-state name='start'>" +
      "    <transition to='superstate/nestedsuperstate/stateinside'/>" +
      "  </start-state>" +
      "  <super-state name='superstate'>" +
      "    <event type='superstate-leave'>" +
      "      <action class='org.jbpm.graph.exe.SuperStateActionExecutionTest$Recorder' />" +
      "    </event>" +
      "    <super-state name='nestedsuperstate'>" +
      "      <event type='superstate-leave'>" +
      "        <action class='org.jbpm.graph.exe.SuperStateActionExecutionTest$Recorder' />" +
      "      </event>" +
      "      <state name='stateinside'>" +
      "        <transition to='../../toplevelstate' />" +
      "      </state>" +
      "    </super-state>" +
      "  </super-state>" +
      "  <state name='toplevelstate' />" +
      "</process-definition>"
    );
    // create the process instance
    processInstance = new ProcessInstance(processDefinition);
    // put the execution in the nestedsuperstate
    processInstance.signal();
    assertEquals(0, executedActions.size());
    
    // the next signal results in a node-enter internally to the superstate so it should have no effect.
    // by default, event propagation is turned on.  that is why we decided to have a separated event type for superstate leave and enter. 
    processInstance.signal();
    assertEquals(3, executedActions.size());
    ExecutedAction executedAction = (ExecutedAction) executedActions.get(0);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);

    executedAction = (ExecutedAction) executedActions.get(1);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);

    executedAction = (ExecutedAction) executedActions.get(2);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);
  }

  public void testNestedSuperStateLeaveViaSuperStateTransition() {
    processDefinition = ProcessDefinition.parseXmlString(
      "<process-definition>" +
      "  <start-state name='start'>" +
      "    <transition to='superstate/nestedsuperstate/stateinside'/>" +
      "  </start-state>" +
      "  <super-state name='superstate'>" +
      "    <event type='superstate-leave'>" +
      "      <action class='org.jbpm.graph.exe.SuperStateActionExecutionTest$Recorder' />" +
      "    </event>" +
      "    <super-state name='nestedsuperstate'>" +
      "      <event type='superstate-leave'>" +
      "        <action class='org.jbpm.graph.exe.SuperStateActionExecutionTest$Recorder' />" +
      "      </event>" +
      "      <state name='stateinside' />" +
      "    </super-state>" +
      "    <transition to='toplevelstate' />" +
      "  </super-state>" +
      "  <state name='toplevelstate' />" +
      "</process-definition>"
    );
    // create the process instance
    processInstance = new ProcessInstance(processDefinition);
    // put the execution in the nestedsuperstate
    processInstance.signal();
    assertEquals(0, executedActions.size());
    
    // the next signal results in a node-enter internally to the superstate so it should have no effect.
    // by default, event propagation is turned on.  that is why we decided to have a separated event type for superstate leave and enter. 
    processInstance.signal();
    assertEquals(3, executedActions.size());
    ExecutedAction executedAction = (ExecutedAction) executedActions.get(0);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);

    executedAction = (ExecutedAction) executedActions.get(1);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate/nestedsuperstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);

    executedAction = (ExecutedAction) executedActions.get(2);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("superstate"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("superstate"), executedAction.eventSource);
    assertSame(processInstance.getRootToken(), executedAction.token);
    assertNull(executedAction.node);
  }

  public void testInterNestedSuperStateTransition() {
    //          +--------------------------------------+
    //          |one                                   |
    //          | +---------------+  +---------------+ |
    //          | |one.one        |  |one.two        | | 
    //          | | +-----------+ |  | +-----------+ | |
    //          | | |one.one.one| |  | |one.two.one| | |
    //  +-----+ | | | +---+     | |  | |  +---+    | | |
    //  |start|-+-+-+>| a |-----+-+--+-+->| b |    | | |
    //  +-----+ | | | +---+     | |  | |  +---+    | | |
    //          | | +-----------+ |  | +-----------+ | |
    //          | +---------------+  +---------------+ |
    //          +--------------------------------------+
    processDefinition = ProcessDefinition.parseXmlString(
      "<process-definition>" +
      "  <start-state name='start'>" +
      "    <transition to='one/one.one/one.one.one/a'/>" +
      "  </start-state>" +
      "  <super-state name='one'>" +
      "    <event type='superstate-enter'><action ref-name='record' /></event>" +
      "    <event type='superstate-leave'><action ref-name='record' /></event>" +
      "    <super-state name='one.one'>" +
      "      <event type='superstate-leave'><action ref-name='record' /></event>" +
      "      <super-state name='one.one.one'>" +
      "        <event type='superstate-leave'><action ref-name='record' /></event>" +
      "        <state name='a'>" +
      "          <transition to='../../one.two/one.two.one/b' />" +
      "        </state>" +
      "      </super-state>" +
      "    </super-state>" +
      "    <super-state name='one.two'>" +
      "      <event type='superstate-enter'><action ref-name='record' /></event>" +
      "      <super-state name='one.two.one'>" +
      "        <event type='superstate-enter'><action ref-name='record' /></event>" +
      "        <state name='b' />" +
      "      </super-state>" +
      "    </super-state>" +
      "  </super-state>" +
      "  <action name='record' class='org.jbpm.graph.exe.SuperStateActionExecutionTest$Recorder' />" +
      "</process-definition>"
    );
    // create the process instance
    processInstance = new ProcessInstance(processDefinition);
    // put the execution in the nestedsuperstate
    processInstance.signal();
    assertEquals(3, executedActions.size());
    
    // the next signal results in a node-enter internally to the superstate so it should have no effect.
    // by default, event propagation is turned on.  that is why we decided to have a separated event type for superstate leave and enter. 
    processInstance.signal();
    assertEquals(13, executedActions.size());

    ExecutedAction executedAction = (ExecutedAction) executedActions.get(3);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.one/one.one.one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.one/one.one.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(4);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.one/one.one.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(5);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.one/one.one.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(6);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(7);
    assertEquals("superstate-leave", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(8);
    assertEquals("superstate-enter", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.two"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.two"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(9);
    assertEquals("superstate-enter", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.two"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(10);
    assertEquals("superstate-enter", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.two/one.two.one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.two/one.two.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(11);
    assertEquals("superstate-enter", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one/one.two"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.two/one.two.one"), executedAction.eventSource);

    executedAction = (ExecutedAction) executedActions.get(12);
    assertEquals("superstate-enter", executedAction.event.getEventType());
    assertSame(processDefinition.findNode("one"), executedAction.event.getGraphElement());
    assertSame(processDefinition.findNode("one/one.two/one.two.one"), executedAction.eventSource);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -