01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.dynamic;
05:
06: import org.apache.xmlbeans.XmlObject;
07:
08: import com.tc.config.schema.MockXmlObject;
09:
10: public class BooleanXPathBasedConfigItemTest extends
11: XPathBasedConfigItemTestBase {
12:
13: private class SubBean extends MockXmlObject {
14: public boolean getBooleanValue() {
15: return currentValue;
16: }
17: }
18:
19: private boolean currentValue;
20:
21: protected MockXmlObject createSubBean() throws Exception {
22: return new SubBean();
23: }
24:
25: public void setUp() throws Exception {
26: super .setUp();
27:
28: this .currentValue = false;
29: }
30:
31: public void testAll() throws Exception {
32: BooleanXPathBasedConfigItem withoutDefault = new BooleanXPathBasedConfigItem(
33: context, xpath);
34: BooleanXPathBasedConfigItem withTrueDefault = new BooleanXPathBasedConfigItem(
35: context, xpath, true);
36: BooleanXPathBasedConfigItem withFalseDefault = new BooleanXPathBasedConfigItem(
37: context, xpath, false);
38:
39: this .currentValue = false;
40: assertFalse(withoutDefault.getBoolean());
41: assertEquals(Boolean.FALSE, withoutDefault.getObject());
42:
43: this .currentValue = true;
44: withoutDefault = new BooleanXPathBasedConfigItem(context, xpath);
45: assertTrue(withoutDefault.getBoolean());
46: assertEquals(Boolean.TRUE, withoutDefault.getObject());
47:
48: this .currentValue = false;
49: assertFalse(withTrueDefault.getBoolean());
50: assertEquals(Boolean.FALSE, withTrueDefault.getObject());
51:
52: withTrueDefault = new BooleanXPathBasedConfigItem(context,
53: xpath, true);
54: this .bean.setReturnedSelectPath(new XmlObject[0]);
55: assertTrue(withTrueDefault.getBoolean());
56: assertEquals(Boolean.TRUE, withTrueDefault.getObject());
57: this .bean
58: .setReturnedSelectPath(new XmlObject[] { this .subBean });
59:
60: this .currentValue = true;
61: assertTrue(withFalseDefault.getBoolean());
62: assertEquals(Boolean.TRUE, withFalseDefault.getObject());
63:
64: withFalseDefault = new BooleanXPathBasedConfigItem(context,
65: xpath, false);
66: this .bean.setReturnedSelectPath(new XmlObject[0]);
67: assertFalse(withFalseDefault.getBoolean());
68: assertEquals(Boolean.FALSE, withFalseDefault.getObject());
69: }
70:
71: }
|