1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.apache.commons.jxpath.util.ValueUtils;
26
27 /***
28 * General purpose test bean for JUnit tests for the "jxpath" component.
29 *
30 * @author Dmitri Plotnikov
31 * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:40 $
32 */
33 public class TestBean {
34
35
36
37 /***
38 * An array of nested java beans.
39 */
40 private NestedTestBean[] beans;
41 {
42 beans = new NestedTestBean[2];
43 beans[0] = new NestedTestBean("Name 1");
44 beans[1] = new NestedTestBean("Name 2");
45 beans[1].setInt(3);
46 }
47
48 public NestedTestBean[] getBeans() {
49 return beans;
50 }
51
52 public void setBeans(NestedTestBean[] beans) {
53 this.beans = beans;
54 }
55
56 /***
57 * A boolean property.
58 */
59 private boolean bool = false;
60 public boolean getBoolean() {
61 return bool;
62 }
63
64 public void setBoolean(boolean bool) {
65 this.bool = bool;
66 }
67
68 private int integer = 1;
69 /***
70 * A read-only integer property
71 */
72 public int getInt() {
73 return integer;
74 }
75
76 public void setInt(int integer) {
77 this.integer = integer;
78 }
79
80 /***
81 * A read-only array of integers
82 */
83 private int[] array = { 1, 2, 3, 4 };
84 public int[] getIntegers() {
85 return array;
86 }
87
88 public int getIntegers(int index) {
89 return array[index];
90 }
91
92 public void setIntegers(int index, int value) {
93 if (index >= array.length) {
94 array = (int[]) ValueUtils.expandCollection(array, index + 1);
95 }
96 array[index] = value;
97 }
98
99 /***
100 * A heterogeneous list: String, Integer, NestedTestBean
101 */
102 private ArrayList list;
103 public List getList() {
104 if (list == null) {
105 list = new ArrayList();
106 list.add("String 3");
107 list.add(new Integer(3));
108 list.add(new NestedTestBean("Name 3"));
109 }
110 return list;
111 }
112
113 /***
114 * A Map
115 */
116 private HashMap map;
117 {
118 map = new HashMap();
119 map.put("Key1", "Value 1");
120 map.put("Key2", new NestedTestBean("Name 6"));
121 }
122
123 public Map getMap() {
124 return map;
125 }
126
127 public void setMap(Map map) {
128 this.map = (HashMap) map;
129 }
130
131 /***
132 * A nested read-only java bean
133 */
134 private NestedTestBean nestedBean = new NestedTestBean("Name 0");
135 public NestedTestBean getNestedBean() {
136 return nestedBean;
137 }
138
139 public void setNestedBean(NestedTestBean bean) {
140 this.nestedBean = bean;
141 }
142
143 private NestedTestBean object = new NestedTestBean("Name 5");
144
145 /***
146 * Returns a NestedTestBean: testing recognition of generic objects
147 */
148 public Object getObject() {
149 return object;
150 }
151
152 /***
153 * Returns an array of ints: testing recognition of generic objects
154 */
155 public Object getObjects() {
156 return getIntegers();
157 }
158
159 /***
160 * A heterogeneous set: String, Integer, NestedTestBean
161 */
162 private HashSet set;
163 public Set getSet() {
164 if (set == null) {
165 set = new HashSet();
166 set.add("String 4");
167 set.add(new Integer(4));
168 set.add(new NestedTestBean("Name 4"));
169 }
170 return set;
171 }
172
173 public String toString() {
174 return "ROOT";
175 }
176 }