Source Code Cross Referenced for EntityManagerIntrospectorTest.java in  » Web-Framework » vraptor » org » vraptor » plugin » jpa » 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 » vraptor » org.vraptor.plugin.jpa 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.vraptor.plugin.jpa;
002:
003:        import java.lang.reflect.Field;
004:
005:        import org.vraptor.AbstractTest;
006:        import org.vraptor.component.ComponentType;
007:        import org.vraptor.component.DefaultLogicMethod;
008:
009:        /**
010:         * @author Fabio Correia Kung
011:         *
012:         */
013:        public class EntityManagerIntrospectorTest extends AbstractTest {
014:
015:            private EntityManagerIntrospector introspector;
016:
017:            private ComponentType wrongDependentType;
018:
019:            private ComponentType dependentType;
020:
021:            private ComponentType independentType;
022:
023:            private ComponentType constructorDependentType;
024:
025:            /*
026:             * (non-Javadoc)
027:             *
028:             * @see junit.framework.TestCase#setUp()
029:             */
030:            protected void setUp() throws Exception {
031:                super .setUp();
032:                this .introspector = new EntityManagerIntrospector();
033:                this .constructorDependentType = createComponentType(DependentByConstructor.class);
034:                this .dependentType = createComponentType(EntityManagerDependent.class);
035:                this .wrongDependentType = createComponentType(EntityManagerWrongDependent.class);
036:                this .independentType = createComponentType(EntityManagerIndependent.class);
037:
038:            }
039:
040:            /**
041:             * Test method for
042:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#getEntityManagerField(org.vraptor.component.ComponentType)}.
043:             */
044:            public void testGetEntityManagerFieldForDependentComponent()
045:                    throws Exception {
046:                Field expectedField = EntityManagerDependent.class
047:                        .getDeclaredField("entityManager");
048:                Field field = this .introspector
049:                        .getEntityManagerField(dependentType);
050:                assertEquals("Same field", expectedField, field);
051:            }
052:
053:            /**
054:             * Test method for
055:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#getEntityManagerField(org.vraptor.component.ComponentType)}.
056:             */
057:            public void testGetEntityManagerShouldGiveNullForIndependentComponent()
058:                    throws Exception {
059:                Field field = this .introspector
060:                        .getEntityManagerField(independentType);
061:                assertNull("hasn't the field", field);
062:            }
063:
064:            /**
065:             * Test method for
066:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#getEntityManagerField(org.vraptor.component.ComponentType)}.
067:             */
068:            public void testGetEntityManagerShouldGiveNullForMissingPersistenceContextAnnotation()
069:                    throws Exception {
070:                Field field = this .introspector
071:                        .getEntityManagerField(wrongDependentType);
072:                assertNull("mising @PersistenceContext", field);
073:            }
074:
075:            /**
076:             * Test method for
077:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#dependsOnEntityManager(org.vraptor.component.ComponentType)}.
078:             */
079:            public void testPersistenceContextAnnotatedFieldIsNotConstructorDependency() {
080:                boolean depends = this .introspector
081:                        .dependsOnEntityManager(dependentType);
082:                assertFalse(depends);
083:            }
084:
085:            /**
086:             * Test method for
087:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#dependsOnEntityManager(org.vraptor.component.ComponentType)}.
088:             */
089:            public void testIndependentComponentHasNotConstructorDependency() {
090:                boolean depends = this .introspector
091:                        .dependsOnEntityManager(independentType);
092:                assertFalse(depends);
093:            }
094:
095:            /**
096:             * Test method for
097:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#dependsOnEntityManager(org.vraptor.component.ComponentType)}.
098:             */
099:            public void testWrongDependentComponentHasNotConstructorDependency() {
100:                boolean depends = this .introspector
101:                        .dependsOnEntityManager(wrongDependentType);
102:                assertFalse(depends);
103:            }
104:
105:            /**
106:             * Test method for
107:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#dependsOnEntityManager(org.vraptor.component.ComponentType)}.
108:             */
109:            public void testComponentThatDependsOnEntityManagerByConstructor() {
110:                boolean depends = this .introspector
111:                        .dependsOnEntityManager(constructorDependentType);
112:                assertTrue(depends);
113:            }
114:
115:            /**
116:             * Test method for
117:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#hasPersistenceContext(org.vraptor.component.ComponentType)}.
118:             */
119:            public void testEntityManagerDependentComponentHasPersistenceContext() {
120:                assertTrue(this .introspector
121:                        .hasPersistenceContext(dependentType));
122:            }
123:
124:            /**
125:             * Test method for
126:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#hasPersistenceContext(org.vraptor.component.ComponentType)}.
127:             */
128:            public void testEntityManagerIndependentComponentHasNotPersistenceContext() {
129:                assertFalse(this .introspector
130:                        .hasPersistenceContext(independentType));
131:            }
132:
133:            /**
134:             * Test method for
135:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#hasPersistenceContext(org.vraptor.component.ComponentType)}.
136:             */
137:            public void testMissingPersistenceContextAnnotationComponentHasNotPersistenceContext() {
138:                assertFalse(this .introspector
139:                        .hasPersistenceContext(wrongDependentType));
140:            }
141:
142:            /**
143:             * Test method for
144:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#hasPersistenceContext(org.vraptor.component.ComponentType)}.
145:             */
146:            public void testDependentByConstructorComponentHasNotPersistenceContext() {
147:                assertFalse(this .introspector
148:                        .hasPersistenceContext(constructorDependentType));
149:            }
150:
151:            /**
152:             * Test method for
153:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#getPersistenceUnitName(org.vraptor.component.ComponentType)}.
154:             *
155:             * @throws Exception
156:             */
157:            public void testGetPersistenceUnitName() throws Exception {
158:                assertEquals("default",
159:                        EntityManagerIntrospector.DEFAULT_PERSISTENCE_UNIT);
160:
161:                String nameForDependent = this .introspector
162:                        .getPersistenceUnitName(dependentType);
163:                assertEquals("default name",
164:                        EntityManagerIntrospector.DEFAULT_PERSISTENCE_UNIT,
165:                        nameForDependent);
166:
167:                String nameForIndependent = this .introspector
168:                        .getPersistenceUnitName(independentType);
169:                assertEquals("default name",
170:                        EntityManagerIntrospector.DEFAULT_PERSISTENCE_UNIT,
171:                        nameForIndependent);
172:
173:                String nameWithoutAnnotation = this .introspector
174:                        .getPersistenceUnitName(wrongDependentType);
175:                assertEquals("default name",
176:                        EntityManagerIntrospector.DEFAULT_PERSISTENCE_UNIT,
177:                        nameWithoutAnnotation);
178:
179:                String customName = this .introspector
180:                        .getPersistenceUnitName(createComponentType(CustomUnitName.class));
181:                assertEquals("customized name", "otherName", customName);
182:            }
183:
184:            /**
185:             * Test method for
186:             * {@link org.vraptor.plugin.jpa.EntityManagerIntrospector#isTransactionRequired(org.vraptor.component.LogicMethod)}.
187:             *
188:             * @throws Exception
189:             */
190:            public void testIsTransactionRequired() throws Exception {
191:                DefaultLogicMethod requiresTransactionLogic = createLogicMethod(
192:                        WithTransaction.class, "logic");
193:                DefaultLogicMethod missingRequiredAttributeLogic = createLogicMethod(
194:                        WithoutTransaction.class, "logic");
195:                DefaultLogicMethod notAnnotatedLogic = createLogicMethod(
196:                        EntityManagerDependent.class, "logic");
197:
198:                assertTrue(this .introspector
199:                        .isTransactionRequired(requiresTransactionLogic));
200:                assertFalse(
201:                        "default value for required is false",
202:                        this .introspector
203:                                .isTransactionRequired(missingRequiredAttributeLogic));
204:                assertFalse("default behavior is no transaction",
205:                        this.introspector
206:                                .isTransactionRequired(notAnnotatedLogic));
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.