Source Code Cross Referenced for LazyDynaClassTestCase.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:        package org.apache.commons.beanutils;
018:
019:        import junit.framework.TestCase;
020:        import junit.framework.Test;
021:        import junit.framework.TestSuite;
022:
023:        /**
024:         * <p>Test Case for the <code>LazyDynaClass</code> implementation class.</p>
025:         *
026:         * @author Niall Pemberton
027:         */
028:        public class LazyDynaClassTestCase extends TestCase {
029:
030:            protected LazyDynaClass dynaClass = null;
031:            protected String testProperty = "myProperty";
032:
033:            // ---------------------------------------------------------- Constructors
034:
035:            /**
036:             * Construct a new instance of this test case.
037:             *
038:             * @param name Name of the test case
039:             */
040:            public LazyDynaClassTestCase(String name) {
041:                super (name);
042:            }
043:
044:            // -------------------------------------------------- Overall Test Methods
045:
046:            /**
047:             * Run this Test
048:             */
049:            public static void main(String[] args) {
050:                junit.textui.TestRunner.run(suite());
051:            }
052:
053:            /**
054:             * Set up instance variables required by this test case.
055:             */
056:            public void setUp() throws Exception {
057:                dynaClass = new LazyDynaClass();
058:            }
059:
060:            /**
061:             * Return the tests included in this test suite.
062:             */
063:            public static Test suite() {
064:                return (new TestSuite(LazyDynaClassTestCase.class));
065:            }
066:
067:            /**
068:             * Tear down instance variables required by this test case.
069:             */
070:            public void tearDown() {
071:                dynaClass = null;
072:            }
073:
074:            // ------------------------------------------------ Individual Test Methods
075:
076:            /**
077:             * Test add(name) method
078:             */
079:            public void testAddProperty1() {
080:                dynaClass.add(testProperty);
081:                DynaProperty dynaProperty = dynaClass
082:                        .getDynaProperty(testProperty);
083:                assertEquals("name is correct", testProperty, dynaProperty
084:                        .getName());
085:                assertEquals("type is correct", Object.class, dynaProperty
086:                        .getType());
087:            }
088:
089:            /**
090:             * Test add(name, type) method
091:             */
092:            public void testAddProperty2() {
093:                dynaClass.add(testProperty, String.class);
094:                DynaProperty dynaProperty = dynaClass
095:                        .getDynaProperty(testProperty);
096:                assertEquals("name is correct", testProperty, dynaProperty
097:                        .getName());
098:                assertEquals("type is correct", String.class, dynaProperty
099:                        .getType());
100:            }
101:
102:            /**
103:             * Test add(name, type, readable, writable) method
104:             */
105:            public void testAddProperty3() {
106:                try {
107:                    dynaClass.add(testProperty, String.class, true, true);
108:                    fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
109:                } catch (UnsupportedOperationException expected) {
110:                    // expected result
111:                }
112:            }
113:
114:            /**
115:             * Test add(name) method with 'null' name
116:             */
117:            public void testAddPropertyNullName1() {
118:                try {
119:                    dynaClass.add((String) null);
120:                    fail("null property name not prevented");
121:                } catch (IllegalArgumentException expected) {
122:                    // expected result
123:                }
124:            }
125:
126:            /**
127:             * Test add(name, type) method with 'null' name
128:             */
129:            public void testAddPropertyNullName2() {
130:                try {
131:                    dynaClass.add(null, String.class);
132:                    fail("null property name not prevented");
133:                } catch (IllegalArgumentException expected) {
134:                    // expected result
135:                }
136:            }
137:
138:            /**
139:             * Test add(name, type, readable, writable) method with 'null' name
140:             */
141:            public void testAddPropertyNullName3() {
142:                try {
143:                    dynaClass.add(null, String.class, true, true);
144:                    fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
145:                } catch (UnsupportedOperationException expected) {
146:                    // expected result
147:                }
148:            }
149:
150:            /**
151:             * Test add(name) method when restricted is set to 'true'
152:             */
153:            public void testAddPropertyRestricted1() {
154:                dynaClass.setRestricted(true);
155:                assertTrue("MutableDynaClass is restricted", dynaClass
156:                        .isRestricted());
157:                try {
158:                    dynaClass.add(testProperty);
159:                    fail("add(name) did not throw IllegalStateException");
160:                } catch (IllegalStateException expected) {
161:                    // expected result
162:                }
163:            }
164:
165:            /**
166:             * Test add(name, type) method when restricted is set to 'true'
167:             */
168:            public void testAddPropertyRestricted2() {
169:                dynaClass.setRestricted(true);
170:                assertTrue("MutableDynaClass is restricted", dynaClass
171:                        .isRestricted());
172:                try {
173:                    dynaClass.add(testProperty, String.class);
174:                    fail("add(name, type) did not throw IllegalStateException");
175:                } catch (IllegalStateException expected) {
176:                    // expected result
177:                }
178:            }
179:
180:            /**
181:             * Test add(name, type, readable, writable) method when restricted is set to 'true'
182:             */
183:            public void testAddPropertyRestricted3() {
184:                dynaClass.setRestricted(true);
185:                assertTrue("MutableDynaClass is restricted", dynaClass
186:                        .isRestricted());
187:                try {
188:                    dynaClass.add(testProperty, String.class, true, true);
189:                    fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
190:                } catch (UnsupportedOperationException t) {
191:                    // expected result
192:                }
193:            }
194:
195:            /**
196:             * Test retrieving a property which doesn't exist (returnNull is 'false')
197:             */
198:            public void testGetPropertyDoesntExist1() {
199:                dynaClass.setReturnNull(false);
200:                assertFalse("returnNull is 'false'", dynaClass.isReturnNull());
201:                DynaProperty dynaProperty = dynaClass
202:                        .getDynaProperty(testProperty);
203:                assertEquals("name is correct", testProperty, dynaProperty
204:                        .getName());
205:                assertEquals("type is correct", Object.class, dynaProperty
206:                        .getType());
207:                assertFalse("property doesnt exist", dynaClass
208:                        .isDynaProperty(testProperty));
209:            }
210:
211:            /**
212:             * Test retrieving a property which doesn't exist (returnNull is 'true')
213:             */
214:            public void testGetPropertyDoesntExist2() {
215:                dynaClass.setReturnNull(true);
216:                assertTrue("returnNull is 'true'", dynaClass.isReturnNull());
217:                assertNull("property is null", dynaClass
218:                        .getDynaProperty(testProperty));
219:            }
220:
221:            /**
222:             * Test removing a property
223:             */
224:            public void testRemoveProperty() {
225:                dynaClass.setReturnNull(true);
226:                dynaClass.add(testProperty);
227:                assertTrue("Property exists", dynaClass
228:                        .isDynaProperty(testProperty));
229:                assertNotNull("property is Not null", dynaClass
230:                        .getDynaProperty(testProperty));
231:                dynaClass.remove(testProperty);
232:                assertFalse("Property doesn't exist", dynaClass
233:                        .isDynaProperty(testProperty));
234:                assertNull("property is null", dynaClass
235:                        .getDynaProperty(testProperty));
236:            }
237:
238:            /**
239:             * Test removing a property, name is null
240:             */
241:            public void testRemovePropertyNullName() {
242:                try {
243:                    dynaClass.remove(null);
244:                    fail("remove(null) did not throw IllegalArgumentException");
245:                } catch (IllegalArgumentException expected) {
246:                    // expected result
247:                }
248:            }
249:
250:            /**
251:             * Test removing a property, DynaClass is restricted
252:             */
253:            public void testRemovePropertyRestricted() {
254:                dynaClass.add(testProperty);
255:                assertTrue("Property exists", dynaClass
256:                        .isDynaProperty(testProperty));
257:                dynaClass.setRestricted(true);
258:                assertTrue("MutableDynaClass is restricted", dynaClass
259:                        .isRestricted());
260:                try {
261:                    dynaClass.remove(testProperty);
262:                    fail("remove property when MutableDynaClassis restricted did not throw IllegalStateException");
263:                } catch (IllegalStateException expected) {
264:                    // expected result
265:                }
266:            }
267:
268:            /**
269:             * Test removing a property which doesn't exist
270:             */
271:            public void testRemovePropertyDoesntExist() {
272:                assertFalse("property doesn't exist", dynaClass
273:                        .isDynaProperty(testProperty));
274:                dynaClass.remove(testProperty);
275:                assertFalse("property still doesn't exist", dynaClass
276:                        .isDynaProperty(testProperty));
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.