KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.TCAssertionError;
10
11 /**
12  * Unit test for {@link StringArrayXPathBasedConfigItem}.
13  */

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