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

📄 actionxmltest.java

📁 jbpm demo 是一款非常不错的开源工作流,简单易用,适合扩张开发!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jbpm.jpdl.xml;

import java.io.StringReader;
import java.util.List;

import org.dom4j.Element;
import org.jbpm.graph.def.Action;
import org.jbpm.graph.def.Event;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.def.Transition;
import org.jbpm.graph.node.State;
import org.jbpm.instantiation.Delegation;

public class ActionXmlTest extends AbstractXmlTestCase {
  
  public void testReadProcessDefinitionAction() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <event type='node-enter'>" +
      "    <action class='one'/>" +
      "    <action class='two'/>" +
      "    <action class='three'/>" +
      "  </event>" +
      "</process-definition>"
    );
    Event event = processDefinition.getEvent("node-enter");
    assertEquals(3, event.getActions().size());
    assertEquals("one", ((Action)event.getActions().get(0)).getActionDelegation().getClassName());
    assertEquals("two", ((Action)event.getActions().get(1)).getActionDelegation().getClassName());
    assertEquals("three", ((Action)event.getActions().get(2)).getActionDelegation().getClassName());
  }

  public void testWriteProcessDefinitionAction() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Event event = new Event("node-enter");
    processDefinition.addEvent(event);
    event.addAction(new Action(new Delegation("one")));
    event.addAction(new Action(new Delegation("two")));
    event.addAction(new Action(new Delegation("three")));
    
    Element eventElement = toXmlAndParse( processDefinition, "/process-definition/event" );
    
    List actionElements = eventElement.elements("action");

    assertEquals(3, actionElements.size());
    assertEquals("one", ((Element)actionElements.get(0)).attributeValue("class"));
    assertEquals("two", ((Element)actionElements.get(1)).attributeValue("class"));
    assertEquals("three", ((Element)actionElements.get(2)).attributeValue("class"));
  }

  public void testReadActionConfigType() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' config-type='bean' />" +
      "</process-definition>" 
    );
  
    assertEquals("bean", processDefinition.getAction("burps").getActionDelegation().getConfigType() );
  }

  public void testWriteActionConfigType() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    actionDelegate.setConfigType("bean");
    Action action = new Action(actionDelegate);
    action.setName("a");
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertEquals("bean", actionElement.attributeValue("config-type"));
  }

  public void testReadActionXmlConfiguration() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' config-type='bean'>" +
      "    <id>63</id>" +
      "    <greeting>aloha</greeting>" +
      "  </action>" +
      "</process-definition>" 
    );
  
    Action action = processDefinition.getAction("burps");
    Delegation instantiatableDelegate = action.getActionDelegation(); 
    assertTrue(instantiatableDelegate.getConfiguration().indexOf("<id>63</id>")!=-1);
    assertTrue(instantiatableDelegate.getConfiguration().indexOf("<greeting>aloha</greeting>")!=-1 );
  }

  public void testWriteActionXmlConfiguration() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    actionDelegate.setConfiguration("<id>63</id><greeting>aloha</greeting>");
    Action action = new Action(actionDelegate);
    action.setName("a");
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertEquals("63", actionElement.elementTextTrim("id"));
    assertEquals("aloha", actionElement.elementTextTrim("greeting"));
  }

  public void testReadActionTextConfiguration() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' config-type='constructor'>" +
      "    a piece of configuration text" +
      "  </action>" +
      "</process-definition>" 
    );
  
    Action action = processDefinition.getAction("burps");
    Delegation instantiatableDelegate = action.getActionDelegation(); 
    assertTrue(instantiatableDelegate.getConfiguration().indexOf("a piece of configuration text")!=-1);
  }

  public void testWriteActionTextConfiguration() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    actionDelegate.setConfiguration("a piece of configuration text");
    actionDelegate.setConfigType("constructor");
    Action action = new Action(actionDelegate);
    action.setName("a");
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertEquals("a piece of configuration text", actionElement.getTextTrim());
  }

  public void testReadActionAcceptPropagatedEventsDefault() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' />" +
      "</process-definition>" 
    );
  
    Action action = processDefinition.getAction("burps");
    assertTrue(action.acceptsPropagatedEvents());
  }

  public void testReadActionAcceptPropagatedEventsTrue() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' accept-propagated-events='true' />" +
      "</process-definition>" 
    );
  
    Action action = processDefinition.getAction("burps");
    assertTrue(action.acceptsPropagatedEvents());
  }

  public void testReadActionAcceptPropagatedEventsFalse() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <action name='burps' class='org.foo.Burps' accept-propagated-events='false' />" +
      "</process-definition>" 
    );
  
    Action action = processDefinition.getAction("burps");
    assertFalse(action.acceptsPropagatedEvents());
  }

  public void testWriteActionAcceptPropagatedEventsDefault() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    Action action = new Action(actionDelegate);
    action.setName("a");
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertNull(actionElement.attribute("accept-propagated-events"));
  }

  public void testWriteActionAcceptPropagatedEventsTrue() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    Action action = new Action(actionDelegate);
    action.setName("a");
    action.setPropagationAllowed(true);
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertNull(actionElement.attribute("accept-propagated-events"));
  }

  public void testWriteActionAcceptPropagatedEventsFalse() throws Exception {
    ProcessDefinition processDefinition = new ProcessDefinition();
    Delegation actionDelegate = new Delegation("one");
    Action action = new Action(actionDelegate);
    action.setName("a");
    action.setPropagationAllowed(false);
    processDefinition.addAction(action);
    Element actionElement = toXmlAndParse( processDefinition, "/process-definition/action" );
    assertEquals("false", actionElement.attributeValue("accept-propagated-events"));
  }

  public void testReadNodeActionName() {
    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 
      "<process-definition>" +
      "  <node name='a'>" +
      "    <event type='node-enter'>" +
      "      <action name='burps' class='org.foo.Burps'/>" +
      "    </event>" +
      "  </node>" +
      "</process-definition>"
    );
    Action burps = (Action)processDefinition.getNode("a").getEvent("node-enter").getActions().get(0);
    assertEquals("burps", burps.getName());
  }

⌨️ 快捷键说明

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