Source Code Cross Referenced for GeneralConstraintContractTest.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » tests » constraints » 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.constraints 
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.constraints;
016:
017:        import junit.framework.TestCase;
018:        import org.apache.commons.lang.builder.EqualsBuilder;
019:        import org.araneaframework.mock.MockLifeCycle;
020:        import org.araneaframework.tests.mock.MockEnvironment;
021:        import org.araneaframework.uilib.form.FormElement;
022:        import org.araneaframework.uilib.form.FormWidget;
023:        import org.araneaframework.uilib.form.constraint.BaseFieldConstraint;
024:        import org.araneaframework.uilib.form.constraint.NotEmptyConstraint;
025:        import org.araneaframework.uilib.form.control.FloatControl;
026:        import org.araneaframework.uilib.form.data.BigDecimalData;
027:
028:        /**
029:         * Tests general {@link org.araneaframework.uilib.form.Constraint} behaviour.
030:         * @author Taimo Peelo (taimo@araneaframework.org)
031:         */
032:        public class GeneralConstraintContractTest extends TestCase {
033:            private FormWidget form;
034:
035:            public void setUp() throws Exception {
036:                form = new FormWidget();
037:                MockLifeCycle.begin(form, new MockEnvironment());
038:            }
039:
040:            /** Test that field constraints cannot be set on various other widgets. */
041:            public void testInvalidFieldConstraintSetting() throws Exception {
042:                try {
043:                    form.setConstraint(new NotEmptyConstraint());
044:                    form.validate();
045:
046:                    fail("Exception should have occured, because field constraint NotEmptyConstraint is not applicable to FormWidget");
047:                } catch (BaseFieldConstraint.FieldConstraintException e) {
048:                    // ok
049:                }
050:            }
051:
052:            /** Test that setting field constraint to null works and does not throw exception */
053:            public void testFieldNullConstraint() throws Exception {
054:                FormElement el = form.createElement("#number",
055:                        new FloatControl(), new BigDecimalData(), false);
056:                el.setConstraint(new NotEmptyConstraint());
057:                el.setConstraint(null);
058:                form.addElement("number", el);
059:
060:                assertTrue(
061:                        "Form is supposed to valid because constraint is not set.",
062:                        form.validate());
063:            }
064:
065:            /** Test that setting {@link FormWidget} constraint to null works and does not throw exception */
066:            public void testFormNullConstraint() throws Exception {
067:                form.addElement("number", "#number", new FloatControl(),
068:                        new BigDecimalData(), false);
069:                form.getElement("number").setConstraint(
070:                        new NotEmptyConstraint());
071:                form.getElement("number").setConstraint(null);
072:
073:                form.setConstraint(new NotEmptyConstraint((FormElement) form
074:                        .getElement("number")));
075:                form.setConstraint(null);
076:
077:                assertTrue(
078:                        "Form is supposed to valid because constraint is not set.",
079:                        form.validate());
080:            }
081:
082:            /** Test environment propagation. */
083:            public void testEnvironmentPropagation() throws Exception {
084:                // test propagation when both formwidget and formelement are inited when constraint is set
085:                // and constraint is set on a formelement
086:                form.addElement("number", "#number", new FloatControl(),
087:                        new BigDecimalData(), false);
088:                NotEmptyConstraint constraint = new NotEmptyConstraint();
089:                form.getElement("number").setConstraint(constraint);
090:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
091:                        "number").getConstraintEnvironment(), constraint
092:                        .getEnvironment()));
093:
094:                // test propagation when both formwidget and formelement are inited when constraint is set
095:                // and constraint is set on a formwidget
096:                form.getElement("number").setConstraint(null);
097:                constraint = new NotEmptyConstraint((FormElement) form
098:                        .getElement("number"));
099:                form.setConstraint(constraint);
100:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
101:                        "number").getConstraintEnvironment(), constraint
102:                        .getEnvironment()));
103:
104:                // test propagation when constraint is set on a formelement that is not yet
105:                // inited and is added to formwidget after setting the constraint
106:                form.removeElement("number");
107:                FormElement element = form.createElement("#number",
108:                        new FloatControl(), new BigDecimalData(), false);
109:                constraint = new NotEmptyConstraint();
110:                element.setConstraint(constraint);
111:                form.addElement("number", element);
112:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
113:                        "number").getConstraintEnvironment(), constraint
114:                        .getEnvironment()));
115:
116:                // test propagation when constraint is set on a formwidget while element is not yet inited
117:                // and is added to formwidget after setting the constraint
118:                form.removeElement("number");
119:                element = form.createElement("#number", new FloatControl(),
120:                        new BigDecimalData(), false);
121:                constraint = new NotEmptyConstraint(element);
122:                form.setConstraint(constraint);
123:                form.addElement("number", element);
124:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
125:                        "number").getConstraintEnvironment(), constraint
126:                        .getEnvironment()));
127:
128:                // test propagation when constraint is set on uninited formwidget while element is not yet inited
129:                // and is added to formwidget after setting the constraint
130:                form = new FormWidget();
131:                element = form.createElement("#number", new FloatControl(),
132:                        new BigDecimalData(), false);
133:                constraint = new NotEmptyConstraint(element);
134:                form.setConstraint(constraint);
135:                form.addElement("number", element);
136:                MockLifeCycle.begin(form, new MockEnvironment());
137:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
138:                        "number").getConstraintEnvironment(), constraint
139:                        .getEnvironment()));
140:
141:                // test propagation when constraint is set on uninited formelement belonging to uninited formwidget
142:                form = new FormWidget();
143:                element = form.createElement("#number", new FloatControl(),
144:                        new BigDecimalData(), false);
145:                constraint = new NotEmptyConstraint();
146:                element.setConstraint(constraint);
147:                form.addElement("number", element);
148:                MockLifeCycle.begin(form, new MockEnvironment());
149:                assertTrue(EqualsBuilder.reflectionEquals(form.getElement(
150:                        "number").getConstraintEnvironment(), constraint
151:                        .getEnvironment()));
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.