Source Code Cross Referenced for AsyncFormModificationTest.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:        package org.araneaframework.tests;
002:
003:        import junit.framework.TestCase;
004:        import org.araneaframework.http.core.StandardServletInputData;
005:        import org.araneaframework.tests.mock.MockEnvironment;
006:        import org.araneaframework.tests.util.RequestUtil;
007:        import org.araneaframework.uilib.form.Data;
008:        import org.araneaframework.uilib.form.FormElement;
009:        import org.araneaframework.uilib.form.FormWidget;
010:        import org.araneaframework.uilib.form.control.BaseControl;
011:        import org.araneaframework.uilib.form.control.FloatControl;
012:        import org.araneaframework.uilib.form.control.TextControl;
013:        import org.araneaframework.uilib.form.data.BigDecimalData;
014:        import org.araneaframework.uilib.form.data.StringData;
015:        import org.springframework.mock.web.MockHttpServletRequest;
016:
017:        /**
018:         * Regression test for changes made in change #153 ("Asynchronous form modifications"). 
019:         * @author Taimo Peelo (taimo@araneaframework.org)
020:         */
021:        public class AsyncFormModificationTest extends TestCase {
022:            protected FormWidget makeForm() throws Exception {
023:                FormWidget testForm = new FormWidget();
024:                testForm.addElement("myLongText", "my long text",
025:                        new TextControl(), new StringData(), true);
026:                testForm._getComponent().init(null, new MockEnvironment());
027:                return testForm;
028:            }
029:
030:            /* Test setting the value of fully initialized FormElement. */
031:            public void testSetValue_1() throws Exception {
032:                String value = "newvalue";
033:
034:                FormWidget form = makeForm();
035:                FormElement el = form.getElementByFullName("myLongText");
036:
037:                el.setValue(value);
038:
039:                assertEquals("Element value incorrect: '" + value + "' != '"
040:                        + el.getValue() + "'", "newvalue", el.getValue());
041:            }
042:
043:            /* Test whether the createElement() with initialValue set produces 
044:             * expected results when FormElement is left uninited. */
045:            public void testSetValue_2() throws Exception {
046:                String value = "newvalue";
047:
048:                FormWidget form = makeForm();
049:                FormElement el = form.createElement("labelId",
050:                        new TextControl(), new StringData(), value, false);
051:
052:                assertEquals("Element value incorrect", value, el.getValue());
053:            }
054:
055:            /* Test that replacing inited FormElement's Data changes FormElement's value to Data's value.
056:             * After that, make sure that Control sees the same value (meaning that asynchronous form 
057:             * modifications work). */
058:            public void testSetValue_3() throws Exception {
059:                String value = "newvalue";
060:                Data data = new StringData();
061:                data.setValue(value);
062:
063:                FormWidget form = makeForm();
064:                FormElement element = form.getElementByFullName("myLongText");
065:
066:                element.setData(data);
067:                assertEquals("Element value incorrect", value, element
068:                        .getValue());
069:
070:                TextControl.ViewModel viewModel = (TextControl.ViewModel) ((BaseControl) (element
071:                        .getControl())).getViewModel();
072:
073:                assertEquals(
074:                        "Inited formelement's Control value differs from Data value",
075:                        value, viewModel.getSimpleValue());
076:            }
077:
078:            /* Test that replacing uninited FormElement's Data changes FormElement's value to Data's value.
079:             * After that, demonstrate that Control inside uninited FormElement is still unaware of its value. */
080:            public void testSetValue_4() throws Exception {
081:                String value = "newvalue";
082:                Data data = new StringData();
083:                data.setValue(value);
084:
085:                FormWidget form = makeForm();
086:                FormElement element = form.createElement("labelId",
087:                        new TextControl(), new StringData(), "initial", false);
088:
089:                element.setData(data);
090:                assertEquals("Element value incorrect", value, element
091:                        .getValue());
092:
093:                TextControl.ViewModel viewModel = (TextControl.ViewModel) ((BaseControl) (element
094:                        .getControl())).getViewModel();
095:
096:                // As Control's converters are not yet in place, this is expected to be false.
097:                if (value.equals(viewModel.getSimpleValue())) {
098:                    fail("Unexpected semantic change (might be real useful :D): See test comments for details.");
099:                }
100:            }
101:
102:            /* Test that convert() retains the Control contents when request with invalid form field content comes in. */
103:            public void testConvert_1() throws Exception {
104:                String notNumber = "qwe";
105:                String someText = "someText";
106:
107:                FormWidget testForm = new FormWidget();
108:                testForm.addElement("number", "#Number", new FloatControl(),
109:                        new BigDecimalData(), true);
110:                testForm.addElement("text", "#Text", new TextControl(),
111:                        new StringData(), false);
112:                testForm._getComponent().init(null, new MockEnvironment());
113:
114:                // construct the request
115:                MockHttpServletRequest validRequest = RequestUtil
116:                        .markSubmitted(new MockHttpServletRequest());
117:
118:                validRequest.addParameter("number", notNumber);
119:                ((FormElement) testForm.getElement("number")).rendered();
120:
121:                validRequest.addParameter("text", someText);
122:                ((FormElement) testForm.getElement("text")).rendered();
123:
124:                // process the request
125:                StandardServletInputData input = new StandardServletInputData(
126:                        validRequest);
127:                testForm._getWidget().update(input);
128:
129:                // convert
130:                testForm.convert();
131:
132:                assertEquals(someText, testForm.getControlByFullName("text")
133:                        .getRawValue());
134:                String simpleValue = ((FloatControl.ViewModel) ((BaseControl) testForm
135:                        .getControlByFullName("number")).getViewModel())
136:                        .getSimpleValue();
137:                assertEquals(notNumber, simpleValue);
138:
139:                // this is not true (because of legacy code in StringArrayRequestControl.process())
140:                assertEquals(someText, testForm.getControlByFullName("text")
141:                        .getRawValue());
142:
143:                simpleValue = ((FloatControl.ViewModel) ((BaseControl) testForm
144:                        .getControlByFullName("number")).getViewModel())
145:                        .getSimpleValue();
146:                assertEquals(notNumber, simpleValue);
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.