Source Code Cross Referenced for BeanToPropertyValueTransformerTestCase.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.beanutils;
019:
020:        import junit.framework.TestCase;
021:
022:        /**
023:         * Test cases for <code>BeanToPropertyValueTransformer</code>.
024:         *
025:         * @author Norm Deane
026:         */
027:        public class BeanToPropertyValueTransformerTestCase extends TestCase {
028:
029:            private static final Integer expectedIntegerValue = new Integer(123);
030:            private static final Long expectedLongValue = new Long(123);
031:            private static final Float expectedFloatValue = new Float(123.123f);
032:            private static final Double expectedDoubleValue = new Double(
033:                    567879.12344d);
034:            private static final Boolean expectedBooleanValue = Boolean.TRUE;
035:            private static final Byte expectedByteValue = new Byte("12");
036:
037:            /**
038:             * Constructor for BeanToPropertyValueTransformerTestCase.
039:             *
040:             * @param name Name of this test case.
041:             */
042:            public BeanToPropertyValueTransformerTestCase(String name) {
043:                super (name);
044:            }
045:
046:            /**
047:             * Test transform with simple String property.
048:             */
049:            public void testTransformWithSimpleStringProperty() {
050:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
051:                        "stringProperty");
052:                TestBean testBean = new TestBean("foo");
053:                assertEquals("foo", transformer.transform(testBean));
054:            }
055:
056:            /**
057:             * Test transform with simple String property and null value.
058:             *
059:             */
060:            public void testTransformWithSimpleStringPropertyAndNullValue() {
061:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
062:                        "stringProperty");
063:                TestBean testBean = new TestBean((String) null);
064:                assertNull(transformer.transform(testBean));
065:            }
066:
067:            /**
068:             * Test transform with simple int property.
069:             */
070:            public void testTransformWithSimpleIntProperty() {
071:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
072:                        "intProperty");
073:                TestBean testBean = new TestBean(expectedIntegerValue
074:                        .intValue());
075:                assertEquals(expectedIntegerValue, transformer
076:                        .transform(testBean));
077:            }
078:
079:            /**
080:             * Test transform with simple long property.
081:             */
082:            public void testTransformWithSimpleLongProperty() {
083:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
084:                        "longProperty");
085:                TestBean testBean = new TestBean();
086:                testBean.setLongProperty(expectedLongValue.longValue());
087:                assertEquals(expectedLongValue, transformer.transform(testBean));
088:            }
089:
090:            /**
091:             * Test transform with simple float property.
092:             */
093:            public void testTransformWithSimpleFloatProperty() {
094:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
095:                        "floatProperty");
096:                TestBean testBean = new TestBean(expectedFloatValue
097:                        .floatValue());
098:                assertEquals(expectedFloatValue, transformer
099:                        .transform(testBean));
100:            }
101:
102:            /**
103:             * Test transform with simple double property.
104:             */
105:            public void testTransformWithSimpleDoubleProperty() {
106:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
107:                        "doubleProperty");
108:                TestBean testBean = new TestBean(expectedDoubleValue
109:                        .doubleValue());
110:                assertEquals(expectedDoubleValue, transformer
111:                        .transform(testBean));
112:            }
113:
114:            /**
115:             * Test transform with simple byte property.
116:             */
117:            public void testTransformWithSimpleByteProperty() {
118:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
119:                        "byteProperty");
120:                TestBean testBean = new TestBean();
121:                testBean.setByteProperty(expectedByteValue.byteValue());
122:                assertEquals(expectedByteValue, transformer.transform(testBean));
123:            }
124:
125:            /**
126:             * Test transform with simple boolean property.
127:             */
128:            public void testTransformWithSimpleBooleanProperty() {
129:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
130:                        "booleanProperty");
131:                TestBean testBean = new TestBean(expectedBooleanValue
132:                        .booleanValue());
133:                assertEquals(expectedBooleanValue, transformer
134:                        .transform(testBean));
135:            }
136:
137:            /**
138:             * Test transform with write only property.
139:             */
140:            public void testTransformWithWriteOnlyProperty() {
141:                try {
142:                    new BeanToPropertyValueTransformer("writeOnlyProperty")
143:                            .transform(new TestBean());
144:                } catch (IllegalArgumentException e) {
145:                    /* This is what should happen */
146:                }
147:            }
148:
149:            /**
150:             * Test transform with read only property.
151:             */
152:            public void testTransformWithReadOnlyProperty() {
153:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
154:                        "readOnlyProperty");
155:                TestBean testBean = new TestBean();
156:                assertEquals(testBean.getReadOnlyProperty(), transformer
157:                        .transform(testBean));
158:            }
159:
160:            /**
161:             * Test transform with invalid property.
162:             */
163:            public void testTransformWithInvalidProperty() {
164:                try {
165:                    new BeanToPropertyValueTransformer("bogusProperty")
166:                            .transform(new TestBean());
167:                } catch (IllegalArgumentException e) {
168:                    /* This is what should happen */
169:                }
170:            }
171:
172:            /**
173:             * Test transform with nested property.
174:             */
175:            public void testTransformWithNestedProperty() {
176:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
177:                        "anotherNested.stringProperty");
178:                TestBean testBean = new TestBean();
179:                TestBean nestedBean = new TestBean("foo");
180:                testBean.setAnotherNested(nestedBean);
181:                assertEquals("foo", transformer.transform(testBean));
182:            }
183:
184:            /**
185:             * Test transform with mapped property.
186:             */
187:            public void testTransformWithMappedProperty() {
188:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
189:                        "mappedProperty(test-key)");
190:                TestBean testBean = new TestBean();
191:
192:                // try a valid key
193:                testBean.setMappedProperty("test-key", "test-value");
194:                assertEquals("test-value", transformer.transform(testBean));
195:
196:                // now try an invalid key
197:                transformer = new BeanToPropertyValueTransformer(
198:                        "mappedProperty(bogus-key)");
199:                assertEquals(null, transformer.transform(testBean));
200:            }
201:
202:            /**
203:             * Test transform with indexed property.
204:             */
205:            public void testTransformWithIndexedProperty() {
206:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
207:                        "intIndexed[0]");
208:                TestBean testBean = new TestBean();
209:                testBean.setIntIndexed(0, expectedIntegerValue.intValue());
210:                assertEquals(expectedIntegerValue, transformer
211:                        .transform(testBean));
212:
213:                // test index out of range
214:                transformer = new BeanToPropertyValueTransformer(
215:                        "intIndexed[9999]");
216:
217:                try {
218:                    transformer.transform(testBean);
219:                    fail("Should have thrown an ArrayIndexOutOfBoundsException");
220:                } catch (ArrayIndexOutOfBoundsException e) {
221:                    /* this is what should happen */
222:                }
223:            }
224:
225:            /**
226:             * Test transform with nested indexed property.
227:             */
228:            public void testTransformWithNestedIndexedProperty() {
229:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
230:                        "anotherNested.intIndexed[0]");
231:                TestBean testBean = new TestBean();
232:                TestBean nestedBean = new TestBean();
233:                nestedBean.setIntIndexed(0, expectedIntegerValue.intValue());
234:                testBean.setAnotherNested(nestedBean);
235:                assertEquals(expectedIntegerValue, transformer
236:                        .transform(testBean));
237:            }
238:
239:            /**
240:             * Test transform with null in property path.
241:             */
242:            public void testTransformWithNullInPath() {
243:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
244:                        "anotherNested.stringProperty");
245:
246:                try {
247:                    transformer.transform(new TestBean());
248:                    fail("Should have throw IllegalArgumentException");
249:                } catch (IllegalArgumentException e) {
250:                    /* ignore this is what should happen */
251:                }
252:            }
253:
254:            /**
255:             * Test transform with null in property path and ignore = true.
256:             */
257:            public void testTransformWithNullInPathAndIgnoreTrue() {
258:                BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer(
259:                        "anotherNested.stringProperty", true);
260:                assertEquals(null, transformer.transform(new TestBean()));
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.