Source Code Cross Referenced for DynaResultSetTestCase.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 java.math.BigDecimal;
021:        import java.util.Iterator;
022:
023:        import junit.framework.TestCase;
024:        import junit.framework.Test;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * Test accessing ResultSets via DynaBeans.
029:         *
030:         * @author Craig R. McClanahan
031:         * @version $Revision: 556221 $ $Date: 2007-07-14 05:19:21 +0100 (Sat, 14 Jul 2007) $
032:         */
033:
034:        public class DynaResultSetTestCase extends TestCase {
035:
036:            // ----------------------------------------------------- Instance Variables
037:
038:            /**
039:             * The mock result set DynaClass to be tested.
040:             */
041:            protected ResultSetDynaClass dynaClass = null;
042:
043:            /**
044:             * Names of the columns for this test.  Must match the order they are
045:             * defined in {@link TestResultSetMetaData}, and must be all lower case.
046:             */
047:            protected String columns[] = { "bigdecimalproperty",
048:                    "booleanproperty", "byteproperty", "dateproperty",
049:                    "doubleproperty", "floatproperty", "intproperty",
050:                    "longproperty", "nullproperty", "shortproperty",
051:                    "stringproperty", "timeproperty", "timestampproperty" };
052:
053:            // ----------------------------------------------------------- Constructors
054:
055:            /**
056:             * Construct a new instance of this test case.
057:             *
058:             * @param name Name of the test case
059:             */
060:            public DynaResultSetTestCase(String name) {
061:
062:                super (name);
063:
064:            }
065:
066:            // --------------------------------------------------- Overall Test Methods
067:
068:            /**
069:             * Set up instance variables required by this test case.
070:             */
071:            public void setUp() throws Exception {
072:
073:                dynaClass = new ResultSetDynaClass(TestResultSet.createProxy());
074:
075:            }
076:
077:            /**
078:             * Return the tests included in this test suite.
079:             */
080:            public static Test suite() {
081:
082:                return (new TestSuite(DynaResultSetTestCase.class));
083:
084:            }
085:
086:            /**
087:             * Tear down instance variables required by this test case.
088:             */
089:            public void tearDown() {
090:
091:                dynaClass = null;
092:
093:            }
094:
095:            // ------------------------------------------------ Individual Test Methods
096:
097:            public void testGetName() {
098:
099:                assertEquals("DynaClass name",
100:                        "org.apache.commons.beanutils.ResultSetDynaClass",
101:                        dynaClass.getName());
102:
103:            }
104:
105:            public void testGetDynaProperty() {
106:
107:                // Invalid argument test
108:                try {
109:                    dynaClass.getDynaProperty(null);
110:                    fail("Did not throw IllegaArgumentException");
111:                } catch (IllegalArgumentException e) {
112:                    // Expected result
113:                }
114:
115:                // Negative test
116:                DynaProperty dynaProp = dynaClass
117:                        .getDynaProperty("unknownProperty");
118:                assertTrue("unknown property returns null", (dynaProp == null));
119:
120:                // Positive test
121:                dynaProp = dynaClass.getDynaProperty("stringproperty");
122:                assertNotNull("string property exists", dynaProp);
123:                assertEquals("string property name", "stringproperty", dynaProp
124:                        .getName());
125:                assertEquals("string property class", String.class, dynaProp
126:                        .getType());
127:
128:            }
129:
130:            public void testGetDynaProperties() {
131:
132:                DynaProperty dynaProps[] = dynaClass.getDynaProperties();
133:                assertNotNull("dynaProps exists", dynaProps);
134:                assertEquals("dynaProps length", columns.length,
135:                        dynaProps.length);
136:                for (int i = 0; i < columns.length; i++) {
137:                    assertEquals("Property " + columns[i], columns[i],
138:                            dynaProps[i].getName());
139:                }
140:
141:            }
142:
143:            public void testNewInstance() {
144:
145:                try {
146:                    dynaClass.newInstance();
147:                    fail("Did not throw UnsupportedOperationException()");
148:                } catch (UnsupportedOperationException e) {
149:                    // Expected result
150:                } catch (Exception e) {
151:                    fail("Threw exception " + e);
152:                }
153:
154:            }
155:
156:            public void testIteratorCount() {
157:
158:                Iterator rows = dynaClass.iterator();
159:                assertNotNull("iterator exists", rows);
160:                int n = 0;
161:                while (rows.hasNext()) {
162:                    rows.next();
163:                    n++;
164:                    if (n > 10) {
165:                        fail("Returned too many rows");
166:                    }
167:                }
168:                assertEquals("iterator rows", 5, n);
169:
170:            }
171:
172:            public void testIteratorResults() {
173:
174:                // Grab the third row
175:                Iterator rows = dynaClass.iterator();
176:                rows.next();
177:                rows.next();
178:                DynaBean row = (DynaBean) rows.next();
179:
180:                // Invalid argument test
181:                try {
182:                    row.get("unknownProperty");
183:                    fail("Did not throw IllegalArgumentException");
184:                } catch (IllegalArgumentException e) {
185:                    // Expected result
186:                }
187:
188:                // Verify property values
189:
190:                Object bigDecimalProperty = row.get("bigdecimalproperty");
191:                assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
192:                assertTrue("bigDecimalProperty type",
193:                        bigDecimalProperty instanceof  BigDecimal);
194:                assertEquals("bigDecimalProperty value", 123.45,
195:                        ((BigDecimal) bigDecimalProperty).doubleValue(), 0.005);
196:
197:                Object intProperty = row.get("intproperty");
198:                assertNotNull("intProperty exists", intProperty);
199:                assertTrue("intProperty type", intProperty instanceof  Integer);
200:                assertEquals("intProperty value", 103, ((Integer) intProperty)
201:                        .intValue());
202:
203:                Object nullProperty = row.get("nullproperty");
204:                assertNull("nullProperty null", nullProperty);
205:
206:                Object stringProperty = row.get("stringproperty");
207:                assertNotNull("stringProperty exists", stringProperty);
208:                assertTrue("stringProperty type",
209:                        stringProperty instanceof  String);
210:                assertEquals("stringProperty value", "This is a string",
211:                        (String) stringProperty);
212:
213:            }
214:
215:            /**
216:             * Test normal case column names (i.e. not converted to lower case)
217:             */
218:            public void testIteratorResultsNormalCase() {
219:                ResultSetDynaClass dynaClass = null;
220:                try {
221:                    dynaClass = new ResultSetDynaClass(TestResultSet
222:                            .createProxy(), false);
223:                } catch (Exception e) {
224:                    fail("Error creating ResultSetDynaClass: " + e);
225:                }
226:
227:                // Grab the third row
228:                Iterator rows = dynaClass.iterator();
229:                rows.next();
230:                rows.next();
231:                DynaBean row = (DynaBean) rows.next();
232:
233:                // Invalid argument test
234:                try {
235:                    row.get("unknownProperty");
236:                    fail("Did not throw IllegalArgumentException");
237:                } catch (IllegalArgumentException e) {
238:                    // Expected result
239:                }
240:
241:                // Verify property values
242:
243:                Object bigDecimalProperty = row.get("bigDecimalProperty");
244:                assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
245:                assertTrue("bigDecimalProperty type",
246:                        bigDecimalProperty instanceof  BigDecimal);
247:                assertEquals("bigDecimalProperty value", 123.45,
248:                        ((BigDecimal) bigDecimalProperty).doubleValue(), 0.005);
249:
250:                Object intProperty = row.get("intProperty");
251:                assertNotNull("intProperty exists", intProperty);
252:                assertTrue("intProperty type", intProperty instanceof  Integer);
253:                assertEquals("intProperty value", 103, ((Integer) intProperty)
254:                        .intValue());
255:
256:                Object nullProperty = row.get("nullProperty");
257:                assertNull("nullProperty null", nullProperty);
258:
259:                Object stringProperty = row.get("stringProperty");
260:                assertNotNull("stringProperty exists", stringProperty);
261:                assertTrue("stringProperty type",
262:                        stringProperty instanceof  String);
263:                assertEquals("stringProperty value", "This is a string",
264:                        (String) stringProperty);
265:
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.