1   package net.sf.msplice.model;
2   
3   import junit.framework.TestCase;
4   import net.sf.msplice.SpliceException;
5   import net.sf.msplice.visitor.AbstractVisitor;
6   import net.sf.msplice.visitor.IVisitor;
7   
8   public class SpliceConfigTest extends TestCase {
9   	
10  	private SpliceConfig rootSpliceElement = null;
11  	
12  	private String childOneName = "child-one";
13  	private String childTwoName = "child-two";
14  
15  	private TestBusinessProperty childOne = null;
16  	private TestBusinessProperty childTwo = null;
17  	
18  	private IVisitor visitor = null;
19  	
20  	
21  	@Override
22  	protected void setUp() throws Exception {
23  		super.setUp();
24  		
25  		rootSpliceElement = new SpliceConfig();
26  		
27  		childOne = new TestBusinessProperty();
28  		childOne.setName(childOneName);
29  		childTwo = new TestBusinessProperty();
30  		childTwo.setName(childTwoName);
31  		
32  		rootSpliceElement.addBusinessProperty(childOne);
33  		rootSpliceElement.addBusinessProperty(childTwo);
34  		
35  		visitor = new TestVisitor();
36  	}
37  	
38  	public void testIterateOverChildren() throws Exception {
39  		rootSpliceElement.accept(visitor);
40  		
41  		assertTrue("Checking visited childOne", childOne.isVisited());
42  		assertTrue("Checking visited childTwo", childTwo.isVisited());
43  		
44  	}
45  
46  	// --------------------------------------------------------------------------------
47  	// test support classes
48  	// --------------------------------------------------------------------------------
49  
50  	public class TestBusinessProperty extends BusinessProperty {
51  	
52  		private boolean visited = false;
53  		
54  		public boolean isVisited() {
55  			return visited;
56  		}
57  
58  		public void setVisited(boolean visited) {
59  			this.visited = visited;
60  		}
61  
62  		@Override
63  		public Object accept(IVisitor visitor) throws SpliceException {
64  			visited = (visitor == SpliceConfigTest.this.visitor);
65  			return super.accept(visitor);
66  		}
67  	}
68  
69  	public class TestVisitor extends AbstractVisitor {
70  	}
71  
72  }