Source Code Cross Referenced for CheckGroupTest.java in  » J2EE » wicket » wicket » markup » html » form » 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 » J2EE » wicket » wicket.markup.html.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CheckGroupTest.java 475147 2006-11-15 07:57:36Z ivaynberg $ $Revision:
003:         * 1.2 $ $Date: 2006-11-15 08:57:36 +0100 (Wed, 15 Nov 2006) $
004:         * 
005:         * ==============================================================================
006:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007:         * use this file except in compliance with the License. You may obtain a copy of
008:         * the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations under
016:         * the License.
017:         */
018:
019:        package wicket.markup.html.form;
020:
021:        import java.io.Serializable;
022:        import java.util.ArrayList;
023:        import java.util.HashSet;
024:        import java.util.List;
025:        import java.util.Set;
026:
027:        import wicket.RequestCycle;
028:        import wicket.WicketRuntimeException;
029:        import wicket.WicketTestCase;
030:        import wicket.markup.html.WebMarkupContainer;
031:        import wicket.model.CompoundPropertyModel;
032:        import wicket.model.Model;
033:        import wicket.protocol.http.MockPage;
034:
035:        /**
036:         * @author jcompagner
037:         */
038:        /**
039:         * Test for RadioGroup and Radio components
040:         * 
041:         * @author igor
042:         * 
043:         */
044:        public class CheckGroupTest extends WicketTestCase {
045:
046:            /**
047:             * @param name
048:             */
049:            public CheckGroupTest(String name) {
050:                super (name);
051:            }
052:
053:            /**
054:             * mock model object with an embedded property used to test compound
055:             * property model
056:             * 
057:             * @author igor
058:             * 
059:             */
060:            public static class MockModelObject implements  Serializable {
061:                private static final long serialVersionUID = 1L;
062:
063:                private Set prop1 = new HashSet();
064:                private String prop2;
065:
066:                /**
067:                 * @return prop1
068:                 */
069:                public Set getProp1() {
070:                    return prop1;
071:                }
072:
073:                /**
074:                 * @param prop1
075:                 */
076:                public void setProp1(Set prop1) {
077:                    this .prop1 = prop1;
078:                }
079:
080:                /**
081:                 * @return prop2
082:                 */
083:                public String getProp2() {
084:                    return prop2;
085:                }
086:
087:                /**
088:                 * @param prop2
089:                 */
090:                public void setProp2(String prop2) {
091:                    this .prop2 = prop2;
092:                }
093:
094:            }
095:
096:            /**
097:             * test component form processing
098:             */
099:            public void testFormProcessing() {
100:                // setup some values we will use for testing as well as a test model
101:                final String check1 = "check1-selection";
102:                final String check2 = "check2-selection";
103:
104:                MockModelObject modelObject = new MockModelObject();
105:                modelObject.setProp2(check2);
106:
107:                // test model constructors
108:                List list = new ArrayList();
109:                Model model = new Model((Serializable) list);
110:
111:                final CheckGroup group2 = new CheckGroup("group2", model);
112:                assertTrue(group2.getModelObject() == list);
113:
114:                final CheckGroup group3 = new CheckGroup("group3", list);
115:                assertTrue(group3.getModelObject() == list);
116:
117:                // set up necessary objects to emulate a form submission
118:
119:                RequestCycle cycle = application.createRequestCycle();
120:
121:                MockPage page = new MockPage();
122:
123:                // create component hierarchy
124:
125:                final Form form = new Form("form", new CompoundPropertyModel(
126:                        modelObject));
127:
128:                final CheckGroup group = new CheckGroup("prop1");
129:
130:                final WebMarkupContainer container = new WebMarkupContainer(
131:                        "container");
132:
133:                final Check choice1 = new Check("check1", new Model(check1));
134:                final Check choice2 = new Check("prop2");
135:
136:                page.add(form);
137:                form.add(group);
138:                group.add(container);
139:                container.add(choice1);
140:                group.add(choice2);
141:
142:                // test mock form submissions
143:
144:                modelObject.getProp1().add(check1);
145:
146:                form.onFormSubmitted();
147:                assertTrue(
148:                        "running with nothing selected - model must be empty",
149:                        modelObject.getProp1().size() == 0);
150:
151:                application.getServletRequest().setParameter(
152:                        group.getInputName(),
153:                        String.valueOf(choice1.getValue()));
154:                form.onFormSubmitted();
155:                assertTrue(
156:                        "running with choice1 selected - model must only contain value of check1",
157:                        modelObject.getProp1().size() == 1
158:                                && modelObject.getProp1().contains(check1));
159:
160:                application.getServletRequest().setParameter(
161:                        group.getInputName(),
162:                        String.valueOf(choice2.getValue()));
163:                form.onFormSubmitted();
164:                assertTrue(
165:                        "running with choice2 selected - model must only contain value of check2",
166:                        modelObject.getProp1().size() == 1
167:                                && modelObject.getProp1().contains(check2));
168:
169:                // throw in some nulls into the request param to make sure they are
170:                // ignored
171:                application.getServletRequest().getParameterMap().put(
172:                        group.getInputName(),
173:                        new String[] { null,
174:                                String.valueOf(choice1.getValue()), null,
175:                                String.valueOf(choice2.getValue()) });
176:                form.onFormSubmitted();
177:                assertTrue(
178:                        "running with choice1 and choice2 selected - model must only contain values of check1 and check2",
179:                        modelObject.getProp1().size() == 2
180:                                && modelObject.getProp1().contains(check2)
181:                                && modelObject.getProp1().contains(check1));
182:
183:                application
184:                        .getServletRequest()
185:                        .getParameterMap()
186:                        .put(
187:                                group.getInputName(),
188:                                new String[] { "some weird choice uuid to test error" });
189:                try {
190:                    form.onFormSubmitted();
191:                    fail("running with an invalid choice value in the request param, should fail");
192:                } catch (WicketRuntimeException e) {
193:
194:                }
195:
196:            }
197:
198:            /**
199:             * test component rendering
200:             * 
201:             * @throws Exception
202:             */
203:            public void testRendering() throws Exception {
204:                executeTest(CheckGroupTestPage1.class,
205:                        "CheckGroupTestPage1_expected.html");
206:                executeTest(CheckGroupTestPage2.class,
207:                        "CheckGroupTestPage2_expected.html");
208:                executeTest(CheckGroupTestPage3.class,
209:                        "CheckGroupTestPage3_expected.html");
210:                executeTest(CheckGroupTestPage4.class,
211:                        "CheckGroupTestPage4_expected.html");
212:                try {
213:                    executeTest(CheckGroupTestPage5.class, "");
214:                    fail("this will always fail");
215:                } catch (WicketRuntimeException e) {
216:                    if (e
217:                            .getMessage()
218:                            .indexOf(
219:                                    "Check component [4:form:check2] cannot find its parent CheckGroup") < 0) {
220:                        fail("failed with wrong exception");
221:                    }
222:
223:                }
224:            }
225:
226:            /**
227:             * @throws Exception
228:             */
229:            public void testDisabledCheckGroup() throws Exception {
230:                executeTest(CheckGroupDisabledTestPage.class,
231:                        "CheckGroupDisabledTestPage_expected.html");
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.