KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > dynamic > BooleanXPathBasedConfigItemTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.dynamic;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 import com.tc.config.schema.MockXmlObject;
9
10 public class BooleanXPathBasedConfigItemTest extends XPathBasedConfigItemTestBase {
11
12   private class SubBean extends MockXmlObject {
13     public boolean getBooleanValue() {
14       return currentValue;
15     }
16   }
17
18   private boolean currentValue;
19
20   protected MockXmlObject createSubBean() throws Exception JavaDoc {
21     return new SubBean();
22   }
23
24   public void setUp() throws Exception JavaDoc {
25     super.setUp();
26
27     this.currentValue = false;
28   }
29
30   public void testAll() throws Exception JavaDoc {
31     BooleanXPathBasedConfigItem withoutDefault = new BooleanXPathBasedConfigItem(context, xpath);
32     BooleanXPathBasedConfigItem withTrueDefault = new BooleanXPathBasedConfigItem(context, xpath, true);
33     BooleanXPathBasedConfigItem withFalseDefault = new BooleanXPathBasedConfigItem(context, xpath, false);
34
35     this.currentValue = false;
36     assertFalse(withoutDefault.getBoolean());
37     assertEquals(Boolean.FALSE, withoutDefault.getObject());
38
39     this.currentValue = true;
40     withoutDefault = new BooleanXPathBasedConfigItem(context, xpath);
41     assertTrue(withoutDefault.getBoolean());
42     assertEquals(Boolean.TRUE, withoutDefault.getObject());
43
44     this.currentValue = false;
45     assertFalse(withTrueDefault.getBoolean());
46     assertEquals(Boolean.FALSE, withTrueDefault.getObject());
47
48     withTrueDefault = new BooleanXPathBasedConfigItem(context, xpath, true);
49     this.bean.setReturnedSelectPath(new XmlObject[0]);
50     assertTrue(withTrueDefault.getBoolean());
51     assertEquals(Boolean.TRUE, withTrueDefault.getObject());
52     this.bean.setReturnedSelectPath(new XmlObject[] { this.subBean });
53
54     this.currentValue = true;
55     assertTrue(withFalseDefault.getBoolean());
56     assertEquals(Boolean.TRUE, withFalseDefault.getObject());
57
58     withFalseDefault = new BooleanXPathBasedConfigItem(context, xpath, false);
59     this.bean.setReturnedSelectPath(new XmlObject[0]);
60     assertFalse(withFalseDefault.getBoolean());
61     assertEquals(Boolean.FALSE, withFalseDefault.getObject());
62   }
63
64 }
65
Popular Tags