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


001:        /**
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of 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,
014:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */package org.apache.openejb.core.stateful;
018:
019:        import junit.framework.TestCase;
020:        import org.apache.openejb.assembler.classic.Assembler;
021:        import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
022:        import org.apache.openejb.assembler.classic.SecurityServiceInfo;
023:        import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
024:        import org.apache.openejb.assembler.classic.TransactionServiceInfo;
025:        import org.apache.openejb.config.ConfigurationFactory;
026:        import org.apache.openejb.core.ivm.naming.InitContextFactory;
027:        import org.apache.openejb.jee.EjbJar;
028:        import org.apache.openejb.jee.StatefulBean;
029:
030:        import javax.annotation.PostConstruct;
031:        import javax.annotation.PreDestroy;
032:        import javax.annotation.Resource;
033:        import javax.ejb.Local;
034:        import javax.ejb.PostActivate;
035:        import javax.ejb.PrePassivate;
036:        import javax.ejb.Remote;
037:        import javax.ejb.Remove;
038:        import javax.ejb.SessionContext;
039:        import javax.naming.InitialContext;
040:        import java.io.Serializable;
041:        import java.util.Arrays;
042:        import java.util.List;
043:        import java.util.Stack;
044:        import java.util.ArrayList;
045:
046:        /**
047:         * @version $Revision: 632525 $ $Date: 2008-02-29 17:16:47 -0800 $
048:         */
049:        public class StatefulContainerTest extends TestCase {
050:
051:            public void testBusinessLocalInterface() throws Exception {
052:
053:                // Do a create...
054:
055:                InitialContext ctx = new InitialContext();
056:                Object object = ctx.lookup("WidgetBeanLocal");
057:
058:                assertTrue("instanceof widget", object instanceof  Widget);
059:
060:                Widget widget = (Widget) object;
061:
062:                // Do a business method...
063:                Stack<Lifecycle> lifecycle = widget.getLifecycle();
064:                assertNotNull("lifecycle", lifecycle);
065:
066:                // Do a remove...
067:                widget.destroy();
068:
069:                // Check the lifecycle of the bean
070:                List expected = Arrays.asList(StatefulContainerTest.Lifecycle
071:                        .values());
072:
073:                assertEquals(StatefulContainerTest.join("\n", expected), join(
074:                        "\n", WidgetBean.lifecycle));
075:            }
076:
077:            public void testBusinessRemoteInterface() throws Exception {
078:                WidgetBean.lifecycle.clear();
079:
080:                // Do a create...
081:
082:                InitialContext ctx = new InitialContext();
083:                Object object = ctx.lookup("WidgetBeanRemote");
084:
085:                assertTrue("instanceof widget", object instanceof  RemoteWidget);
086:
087:                RemoteWidget widget = (RemoteWidget) object;
088:
089:                // Do a business method...
090:                Stack<Lifecycle> lifecycle = widget.getLifecycle();
091:                assertNotNull("lifecycle", lifecycle);
092:                assertNotSame("is copy", lifecycle, WidgetBean.lifecycle);
093:
094:                // Do a remove...
095:                widget.destroy();
096:
097:                try {
098:                    widget.destroy();
099:                    fail("Calling a removed bean should not be possible");
100:                } catch (Exception e) {
101:                }
102:
103:                // Check the lifecycle of the bean
104:                List expected = Arrays.asList(StatefulContainerTest.Lifecycle
105:                        .values());
106:
107:                assertEquals(StatefulContainerTest.join("\n", expected), join(
108:                        "\n", WidgetBean.lifecycle));
109:            }
110:
111:            protected void setUp() throws Exception {
112:                super .setUp();
113:
114:                System.setProperty(
115:                        javax.naming.Context.INITIAL_CONTEXT_FACTORY,
116:                        InitContextFactory.class.getName());
117:
118:                ConfigurationFactory config = new ConfigurationFactory();
119:                Assembler assembler = new Assembler();
120:
121:                assembler.createProxyFactory(config
122:                        .configureService(ProxyFactoryInfo.class));
123:                assembler.createTransactionManager(config
124:                        .configureService(TransactionServiceInfo.class));
125:                assembler.createSecurityService(config
126:                        .configureService(SecurityServiceInfo.class));
127:
128:                // containers
129:                StatefulSessionContainerInfo statefulContainerInfo = config
130:                        .configureService(StatefulSessionContainerInfo.class);
131:                statefulContainerInfo.properties.setProperty("PoolSize", "0");
132:                statefulContainerInfo.properties.setProperty("BulkPassivate",
133:                        "1");
134:                assembler.createContainer(statefulContainerInfo);
135:
136:                // Setup the descriptor information
137:
138:                EjbJar ejbJar = new EjbJar();
139:                ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class));
140:
141:                assembler
142:                        .createApplication(config.configureApplication(ejbJar));
143:
144:                WidgetBean.lifecycle.clear();
145:
146:            }
147:
148:            private static String join(String delimeter, List items) {
149:                StringBuffer sb = new StringBuffer();
150:                for (Object item : items) {
151:                    sb.append(item.toString()).append(delimeter);
152:                }
153:                return sb.toString();
154:            }
155:
156:            @Local
157:            public static interface Widget {
158:                Stack<Lifecycle> getLifecycle();
159:
160:                void destroy();
161:            }
162:
163:            @Remote
164:            public static interface RemoteWidget extends Widget {
165:
166:            }
167:
168:            public static enum Lifecycle {
169:                CONSTRUCTOR, INJECTION, POST_CONSTRUCT, PRE_PASSIVATE1, POST_ACTIVATE1, BUSINESS_METHOD, PRE_PASSIVATE2, POST_ACTIVATE2, REMOVE, PRE_DESTROY,
170:            }
171:
172:            public static class WidgetBean implements  Widget, RemoteWidget {
173:                private static final long serialVersionUID = -8499745487520955081L;
174:
175:                private int activates = 0;
176:                private int passivates = 0;
177:
178:                public static Stack<Lifecycle> lifecycle = new Stack<Lifecycle>();
179:
180:                public WidgetBean() {
181:                    lifecycle.push(Lifecycle.CONSTRUCTOR);
182:                }
183:
184:                @Resource
185:                public void setContext(SessionContext context) {
186:                    lifecycle.push(Lifecycle.INJECTION);
187:                }
188:
189:                public Stack<Lifecycle> getLifecycle() {
190:                    lifecycle.push(Lifecycle.BUSINESS_METHOD);
191:                    return lifecycle;
192:                }
193:
194:                @PostActivate
195:                public void activate() {
196:                    lifecycle.push(Enum.valueOf(Lifecycle.class,
197:                            "POST_ACTIVATE" + (++activates)));
198:                }
199:
200:                @PrePassivate
201:                public void passivate() {
202:                    lifecycle.push(Enum.valueOf(Lifecycle.class,
203:                            "PRE_PASSIVATE" + (++passivates)));
204:                }
205:
206:                @PostConstruct
207:                public void init() {
208:                    lifecycle.push(Lifecycle.POST_CONSTRUCT);
209:                }
210:
211:                @PreDestroy
212:                public void predestroy() {
213:                    lifecycle.push(Lifecycle.PRE_DESTROY);
214:                }
215:
216:                @Remove
217:                public void destroy() {
218:                    lifecycle.push(Lifecycle.REMOVE);
219:                }
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.