Source Code Cross Referenced for JPAAnnotationsConfigurerTest.java in  » Development » OVal » net » sf » oval » test » validator » 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 » Development » OVal » net.sf.oval.test.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
003:         * Thomschke.
004:         * 
005:         * All Rights Reserved. This program and the accompanying materials
006:         * are made available under the terms of the Eclipse Public License v1.0
007:         * which accompanies this distribution, and is available at
008:         * http://www.eclipse.org/legal/epl-v10.html
009:         * 
010:         * Contributors:
011:         *     Sebastian Thomschke - initial implementation.
012:         *******************************************************************************/package net.sf.oval.test.validator;
013:
014:        import java.util.ArrayList;
015:        import java.util.Collection;
016:        import java.util.List;
017:
018:        import javax.persistence.Basic;
019:        import javax.persistence.Column;
020:        import javax.persistence.Entity;
021:        import javax.persistence.ManyToOne;
022:        import javax.persistence.OneToMany;
023:        import javax.persistence.OneToOne;
024:
025:        import junit.framework.TestCase;
026:        import net.sf.oval.ConstraintViolation;
027:        import net.sf.oval.Validator;
028:        import net.sf.oval.configuration.annotation.JPAAnnotationsConfigurer;
029:
030:        /**
031:         * @author Sebastian Thomschke
032:         *
033:         */
034:        public class JPAAnnotationsConfigurerTest extends TestCase {
035:            @Entity
036:            protected static class TestEntity {
037:                // -> @NotNull
038:                @Basic(optional=false)
039:                // -> @MaxLength(4)
040:                @Column(length=4)
041:                public String code;
042:
043:                // -> @NotNull
044:                @Column(nullable=false)
045:                public String description;
046:
047:                // -> @NotNull & @AssertValid
048:                @ManyToOne(optional=false)
049:                public TestEntity ref1;
050:
051:                // -> @AssertValid
052:                @OneToOne(optional=true)
053:                public TestEntity ref2;
054:
055:                // -> @AssertValid
056:                @OneToMany
057:                public Collection<TestEntity> refs;
058:            }
059:
060:            public void testJPAAnnotationsConfigurer() {
061:                Validator v = new Validator(new JPAAnnotationsConfigurer());
062:                List<ConstraintViolation> violations;
063:
064:                TestEntity entity;
065:
066:                {
067:                    entity = new TestEntity();
068:
069:                    violations = v.validate(entity);
070:                    // code is null
071:                    // description is null
072:                    // ref1 is null
073:                    assertEquals(3, violations.size());
074:                    assertNull(violations.get(0).getInvalidValue());
075:                    assertNull(violations.get(1).getInvalidValue());
076:                    assertNull(violations.get(2).getInvalidValue());
077:                }
078:
079:                {
080:                    entity.code = "";
081:                    entity.description = "";
082:                    entity.ref1 = new TestEntity();
083:
084:                    violations = v.validate(entity);
085:                    // ref1 is invalid
086:                    assertEquals(1, violations.size());
087:                }
088:
089:                {
090:                    entity.ref1.code = "";
091:                    entity.ref1.description = "";
092:                    entity.ref1.ref1 = entity;
093:
094:                    violations = v.validate(entity);
095:                    assertEquals(0, violations.size());
096:                }
097:
098:                {
099:                    entity.ref2 = new TestEntity();
100:
101:                    violations = v.validate(entity);
102:                    // ref2 is invalid
103:                    assertEquals(1, violations.size());
104:                }
105:
106:                {
107:                    entity.ref2.code = "";
108:                    entity.ref2.description = "";
109:                    entity.ref2.ref1 = entity;
110:
111:                    violations = v.validate(entity);
112:                    assertEquals(0, violations.size());
113:                }
114:
115:                // Column length test
116:                {
117:                    entity.code = "12345";
118:                    violations = v.validate(entity);
119:                    // code is too long
120:                    assertEquals(1, violations.size());
121:
122:                    entity.code = "";
123:                }
124:
125:                // OneToMany test
126:                {
127:                    entity.refs = new ArrayList<TestEntity>();
128:                    TestEntity d = new TestEntity();
129:                    entity.refs.add(d);
130:
131:                    violations = v.validate(entity);
132:                    assertEquals(1, violations.size());
133:
134:                    d.code = "";
135:                    d.description = "";
136:                    d.ref1 = entity;
137:
138:                    violations = v.validate(entity);
139:                    assertEquals(0, violations.size());
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.