001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.config.schema.dynamic;
005:
006: import org.apache.xmlbeans.XmlObject;
007:
008: import com.tc.config.schema.MockXmlObject;
009: import com.tc.util.TCAssertionError;
010:
011: /**
012: * Unit test for {@link StringArrayXPathBasedConfigItem}.
013: */
014: public class StringArrayXPathBasedConfigItemTest extends
015: XPathBasedConfigItemTestBase {
016:
017: private class NoGetMethod extends MockXmlObject {
018: public String[] getFoo() {
019: return new String[] { "foo", "bar" };
020: }
021:
022: public String[] getBarArray(int val) {
023: return new String[] { "baz", "bar" };
024: }
025:
026: protected String[] getBazArray() {
027: return new String[] { "foo", "baz" };
028: }
029: }
030:
031: private class OneGetMethod extends MockXmlObject {
032: public String[] getFoo() {
033: return new String[] { "foo", "bar" };
034: }
035:
036: public String[] getBarArray(int val) {
037: return new String[] { "baz", "bar" };
038: }
039:
040: protected String[] getBazArray() {
041: return new String[] { "foo", "baz" };
042: }
043:
044: public String[] getZonkArray() {
045: return currentValue;
046: }
047: }
048:
049: private class TwoGetMethods extends MockXmlObject {
050: public String[] getFoo() {
051: return new String[] { "foo", "bar" };
052: }
053:
054: public String[] getBarArray(int val) {
055: return new String[] { "baz", "bar" };
056: }
057:
058: protected String[] getBazArray() {
059: return new String[] { "foo", "baz" };
060: }
061:
062: public String[] getZonkArray() {
063: return new String[] { "baz", "quux" };
064: }
065:
066: public String[] getAnotherArray() {
067: return new String[] { "baz2", "quux2" };
068: }
069: }
070:
071: private String[] currentValue;
072:
073: public void setUp() throws Exception {
074: super .setUp();
075:
076: this .currentValue = new String[] { "real", "data" };
077: }
078:
079: protected MockXmlObject createSubBean() throws Exception {
080: return new OneGetMethod();
081: }
082:
083: public void testBogusCandidates() throws Exception {
084: bean
085: .setReturnedSelectPath(new XmlObject[] { new NoGetMethod() });
086: StringArrayXPathBasedConfigItem item = new StringArrayXPathBasedConfigItem(
087: context, xpath);
088:
089: try {
090: item.getObject();
091: fail("Didn't get TCAE on no get method");
092: } catch (TCAssertionError tcae) {
093: // ok
094: }
095:
096: try {
097: item.getStringArray();
098: fail("Didn't get TCAE on no get method");
099: } catch (TCAssertionError tcae) {
100: // ok
101: }
102:
103: bean
104: .setReturnedSelectPath(new XmlObject[] { new TwoGetMethods() });
105: item = new StringArrayXPathBasedConfigItem(context, xpath);
106:
107: try {
108: item.getObject();
109: fail("Didn't get TCAE on no get method");
110: } catch (TCAssertionError tcae) {
111: // ok
112: }
113:
114: try {
115: item.getStringArray();
116: fail("Didn't get TCAE on no get method");
117: } catch (TCAssertionError tcae) {
118: // ok
119: }
120: }
121:
122: public void testRealData() throws Exception {
123: StringArrayXPathBasedConfigItem item = new StringArrayXPathBasedConfigItem(
124: context, xpath);
125:
126: assertEqualsOrdered(new String[] { "real", "data" }, item
127: .getStringArray());
128: assertEqualsOrdered(new String[] { "real", "data" }, item
129: .getObject());
130:
131: this .currentValue = new String[] { "more", "stuff" };
132:
133: item = new StringArrayXPathBasedConfigItem(context, xpath);
134:
135: assertEqualsOrdered(new String[] { "more", "stuff" }, item
136: .getStringArray());
137: assertEqualsOrdered(new String[] { "more", "stuff" }, item
138: .getObject());
139: }
140:
141: }
|