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

📄 assemblertest.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm;

import java.util.*;
import junit.framework.*;

public class AssemblerTest extends TestCase {

  private static TestHelper helper = new TestHelper();
  
  private Collection collector = null;
  private Parent homer = null;
  private Parent grampa = null;
  
  /**
   * @see http://www.doheth.co.uk/information.shtml
   */
  public void setUp() {
    collector = new HashSet();

    List children = new ArrayList();
    children.add( new Child( "bart", collector ) );
    children.add( new Child( "lisa", collector ) );
    children.add( new Child( "maggie", collector ) );
    Child bart = (Child) children.get(0);

    homer = new Parent( "homer", collector );
    homer.setChildren( children );
    
    // since my model only allows one parent, Marge cannot participate in the assemblertest :-(
    
    List friends = new ArrayList();
    friends.add( new Child( "ralph wiggum", collector ) );
    friends.add( new Child( "krusty", collector ) );
    friends.add( new Child( "ned flanders", collector ) );
    Child ralph = (Child) friends.get(0);
    
    Collection otherFriends = new ArrayList();
    otherFriends.add( new Child( "mr burns", collector ) );
    otherFriends.add( new Child( "apu", collector ) );
    
    bart.setFriends( friends );
    ralph.setFriends( otherFriends );
  }
  
  public class Collectable {
    private String text = null;
    private Collection collector = null; 
    public Collectable( String text, Collection collector ) {
      this.text = text;
      this.collector = collector;
    }
    public Object getCollect() {
      collector.add( text );
      return null;
    }
  }

  public class Parent extends Collectable {
    private Collection children = null;
    private Parent partner = null;
    public Parent(String text, Collection collector) {
      super(text, collector);
    }
    public Collection getChildren() { return this.children; }
    public void setChildren(Collection children) { 
      this.children = children;
      Iterator iter = children.iterator();
			while (iter.hasNext()) ((Child) iter.next()).setParent( this );
    }
    public Parent getPartner() { return this.partner; }
    public void setPartner(Parent partner) { this.partner = partner; }
  }
  
  public class Child extends Collectable {
    private Parent parent = null;
    private Collection friends = null;
    public Child(String text, Collection collector) {
      super(text, collector);
    }
    public Parent getParent() { return this.parent; }
    public void setParent(Parent parent) {this.parent = parent;}
    public Collection getFriends() { return this.friends; }
    public void setFriends(Collection friends) { this.friends = friends; }
  }
  
  public void testGetInCollection() {
    Collection collector = new HashSet();
    
    Collection collection = new ArrayList();
    collection.add( new Collectable( "one", collector ) );
    collection.add( new Collectable( "two", collector ) );
    collection.add( new Collectable( "three", collector ) );
    collection.add( new Collectable( "four", collector ) );

    new PropertyAssembler( "[ITERATE].collect" ).assemble( collection );
    
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "one", "two", "three", "four" } ) );
    assertEquals( expectedCollects, collector );
  }

  public void testParent() {
    new PropertyAssembler( new String[]{ "children[ITERATE].parent.collect" } ).assemble( homer );
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "homer" } ) );
    assertEquals( expectedCollects, collector );
  }

  public void testParentChildFriends() {
    new PropertyAssembler( new String[]{ "children[ITERATE].parent.children[ITERATE].collect" } ).assemble( homer );
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "bart", "lisa", "maggie" } ) );
    assertEquals( expectedCollects, collector );
  }

  public void testFriends() {
    new PropertyAssembler( new String[]{ "children[ITERATE].friends[ITERATE].collect" } ).assemble( homer );
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "ralph wiggum", "krusty", "ned flanders" } ) );
    assertEquals( expectedCollects, collector );
  }

  public void testOtherFriends() {
    new PropertyAssembler( new String[]{ "children[ITERATE].friends[ITERATE].friends[ITERATE].collect" } ).assemble( homer );
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "mr burns", "apu" } ) );
    assertEquals( expectedCollects, collector );
  }

  public void testFriendsRecusive() {
    new PropertyAssembler( new String[]{ "children[ITERATE].friends[ITERATE][RECURSIVE].collect" } ).assemble( homer );
    Collection expectedCollects = new HashSet( Arrays.asList( new Object[] { "ralph wiggum", "krusty", "ned flanders", "mr burns", "apu" } ) );
    assertEquals( expectedCollects, collector );
  }
}

⌨️ 快捷键说明

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