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.util.TCAssertionError; 10 11 14 public class StringArrayXPathBasedConfigItemTest extends XPathBasedConfigItemTestBase { 15 16 private class NoGetMethod extends MockXmlObject { 17 public String [] getFoo() { 18 return new String [] { "foo", "bar" }; 19 } 20 21 public String [] getBarArray(int val) { 22 return new String [] { "baz", "bar" }; 23 } 24 25 protected String [] getBazArray() { 26 return new String [] { "foo", "baz" }; 27 } 28 } 29 30 private class OneGetMethod extends MockXmlObject { 31 public String [] getFoo() { 32 return new String [] { "foo", "bar" }; 33 } 34 35 public String [] getBarArray(int val) { 36 return new String [] { "baz", "bar" }; 37 } 38 39 protected String [] getBazArray() { 40 return new String [] { "foo", "baz" }; 41 } 42 43 public String [] getZonkArray() { 44 return currentValue; 45 } 46 } 47 48 private class TwoGetMethods extends MockXmlObject { 49 public String [] getFoo() { 50 return new String [] { "foo", "bar" }; 51 } 52 53 public String [] getBarArray(int val) { 54 return new String [] { "baz", "bar" }; 55 } 56 57 protected String [] getBazArray() { 58 return new String [] { "foo", "baz" }; 59 } 60 61 public String [] getZonkArray() { 62 return new String [] { "baz", "quux" }; 63 } 64 65 public String [] getAnotherArray() { 66 return new String [] { "baz2", "quux2" }; 67 } 68 } 69 70 private String [] currentValue; 71 72 public void setUp() throws Exception { 73 super.setUp(); 74 75 this.currentValue = new String [] { "real", "data" }; 76 } 77 78 protected MockXmlObject createSubBean() throws Exception { 79 return new OneGetMethod(); 80 } 81 82 public void testBogusCandidates() throws Exception { 83 bean.setReturnedSelectPath(new XmlObject[] { new NoGetMethod() }); 84 StringArrayXPathBasedConfigItem item = new StringArrayXPathBasedConfigItem(context, xpath); 85 86 try { 87 item.getObject(); 88 fail("Didn't get TCAE on no get method"); 89 } catch (TCAssertionError tcae) { 90 } 92 93 try { 94 item.getStringArray(); 95 fail("Didn't get TCAE on no get method"); 96 } catch (TCAssertionError tcae) { 97 } 99 100 bean.setReturnedSelectPath(new XmlObject[] { new TwoGetMethods() }); 101 item = new StringArrayXPathBasedConfigItem(context, xpath); 102 103 try { 104 item.getObject(); 105 fail("Didn't get TCAE on no get method"); 106 } catch (TCAssertionError tcae) { 107 } 109 110 try { 111 item.getStringArray(); 112 fail("Didn't get TCAE on no get method"); 113 } catch (TCAssertionError tcae) { 114 } 116 } 117 118 public void testRealData() throws Exception { 119 StringArrayXPathBasedConfigItem item = new StringArrayXPathBasedConfigItem(context, xpath); 120 121 assertEqualsOrdered(new String [] { "real", "data" }, item.getStringArray()); 122 assertEqualsOrdered(new String [] { "real", "data" }, item.getObject()); 123 124 this.currentValue = new String [] { "more", "stuff" }; 125 126 item = new StringArrayXPathBasedConfigItem(context, xpath); 127 128 assertEqualsOrdered(new String [] { "more", "stuff" }, item.getStringArray()); 129 assertEqualsOrdered(new String [] { "more", "stuff" }, item.getObject()); 130 } 131 132 } 133 | Popular Tags |