KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > archie > SingleValueNodeTest


1 package org.sapia.archie;
2
3 import org.sapia.archie.impl.*;
4
5 import junit.framework.TestCase;
6
7 import java.util.HashMap JavaDoc;
8
9
10 /**
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class SingleValueNodeTest extends TestCase {
20   public SingleValueNodeTest(String JavaDoc name) {
21     super(name);
22   }
23   
24   public void testPutGetValue() throws Exception JavaDoc {
25     NamePart name = new DefaultNameParser().parse("name").first();
26     SingleValueNode node = new SingleValueNode(new HashMap JavaDoc(), new HashMap JavaDoc(),
27                                                new DefaultNodeFactory());
28     super.assertTrue(node.putValue(name, "value", true));
29     super.assertEquals("value", node.getValue(name));
30
31     super.assertTrue(!node.putValue(name, "value2", false));
32     super.assertEquals("value", node.getValue(name).toString());
33
34     super.assertTrue(node.putValue(name, "value2", true));
35     super.assertEquals("value2", node.getValue(name).toString());
36   }
37   
38   public void testOnWriteRead() throws Exception JavaDoc{
39     NamePart name = new DefaultNameParser().parse("name").first();
40     TestSingeValueNode node = new TestSingeValueNode();
41     node.putValue(name, "SomeObject", true);
42     super.assertTrue(node.write);
43     super.assertEquals("SomeObject", node.getValue(name));
44     super.assertTrue(node.read);
45     
46   }
47   
48   public void testRemoveValue() throws Exception JavaDoc{
49     NamePart name = new DefaultNameParser().parse("name").first();
50     SingleValueNode node = new SingleValueNode(new HashMap JavaDoc(), new HashMap JavaDoc(), new DefaultNodeFactory());
51     node.putValue(name, "value", true);
52     node.removeValue(name);
53     super.assertTrue(node.getValue(name) == null);
54   }
55   
56   public void testCreateChild() throws Exception JavaDoc{
57     SingleValueNode node = new SingleValueNode(new HashMap JavaDoc(), new HashMap JavaDoc(), new DefaultNodeFactory());
58     DefaultNamePart n;
59     node.createChild(n = new DefaultNamePart("child"));
60     super.assertTrue(node.getChild(n) != null);
61   }
62   
63   public void testRemoveChild() throws Exception JavaDoc{
64     SingleValueNode node = new SingleValueNode(new HashMap JavaDoc(), new HashMap JavaDoc(), new DefaultNodeFactory());
65     DefaultNamePart n;
66     node.createChild(n = new DefaultNamePart("child"));
67     node.removeChild(n);
68     super.assertTrue(node.getChild(n) == null);
69   }
70   
71   public void testGetChildrenCount() throws Exception JavaDoc{
72     SingleValueNode node = new SingleValueNode(new HashMap JavaDoc(), new HashMap JavaDoc(), new DefaultNodeFactory());
73     node.createChild(new DefaultNamePart("child1"));
74     node.createChild(new DefaultNamePart("child2"));
75     super.assertEquals(2, node.getChildrenCount());
76        
77   }
78   
79   static class TestSingeValueNode extends SingleValueNode{
80     
81     boolean read, write;
82     
83     TestSingeValueNode() throws ProcessingException{
84       super(new HashMap JavaDoc(), new HashMap JavaDoc(), new DefaultNodeFactory());
85     }
86     
87     protected Object JavaDoc onRead(NamePart part, Object JavaDoc toRead) {
88       read = true;
89       return ((TestBinding)toRead).bound;
90     }
91     
92     /**
93      * @see org.sapia.archie.impl.SingleValueNode#onWrite(java.lang.Object)
94      */

95     protected Object JavaDoc onWrite(NamePart part, Object JavaDoc o) {
96       write = true;
97       TestBinding bd = new TestBinding();
98       bd.bound = o;
99       return bd;
100     }
101   
102   }
103   
104   static class TestBinding{
105     Object JavaDoc bound;
106   }
107 }
108
Popular Tags