Source Code Cross Referenced for FormRWTest.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » tests » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.tests;
016:
017:        import java.util.HashMap;
018:        import java.util.Map;
019:        import junit.framework.TestCase;
020:        import org.apache.commons.logging.Log;
021:        import org.apache.commons.logging.LogFactory;
022:        import org.araneaframework.tests.mock.MockEnvironment;
023:        import org.araneaframework.tests.mock.TestVO;
024:        import org.araneaframework.uilib.form.FormWidget;
025:        import org.araneaframework.uilib.form.control.CheckboxControl;
026:        import org.araneaframework.uilib.form.control.TextControl;
027:        import org.araneaframework.uilib.form.data.BooleanData;
028:        import org.araneaframework.uilib.form.data.LongData;
029:        import org.araneaframework.uilib.form.data.StringData;
030:        import org.araneaframework.uilib.form.reader.BeanFormReader;
031:        import org.araneaframework.uilib.form.reader.BeanFormWriter;
032:        import org.araneaframework.uilib.form.reader.MapFormReader;
033:        import org.araneaframework.uilib.form.reader.MapFormWriter;
034:
035:        /**
036:         * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
037:         * 
038:         */
039:        public class FormRWTest extends TestCase {
040:
041:            private static final Log log = LogFactory.getLog(FormRWTest.class);
042:
043:            private FormWidget makeVoForm() throws Exception {
044:
045:                //Creating form :-)
046:                FormWidget voForm = new FormWidget();
047:                voForm._getComponent().init(null, new MockEnvironment());
048:
049:                //Adding elements to form
050:                voForm.addElement("booleanValue", "vo checkbox",
051:                        new CheckboxControl(), new BooleanData(), true);
052:                voForm.addElement("stringValue", "vo text", new TextControl(),
053:                        new StringData(), true);
054:                voForm.addElement("longValue", "vo long", new TextControl(),
055:                        new LongData(), true);
056:
057:                //Adding a composite element
058:                FormWidget subTestVO = voForm.addSubForm("subTestVO");
059:                subTestVO.addElement("booleanValue", "vo checkbox",
060:                        new CheckboxControl(), new BooleanData(), true);
061:                subTestVO.addElement("stringValue", "vo text",
062:                        new TextControl(), new StringData(), true);
063:                subTestVO.addElement("longValue", "vo long", new TextControl(),
064:                        new LongData(), true);
065:
066:                return voForm;
067:            }
068:
069:            /**
070:             * Tests basic Value Object reading.
071:             */
072:            public void testFormBasicVoReading() throws Exception {
073:
074:                FormWidget voForm = makeVoForm();
075:                TestVO test = new TestVO();
076:
077:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
078:                final Long TEN = new Long(10);
079:
080:                voForm.setValueByFullName("booleanValue", Boolean.TRUE);
081:                voForm.setValueByFullName("stringValue", LIFE_IS_BEAUTIFUL);
082:                voForm.setValueByFullName("longValue", TEN);
083:
084:                BeanFormReader voReader = new BeanFormReader(voForm);
085:
086:                voReader.readFormBean(test);
087:
088:                log.debug("Value Object after reading from form" + test);
089:
090:                assertTrue("Boolean value read properly", test
091:                        .getBooleanValue().equals(Boolean.TRUE));
092:                assertTrue("String value read properly", test.getStringValue()
093:                        .equals(LIFE_IS_BEAUTIFUL));
094:                assertTrue("Long value read properly", test.getLongValue()
095:                        .equals(TEN));
096:            }
097:
098:            /**
099:             * Tests hierarchical Value Object reading.
100:             */
101:            public void testFormHierarchicalVoReading() throws Exception {
102:
103:                FormWidget voForm = makeVoForm();
104:                TestVO test = new TestVO();
105:
106:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
107:                final Long TEN = new Long(10);
108:
109:                voForm.setValueByFullName("subTestVO.booleanValue",
110:                        Boolean.TRUE);
111:                voForm.setValueByFullName("subTestVO.stringValue",
112:                        LIFE_IS_BEAUTIFUL);
113:                voForm.setValueByFullName("subTestVO.longValue", TEN);
114:
115:                BeanFormReader voReader = new BeanFormReader(voForm);
116:
117:                voReader.readFormBean(test);
118:
119:                log.debug("Value Object after reading from form");
120:
121:                assertTrue("Boolean value read properly", test.getSubTestVO()
122:                        .getBooleanValue().equals(Boolean.TRUE));
123:                assertTrue("String value read properly", test.getSubTestVO()
124:                        .getStringValue().equals(LIFE_IS_BEAUTIFUL));
125:                assertTrue("Long value read properly", test.getSubTestVO()
126:                        .getLongValue().equals(TEN));
127:            }
128:
129:            /**
130:             * Tests basic Value Object writing.
131:             */
132:            public void testFormBasicVoWriting() throws Exception {
133:
134:                FormWidget voForm = makeVoForm();
135:                TestVO test = new TestVO();
136:
137:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
138:                final Long TEN = new Long(10);
139:
140:                test.setBooleanValue(Boolean.TRUE);
141:                test.setStringValue(LIFE_IS_BEAUTIFUL);
142:                test.setLongValue(TEN);
143:
144:                BeanFormWriter voWriter = new BeanFormWriter(test.getClass());
145:
146:                voWriter.writeFormBean(voForm, test);
147:
148:                assertTrue("Boolean value written properly", voForm
149:                        .getValueByFullName("booleanValue")
150:                        .equals(Boolean.TRUE));
151:                assertTrue("String value written properly", voForm
152:                        .getValueByFullName("stringValue").equals(
153:                                LIFE_IS_BEAUTIFUL));
154:                assertTrue("Long value written properly", voForm
155:                        .getValueByFullName("longValue").equals(TEN));
156:            }
157:
158:            /**
159:             * Tests hierarchical Value Object writing.
160:             */
161:            public void testFormHierarchicalVoWriting() throws Exception {
162:
163:                FormWidget voForm = makeVoForm();
164:                TestVO test = new TestVO();
165:
166:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
167:                final Long TEN = new Long(10);
168:
169:                test.setSubTestVO(new TestVO());
170:
171:                test.getSubTestVO().setBooleanValue(Boolean.TRUE);
172:                test.getSubTestVO().setStringValue(LIFE_IS_BEAUTIFUL);
173:                test.getSubTestVO().setLongValue(TEN);
174:
175:                BeanFormWriter voWriter = new BeanFormWriter(test.getClass());
176:
177:                voWriter.writeFormBean(voForm, test);
178:
179:                assertTrue("Boolean value written properly", voForm
180:                        .getValueByFullName("subTestVO.booleanValue").equals(
181:                                Boolean.TRUE));
182:                assertTrue("String value written properly", voForm
183:                        .getValueByFullName("subTestVO.stringValue").equals(
184:                                LIFE_IS_BEAUTIFUL));
185:                assertTrue("Long value written properly", voForm
186:                        .getValueByFullName("subTestVO.longValue").equals(TEN));
187:            }
188:
189:            /**
190:             * Tests basic Map reading.
191:             */
192:            public void testFormBasicMapReading() throws Exception {
193:
194:                FormWidget mapForm = makeVoForm();
195:
196:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
197:                final Long TEN = new Long(10);
198:
199:                mapForm.setValueByFullName("booleanValue", Boolean.TRUE);
200:                mapForm.setValueByFullName("stringValue", LIFE_IS_BEAUTIFUL);
201:                mapForm.setValueByFullName("longValue", TEN);
202:
203:                MapFormReader mapReader = new MapFormReader(mapForm);
204:
205:                Map readMap = mapReader.getMap();
206:
207:                log.debug("Map read from form: " + readMap);
208:
209:                assertTrue("Boolean value read properly", readMap.get(
210:                        "booleanValue").equals(Boolean.TRUE));
211:                assertTrue("String value read properly", readMap.get(
212:                        "stringValue").equals(LIFE_IS_BEAUTIFUL));
213:                assertTrue("Long value read properly", readMap.get("longValue")
214:                        .equals(TEN));
215:            }
216:
217:            /**
218:             * Tests hierarchical Map reading.
219:             */
220:            public void testFormHierarchicalMapReading() throws Exception {
221:
222:                FormWidget mapForm = makeVoForm();
223:
224:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
225:                final Long TEN = new Long(10);
226:
227:                mapForm.setValueByFullName("subTestVO.booleanValue",
228:                        Boolean.TRUE);
229:                mapForm.setValueByFullName("subTestVO.stringValue",
230:                        LIFE_IS_BEAUTIFUL);
231:                mapForm.setValueByFullName("subTestVO.longValue", TEN);
232:
233:                MapFormReader mapReader = new MapFormReader(mapForm);
234:
235:                Map readMap = mapReader.getMap();
236:
237:                log.debug("Map read from form: " + readMap);
238:
239:                Map subTestVoMap = (Map) readMap.get("subTestVO");
240:                assertEquals(Boolean.FALSE, readMap.get("booleanValue"));
241:                assertNull("String value read properly", readMap
242:                        .get("stringValue"));
243:                assertNull("Long value read properly", readMap.get("longValue"));
244:
245:                assertTrue("Boolean value read properly", subTestVoMap.get(
246:                        "booleanValue").equals(Boolean.TRUE));
247:                assertTrue("String value read properly", subTestVoMap.get(
248:                        "stringValue").equals(LIFE_IS_BEAUTIFUL));
249:                assertTrue("Long value read properly", subTestVoMap.get(
250:                        "longValue").equals(TEN));
251:            }
252:
253:            /**
254:             * Tests basic Map writing.
255:             */
256:            public void testFormBasicMapWriting() throws Exception {
257:
258:                FormWidget mapForm = makeVoForm();
259:                Map testMap = new HashMap();
260:
261:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
262:                final Long TEN = new Long(10);
263:
264:                testMap.put("booleanValue", Boolean.TRUE);
265:                testMap.put("stringValue", LIFE_IS_BEAUTIFUL);
266:                testMap.put("longValue", TEN);
267:
268:                MapFormWriter mapWriter = new MapFormWriter();
269:
270:                mapWriter.writeForm(mapForm, testMap);
271:
272:                assertTrue("Boolean value written properly", mapForm
273:                        .getValueByFullName("booleanValue")
274:                        .equals(Boolean.TRUE));
275:                assertTrue("String value written properly", mapForm
276:                        .getValueByFullName("stringValue").equals(
277:                                LIFE_IS_BEAUTIFUL));
278:                assertTrue("Long value written properly", mapForm
279:                        .getValueByFullName("longValue").equals(TEN));
280:            }
281:
282:            /**
283:             * Tests hierarchical Map writing.
284:             */
285:            public void testFormHierarchicalMapWriting() throws Exception {
286:
287:                FormWidget mapForm = makeVoForm();
288:                Map testMap = new HashMap();
289:
290:                final String LIFE_IS_BEAUTIFUL = "Life is beautiful";
291:                final Long TEN = new Long(10);
292:
293:                testMap.put("booleanValue", Boolean.TRUE);
294:                testMap.put("stringValue", LIFE_IS_BEAUTIFUL);
295:                testMap.put("longValue", TEN);
296:
297:                Map topTestMap = new HashMap();
298:                topTestMap.put("subTestVO", testMap);
299:
300:                MapFormWriter mapWriter = new MapFormWriter();
301:
302:                mapWriter.writeForm(mapForm, topTestMap);
303:
304:                assertTrue("Boolean value written properly", mapForm
305:                        .getValueByFullName("subTestVO.booleanValue").equals(
306:                                Boolean.TRUE));
307:                assertTrue("String value written properly", mapForm
308:                        .getValueByFullName("subTestVO.stringValue").equals(
309:                                LIFE_IS_BEAUTIFUL));
310:                assertTrue("Long value written properly", mapForm
311:                        .getValueByFullName("subTestVO.longValue").equals(TEN));
312:            }
313:
314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.