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: import com.tc.config.schema.context.ConfigContext;
10: import com.tc.config.schema.context.MockConfigContext;
11: import com.tc.test.TCTestCase;
12:
13: import java.util.Date;
14:
15: /**
16: * Unit test for {@link ObjectArrayXPathBasedConfigItem}.
17: */
18: public class ObjectArrayXPathBasedConfigItemTest extends TCTestCase {
19:
20: private class TestObjectArrayXPathBasedConfigItem extends
21: ObjectArrayXPathBasedConfigItem {
22: private int numFetchDataFromXmlObjects;
23: private XmlObject lastXmlObject;
24:
25: public TestObjectArrayXPathBasedConfigItem(
26: ConfigContext context, String xpath, Object defaultValue) {
27: super (context, xpath, defaultValue);
28:
29: reset();
30: }
31:
32: public TestObjectArrayXPathBasedConfigItem(
33: ConfigContext context, String xpath) {
34: super (context, xpath);
35:
36: reset();
37: }
38:
39: public void reset() {
40: this .numFetchDataFromXmlObjects = 0;
41: this .lastXmlObject = null;
42: }
43:
44: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
45: ++this .numFetchDataFromXmlObjects;
46: this .lastXmlObject = xmlObject;
47: return currentValue;
48: }
49:
50: public XmlObject getLastXmlObject() {
51: return lastXmlObject;
52: }
53:
54: public int getNumFetchDataFromXmlObjects() {
55: return numFetchDataFromXmlObjects;
56: }
57: }
58:
59: private Object[] currentValue;
60:
61: protected void setUp() throws Exception {
62: super .setUp();
63:
64: this .currentValue = new Object[] { "foo", new Integer(42),
65: new Date() };
66: }
67:
68: public void testAll() throws Exception {
69: MockXmlObject bean = new MockXmlObject();
70: MockXmlObject subBean = new MockXmlObject();
71:
72: bean.setReturnedSelectPath(new XmlObject[] { subBean });
73:
74: MockConfigContext context = new MockConfigContext();
75:
76: context.setReturnedBean(bean);
77:
78: TestObjectArrayXPathBasedConfigItem withoutDefault = new TestObjectArrayXPathBasedConfigItem(
79: context, "foobar");
80:
81: assertSame(this .currentValue, withoutDefault.getObject());
82: assertEquals(1, withoutDefault.getNumFetchDataFromXmlObjects());
83: assertSame(subBean, withoutDefault.getLastXmlObject());
84:
85: withoutDefault.reset();
86: withoutDefault = new TestObjectArrayXPathBasedConfigItem(
87: context, "foobar");
88:
89: assertSame(this .currentValue, withoutDefault.getObjects());
90: assertEquals(1, withoutDefault.getNumFetchDataFromXmlObjects());
91: assertSame(subBean, withoutDefault.getLastXmlObject());
92: }
93: }
|