Source Code Cross Referenced for MdbConfigTest.java in  » J2EE » openejb3 » org » apache » openejb » assembler » classic » 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.assembler.classic 
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.assembler.classic;
018:
019:        import junit.framework.TestCase;
020:        import org.apache.openejb.config.ConfigurationFactory;
021:        import org.apache.openejb.config.EjbModule;
022:        import org.apache.openejb.jee.ActivationConfig;
023:        import org.apache.openejb.jee.ActivationConfigProperty;
024:        import org.apache.openejb.jee.EjbJar;
025:        import org.apache.openejb.jee.MessageDrivenBean;
026:        import org.apache.openejb.test.mdb.BasicMdbBean;
027:
028:        import javax.jms.MessageListener;
029:        import javax.resource.spi.ResourceAdapter;
030:        import javax.resource.spi.BootstrapContext;
031:        import javax.resource.spi.ResourceAdapterInternalException;
032:        import javax.resource.spi.ActivationSpec;
033:        import javax.resource.spi.UnavailableException;
034:        import javax.resource.spi.InvalidPropertyException;
035:        import javax.resource.spi.endpoint.MessageEndpointFactory;
036:        import javax.resource.spi.endpoint.MessageEndpoint;
037:        import javax.resource.ResourceException;
038:        import javax.transaction.xa.XAResource;
039:        import java.util.Properties;
040:
041:        /**
042:         * @version $Rev: 610927 $ $Date: 2008-01-10 12:48:37 -0800 $
043:         */
044:        public class MdbConfigTest extends TestCase {
045:            public void test() throws Exception {
046:                ConfigurationFactory config = new ConfigurationFactory();
047:                Assembler assembler = new Assembler();
048:
049:                // System services
050:                assembler.createProxyFactory(config
051:                        .configureService(ProxyFactoryInfo.class));
052:                assembler.createTransactionManager(config
053:                        .configureService(TransactionServiceInfo.class));
054:                assembler.createSecurityService(config
055:                        .configureService(SecurityServiceInfo.class));
056:
057:                // JMS persistence datasource
058:                ResourceInfo dataSourceInfo = config.configureService(
059:                        "Default Unmanaged JDBC Database", ResourceInfo.class);
060:                dataSourceInfo.properties.setProperty("JdbcUrl",
061:                        "jdbc:hsqldb:mem:MdbConfigTest");
062:                assembler.createResource(dataSourceInfo);
063:
064:                // JMS
065:                assembler.createResource(config.configureService(
066:                        "Default JMS Resource Adapter", ResourceInfo.class));
067:
068:                // JMS Container
069:                MdbContainerInfo mdbContainerInfo = config
070:                        .configureService(MdbContainerInfo.class);
071:                assembler.createContainer(mdbContainerInfo);
072:
073:                // FakeRA
074:                ResourceInfo resourceInfo = new ResourceInfo();
075:                resourceInfo.service = "Resource";
076:                resourceInfo.className = FakeRA.class.getName();
077:                resourceInfo.id = "FakeRA";
078:                resourceInfo.properties = new Properties();
079:                assembler.createResource(resourceInfo);
080:
081:                // FakeRA container
082:                ContainerInfo containerInfo = config
083:                        .configureService(MdbContainerInfo.class);
084:                containerInfo.id = "FakeContainer";
085:                containerInfo.displayName = "Fake Container";
086:                containerInfo.properties.setProperty("ResourceAdapter",
087:                        "FakeRA");
088:                containerInfo.properties.setProperty(
089:                        "MessageListenerInterface", FakeMessageListener.class
090:                                .getName());
091:                containerInfo.properties.setProperty("ActivationSpecClass",
092:                        FakeActivationSpec.class.getName());
093:                assembler.createContainer(containerInfo);
094:
095:                // generate ejb jar application
096:                EjbJar ejbJar = new EjbJar();
097:                ejbJar.addEnterpriseBean(createJaxbMdb("JmsMdb",
098:                        BasicMdbBean.class.getName(), MessageListener.class
099:                                .getName()));
100:                ejbJar.addEnterpriseBean(createJaxbMdb("FakeMdb", FakeMdb.class
101:                        .getName(), FakeMessageListener.class.getName()));
102:                EjbModule ejbModule = new EjbModule(
103:                        getClass().getClassLoader(), "FakeEjbJar", "fake.jar",
104:                        ejbJar, null);
105:
106:                // configure and deploy it
107:                EjbJarInfo info = config.configureApplication(ejbModule);
108:                assembler.createEjbJar(info);
109:            }
110:
111:            public static class FakeMdb implements  FakeMessageListener {
112:                public void doIt(Properties properties) {
113:                }
114:            }
115:
116:            public static interface FakeMessageListener {
117:                public void doIt(Properties properties);
118:            }
119:
120:            public static class FakeRA implements  ResourceAdapter {
121:                public boolean started;
122:
123:                public void start(BootstrapContext bootstrapContext)
124:                        throws ResourceAdapterInternalException {
125:                    assertFalse("Already started", started);
126:                    assertNotNull("bootstrapContext is null", bootstrapContext);
127:                    assertNotNull("bootstrapContext.getWorkManager() is null",
128:                            bootstrapContext.getWorkManager());
129:                    assertNotNull("bootstrapContext.getXATerminator() is null",
130:                            bootstrapContext.getXATerminator());
131:                    try {
132:                        assertNotNull("bootstrapContext.createTimer() is null",
133:                                bootstrapContext.createTimer());
134:                    } catch (UnavailableException e) {
135:                        throw new ResourceAdapterInternalException(
136:                                "bootstrapContext.createTimer() threw an exception",
137:                                e);
138:                    }
139:                }
140:
141:                public void stop() {
142:                    assertTrue("RA was not started", started);
143:                }
144:
145:                public void endpointActivation(
146:                        MessageEndpointFactory messageEndpointFactory,
147:                        ActivationSpec activationSpec) throws ResourceException {
148:                    assertNotNull("messageEndpointFactory is null",
149:                            messageEndpointFactory);
150:                    assertNotNull("activationSpec is null", activationSpec);
151:                    assertTrue(
152:                            "activationSpec should be an instance of FakeActivationSpec",
153:                            activationSpec instanceof  FakeActivationSpec);
154:
155:                    MessageEndpoint endpoint = messageEndpointFactory
156:                            .createEndpoint(null);
157:                    assertNotNull("endpoint is null", endpoint);
158:                    assertTrue(
159:                            "endpoint should be an instance of FakeMessageListener",
160:                            endpoint instanceof  FakeMessageListener);
161:                }
162:
163:                public void endpointDeactivation(
164:                        MessageEndpointFactory messageEndpointFactory,
165:                        ActivationSpec activationSpec) {
166:                    assertNotNull("messageEndpointFactory is null",
167:                            messageEndpointFactory);
168:                    assertNotNull("activationSpec is null", activationSpec);
169:                    assertTrue(
170:                            "activationSpec should be an instance of FakeActivationSpec",
171:                            activationSpec instanceof  FakeActivationSpec);
172:                }
173:
174:                public XAResource[] getXAResources(
175:                        ActivationSpec[] activationSpecs)
176:                        throws ResourceException {
177:                    return new XAResource[0];
178:                }
179:            }
180:
181:            public static class FakeActivationSpec implements  ActivationSpec {
182:                private FakeRA fakeRA;
183:                protected boolean validated;
184:
185:                public void validate() throws InvalidPropertyException {
186:                    validated = true;
187:                }
188:
189:                public FakeRA getResourceAdapter() {
190:                    return fakeRA;
191:                }
192:
193:                public void setResourceAdapter(ResourceAdapter resourceAdapter) {
194:                    assertNotNull("resourceAdapter is null", resourceAdapter);
195:                    assertTrue(
196:                            "resourceAdapter should be an instance of FakeRA",
197:                            resourceAdapter instanceof  FakeRA);
198:                    this .fakeRA = (FakeRA) resourceAdapter;
199:                    assertTrue("ActivationSpec has not been validated",
200:                            validated);
201:                }
202:            }
203:
204:            private MessageDrivenBean createJaxbMdb(String ejbName,
205:                    String mdbClass, String messageListenerInterface) {
206:                MessageDrivenBean bean = new MessageDrivenBean(ejbName);
207:                bean.setEjbClass(mdbClass);
208:                bean.setMessagingType(messageListenerInterface);
209:
210:                ActivationConfig activationConfig = new ActivationConfig();
211:                activationConfig.getActivationConfigProperty().add(
212:                        new ActivationConfigProperty("destination", ejbName));
213:                activationConfig.getActivationConfigProperty().add(
214:                        new ActivationConfigProperty("destinationType",
215:                                "javax.jms.Queue"));
216:                bean.setActivationConfig(activationConfig);
217:
218:                return bean;
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.