2
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v 1.4 2001/09/03 17:34:36 craigmcc Exp $
4
* $Date: 2001/09/03 17:34:36 $
6
* ====================================================================
8
* The Apache Software License, Version 1.1
10
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following conditions
17
* 1. Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
20
* 2. Redistributions in binary form must reproduce the above copyright
21
* notice, this list of conditions and the following disclaimer in
22
* the documentation and/or other materials provided with the
25
* 3. The end-user documentation included with the redistribution, if
26
* any, must include the following acknowlegement:
27
* "This product includes software developed by the
28
* Apache Software Foundation (http://www.apache.org/)."
29
* Alternately, this acknowlegement may appear in the software itself,
30
* if and wherever such third-party acknowlegements normally appear.
32
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
33
* Foundation" must not be used to endorse or promote products derived
34
* from this software without prior written permission. For written
35
* permission, please contact apache@apache.org.
37
* 5. Products derived from this software may not be called "Apache"
38
* nor may "Apache" appear in their names without prior written
39
* permission of the Apache Group.
41
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53
* ====================================================================
55
* This software consists of voluntary contributions made by many
56
* individuals on behalf of the Apache Software Foundation. For more
57
* information on the Apache Software Foundation, please see
58
* <http://www.apache.org/>.
63
package org.apache.commons.beanutils;
66
import java.util.HashMap;
70
* General purpose test bean for JUnit tests for the "beanutils" component.
72
* @author Craig R. McClanahan
73
* @version $Revision: 1.4 $ $Date: 2001/09/03 17:34:36 $
76
public class TestBean {
79
// ------------------------------------------------------------- Properties
85
private boolean booleanProperty = true;
87
public boolean getBooleanProperty() {
88
return (booleanProperty);
91
public void setBooleanProperty(boolean booleanProperty) {
92
this.booleanProperty = booleanProperty;
97
* A boolean property that uses an "is" method for the getter.
99
private boolean booleanSecond = true;
101
public boolean isBooleanSecond() {
102
return (booleanSecond);
105
public void setBooleanSecond(boolean booleanSecond) {
106
this.booleanSecond = booleanSecond;
113
private double doubleProperty = 321.0;
115
public double getDoubleProperty() {
116
return (this.doubleProperty);
119
public void setDoubleProperty(double doubleProperty) {
120
this.doubleProperty = doubleProperty;
127
private float floatProperty = (float) 123.0;
129
public float getFloatProperty() {
130
return (this.floatProperty);
133
public void setFloatProperty(float floatProperty) {
134
this.floatProperty = floatProperty;
139
* An integer array property accessed as an array.
141
private int intArray[] = { 0, 10, 20, 30, 40 };
143
public int[] getIntArray() {
144
return (this.intArray);
147
public void setIntArray(int intArray[]) {
148
this.intArray = intArray;
153
* An integer array property accessed as an indexed property.
155
private int intIndexed[] = { 0, 10, 20, 30, 40 };
157
public int getIntIndexed(int index) {
158
return (intIndexed[index]);
161
public void setIntIndexed(int index, int value) {
162
intIndexed[index] = value;
167
* An integer property.
169
private int intProperty = 123;
171
public int getIntProperty() {
172
return (this.intProperty);
175
public void setIntProperty(int intProperty) {
176
this.intProperty = intProperty;
183
private long longProperty = 321;
185
public long getLongProperty() {
186
return (this.longProperty);
189
public void setLongProperty(long longProperty) {
190
this.longProperty = longProperty;
195
* A mapped property that has String keys and String values.
197
private HashMap mappedProperty = null;
199
public String getMappedProperty(String key) {
200
// Create the map the very first time
201
if (mappedProperty == null) {
202
mappedProperty = new HashMap();
203
mappedProperty.put("First Key", "First Value");
204
mappedProperty.put("Second Key", "Second Value");
206
return ((String) mappedProperty.get(key));
209
public void setMappedProperty(String key, String value) {
210
mappedProperty.put(key, value);
215
* A mapped property that has String keys and int values.
217
private HashMap mappedIntProperty = null;
219
public int getMappedIntProperty(String key) {
220
// Create the map the very first time
221
if (mappedProperty == null) {
222
mappedProperty = new HashMap();
223
mappedProperty.put("One", new Integer(1));
224
mappedProperty.put("Two", new Integer(2));
226
Integer x = (Integer) mappedIntProperty.get(key);
227
return ((x == null) ? 0 : x.intValue());
230
public void setMappedIntProperty(String key, int value) {
231
mappedIntProperty.put(key, new Integer(value));
236
* A nested reference to another test bean (populated as needed).
238
private TestBean nested = null;
240
public TestBean getNested() {
242
nested = new TestBean();
248
* A String property with an initial value of null.
250
private String nullProperty = null;
252
public String getNullProperty() {
253
return (this.nullProperty);
256
public void setNullProperty(String nullProperty) {
257
this.nullProperty = nullProperty;
262
* A read-only String property.
264
private String readOnlyProperty = "Read Only String Property";
266
public String getReadOnlyProperty() {
267
return (this.readOnlyProperty);
274
private short shortProperty = (short) 987;
276
public short getShortProperty() {
277
return (this.shortProperty);
280
public void setShortProperty(short shortProperty) {
281
this.shortProperty = shortProperty;
286
* A String array property accessed as a String.
288
private String stringArray[] =
289
{ "String 0", "String 1", "String 2", "String 3", "String 4" };
291
public String[] getStringArray() {
292
return (this.stringArray);
295
public void setStringArray(String stringArray[]) {
296
this.stringArray = stringArray;
301
* A String array property accessed as an indexed property.
303
private String stringIndexed[] =
304
{ "String 0", "String 1", "String 2", "String 3", "String 4" };
306
public String getStringIndexed(int index) {
307
return (stringIndexed[index]);
310
public void setStringIndexed(int index, String value) {
311
stringIndexed[index] = value;
318
private String stringProperty = "This is a string";
320
public String getStringProperty() {
321
return (this.stringProperty);
324
public void setStringProperty(String stringProperty) {
325
this.stringProperty = stringProperty;
330
* A write-only String property.
332
private String writeOnlyProperty = "Write Only String Property";
334
public String getWriteOnlyPropertyValue() {
335
return (this.writeOnlyProperty);
338
public void setWriteOnlyProperty(String writeOnlyProperty) {
339
this.writeOnlyProperty = writeOnlyProperty;