Source Code Cross Referenced for StatefulInterceptorTests.java in  » J2EE » openejb3 » org » apache » openejb » test » stateful » 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 » openejb3 » org.apache.openejb.test.stateful 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.openejb.test.stateful;
017:
018:        import java.util.ArrayList;
019:        import java.util.Map;
020:
021:        // import javax.ejb.EJB;
022:
023:        /**
024:         * 
025:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
026:         * @author <a href="mailto:goyathlay.geronimo@gmail.com">Prasad Kashyap</a>
027:         */
028:        // public class StatefulInterceptorTests extends AnnotatedFieldInjectionStatefulLocalTestClient {
029:        public class StatefulInterceptorTests extends
030:                BasicStatefulLocalTestClient {
031:
032:            /*
033:             * @EJB(name="BasicStatefulInterceptedBusinessRemote", beanInterface = BasicStatefulInterceptedRemote.class)
034:             */
035:            private BasicStatefulInterceptedRemote remoteInterceptor;
036:
037:            public StatefulInterceptorTests() {
038:                super ("BasicStatefulIntercepted.");
039:            }
040:
041:            protected void setUp() throws Exception {
042:                super .setUp();
043:                Object obj = initialContext
044:                        .lookup("BasicStatefulInterceptedBusinessRemote");
045:                assertNotNull("The object is null", obj);
046:                remoteInterceptor = (BasicStatefulInterceptedRemote) javax.rmi.PortableRemoteObject
047:                        .narrow(obj, BasicStatefulInterceptedRemote.class);
048:                assertNotNull("Remote interceptor is null", remoteInterceptor);
049:            }
050:
051:            /**
052:             * Tears down the fixture, for example, close a network connection. This method is called after a test is executed.
053:             */
054:            protected void tearDown() throws Exception {
055:                super .tearDown();
056:            }
057:
058:            /**
059:             * Invokes a business method which is to be intercepted by class, in-bean and at method level.
060:             */
061:            public void test01_interceptorChaining() {
062:                String reverseMe = "Intercept";
063:                String reversedString = remoteInterceptor.reverse(reverseMe);
064:                // verifying InvocationContext.procced()
065:                assertEquals("tpecretnI", reversedString);
066:
067:                Map contextData = remoteInterceptor.getContextData();
068:                // verifying that inBeanInterceptor indeed intercepted this method. This cannot be excluded at all.
069:                assertNotNull(contextData.containsKey("reverse"));
070:
071:                Map innerMap = (Map) contextData.get("reverse");
072:                ArrayList interceptorsList = (ArrayList) innerMap
073:                        .get("INTERCEPTORS");
074:                // verifying interceptor chaining order
075:                assertEquals("superClassInterceptor", interceptorsList.get(0)); //derived from class extension
076:                assertEquals("classInterceptor", interceptorsList.get(1)); //specified by @
077:                assertEquals("secondClassInterceptor", interceptorsList.get(2)); //specified by @
078:                assertEquals("methodInterceptor", interceptorsList.get(3)); //specified by @ on method
079:                assertEquals("ddInterceptor", interceptorsList.get(4)); //specified in DD on method
080:                assertEquals("superBeanInterceptor", interceptorsList.get(5)); //derived from bean extension
081:                assertEquals("inBeanInterceptor", interceptorsList.get(6)); //in bean
082:            }
083:
084:            /**
085:             * Invokes just 1 business method on the bean. The interceptor method stores the intercepted method's name and
086:             * params in a map that is returned by the <code>getContextData</code>
087:             */
088:            public void test02_methodProfile() {
089:                String reverseMe = "Intercept";
090:                String reversedString = remoteInterceptor.reverse(reverseMe);
091:                // verifying InvocationContext.procced()
092:                assertEquals("tpecretnI", reversedString);
093:
094:                Map contextData = remoteInterceptor.getContextData();
095:                // verifying InvocationContext.getMethod().getName()
096:                assertTrue(contextData.containsKey("reverse"));
097:
098:                Map innerMap = (Map) contextData.get("reverse");
099:                Object[] params = (Object[]) innerMap.get("PARAMETERS");
100:                // verifying that the parameters array was received from contextData and stored.
101:                assertNotNull("value of PARAMETERS key is null", params);
102:                // verifying InvocationContext.getParameters()
103:                assertEquals(1, params.length);
104:                assertEquals(reverseMe, params[0].toString());
105:            }
106:
107:            /**
108:             * Invokes a business method which is annotated to be excluded from interception.
109:             * <code>getContextData()</code> has been annotated with <code>@ExcludesClassInterceptors</code>
110:             */
111:            public void test03_excludeClassInterceptors() {
112:                Map contextData = remoteInterceptor.getContextData();
113:                // verifying that inBeanInterceptor indeed intercepted this method. This cannot be excluded at all.
114:                assertNotNull(contextData.containsKey("getContextData"));
115:
116:                Map innerMap = (Map) contextData.get("getContextData");
117:                ArrayList interceptorsList = (ArrayList) innerMap
118:                        .get("INTERCEPTORS");
119:                // verifying @ExcludeClassInterceptors annotated method was not intercepted by class interceptors
120:                assertFalse(
121:                        "getContextData() should not have been intercepted by superClassInterceptor()",
122:                        interceptorsList.contains("superClassInterceptor"));
123:                assertFalse(
124:                        "getContextData() should not have been intercepted by classInterceptor()",
125:                        interceptorsList.contains("classInterceptor"));
126:                assertFalse(
127:                        "getContextData() should not have been intercepted by secondClassInterceptor()",
128:                        interceptorsList.contains("secondClassInterceptor"));
129:                assertFalse(
130:                        "getContextData() should not have been intercepted by ddInterceptor()",
131:                        interceptorsList.contains("ddInterceptor"));
132:            }
133:
134:            /**
135:             * Invokes a business method which is declared to be excluded from interception by the DD
136:             * <code>getContextData()</code> has been annotated with <code>@ExcludesClassInterceptors</code>
137:             */
138:            public void test04_excludeClassInterceptors_02() {
139:                String catString = remoteInterceptor.concat("Inter", "cept");
140:                // verifying InvocationContext.procced()
141:                assertEquals("Intercept", catString);
142:
143:                Map contextData = remoteInterceptor.getContextData();
144:                // verifying that inBeanInterceptor indeed intercepted this method. This cannot be excluded at all.
145:                assertNotNull(contextData.containsKey("concat"));
146:
147:                Map innerMap = (Map) contextData.get("concat");
148:                ArrayList interceptorsList = (ArrayList) innerMap
149:                        .get("INTERCEPTORS");
150:                // verifying @ExcludeClassInterceptors annotated method was not intercepted
151:                assertFalse(
152:                        "concat() should not have been intercepted by superClassInterceptor()",
153:                        interceptorsList.contains("superClassInterceptor"));
154:                assertFalse(
155:                        "concat() should not have been intercepted by classInterceptor()",
156:                        interceptorsList.contains("classInterceptor"));
157:                assertFalse(
158:                        "concat() should not have been intercepted by ddInterceptor()",
159:                        interceptorsList.contains("ddInterceptor"));
160:                assertFalse(
161:                        "concat() should not have been intercepted by secondClassInterceptor()",
162:                        interceptorsList.contains("secondClassInterceptor"));
163:            }
164:
165:            /**
166:             * Invokes a business method which is annotated to be excluded from interception.
167:             * <code>getContextData()</code> has been annotated with <code>@ExcludesClassInterceptors</code>
168:             */
169:            public void test05_PreDestroy() {
170:                try {
171:                    tearDown();
172:                    Map contextData = remoteInterceptor.getContextData();
173:                    Map innerMap = (Map) contextData
174:                            .get("BasicStatefulInterceptedBean");
175:                    assertNotNull("InnerMap is null", innerMap);
176:                    ArrayList interceptorsList = (ArrayList) innerMap
177:                            .get("INTERCEPTORS");
178:                    // verifying interceptor chaining order
179:                    assertEquals("superClassInterceptorPreDestroy",
180:                            interceptorsList.get(0));
181:                } catch (Exception e) {
182:                    // TODO Auto-generated catch block
183:                    e.printStackTrace();
184:                }
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.