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