1 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 ; 14 15 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 xpath, Object defaultValue) { 25 super(context, xpath, defaultValue); 26 27 reset(); 28 } 29 30 public TestObjectArrayXPathBasedConfigItem(ConfigContext context, String 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 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 [] currentValue; 57 58 protected void setUp() throws Exception { 59 super.setUp(); 60 61 this.currentValue = new Object [] { "foo", new Integer (42), new Date () }; 62 } 63 64 public void testAll() throws Exception { 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 |