KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 JavaDoc;
14
15 /**
16  * Unit test for {@link ObjectArrayXPathBasedConfigItem}.
17  */

18 public class ObjectArrayXPathBasedConfigItemTest extends TCTestCase {
19
20   private class TestObjectArrayXPathBasedConfigItem extends ObjectArrayXPathBasedConfigItem {
21     private int numFetchDataFromXmlObjects;
22     private XmlObject lastXmlObject;
23
24     public TestObjectArrayXPathBasedConfigItem(ConfigContext context, String JavaDoc xpath, Object JavaDoc defaultValue) {
25       super(context, xpath, defaultValue);
26
27       reset();
28     }
29
30     public TestObjectArrayXPathBasedConfigItem(ConfigContext context, String JavaDoc xpath) {
31       super(context, xpath);
32
33       reset();
34     }
35
36     public void reset() {
37       this.numFetchDataFromXmlObjects = 0;
38       this.lastXmlObject = null;
39     }
40
41     protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
42       ++this.numFetchDataFromXmlObjects;
43       this.lastXmlObject = xmlObject;
44       return currentValue;
45     }
46
47     public XmlObject getLastXmlObject() {
48       return lastXmlObject;
49     }
50
51     public int getNumFetchDataFromXmlObjects() {
52       return numFetchDataFromXmlObjects;
53     }
54   }
55
56   private Object JavaDoc[] currentValue;
57
58   protected void setUp() throws Exception JavaDoc {
59     super.setUp();
60
61     this.currentValue = new Object JavaDoc[] { "foo", new Integer JavaDoc(42), new Date JavaDoc() };
62   }
63
64   public void testAll() throws Exception JavaDoc {
65     MockXmlObject bean = new MockXmlObject();
66     MockXmlObject subBean = new MockXmlObject();
67
68     bean.setReturnedSelectPath(new XmlObject[] { subBean });
69
70     MockConfigContext context = new MockConfigContext();
71
72     context.setReturnedBean(bean);
73
74     TestObjectArrayXPathBasedConfigItem withoutDefault = new TestObjectArrayXPathBasedConfigItem(context, "foobar");
75
76     assertSame(this.currentValue, withoutDefault.getObject());
77     assertEquals(1, withoutDefault.getNumFetchDataFromXmlObjects());
78     assertSame(subBean, withoutDefault.getLastXmlObject());
79
80     withoutDefault.reset();
81     withoutDefault = new TestObjectArrayXPathBasedConfigItem(context, "foobar");
82
83     assertSame(this.currentValue, withoutDefault.getObjects());
84     assertEquals(1, withoutDefault.getNumFetchDataFromXmlObjects());
85     assertSame(subBean, withoutDefault.getLastXmlObject());
86   }
87 }
88
Popular Tags