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 com.tc.config.schema.MockXmlObject;
07:
08: public class StringXPathBasedConfigItemTest extends
09: XPathBasedConfigItemTestBase {
10:
11: private class SubBean extends MockXmlObject {
12: public String getStringValue() {
13: return currentValue;
14: }
15: }
16:
17: private class DefaultBean extends MockXmlObject {
18: private final String value;
19:
20: public DefaultBean(String value) {
21: this .value = value;
22: }
23:
24: public String getStringValue() {
25: return value;
26: }
27: }
28:
29: private String currentValue;
30:
31: protected MockXmlObject createSubBean() throws Exception {
32: return new SubBean();
33: }
34:
35: public void setUp() throws Exception {
36: super .setUp();
37:
38: this .currentValue = "hi there";
39: }
40:
41: public void testNoDefault() throws Exception {
42: StringXPathBasedConfigItem item = new StringXPathBasedConfigItem(
43: context, xpath);
44:
45: assertEquals("hi there", item.getString());
46: assertEquals("hi there", item.getObject());
47:
48: currentValue = null;
49: item = new StringXPathBasedConfigItem(context, xpath);
50:
51: assertNull(item.getString());
52: assertNull(item.getObject());
53: }
54:
55: public void testDefault() throws Exception {
56: context.setReturnedHasDefaultFor(true);
57: context.setReturnedDefaultFor(new DefaultBean("the default"));
58: StringXPathBasedConfigItem item = new StringXPathBasedConfigItem(
59: context, xpath);
60:
61: assertEquals("hi there", item.getString());
62: assertEquals("hi there", item.getObject());
63:
64: currentValue = null;
65: item = new StringXPathBasedConfigItem(context, xpath);
66:
67: assertEquals("the default", item.getString());
68: assertEquals("the default", item.getObject());
69: }
70:
71: }
|