Source Code Cross Referenced for EjbJarXmlTestCase.java in  » EJB-Server-JBoss-4.2.1 » ejb3 » org » jboss » ejb3 » test » dd » unit » 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 » EJB Server JBoss 4.2.1 » ejb3 » org.jboss.ejb3.test.dd.unit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.ejb3.test.dd.unit;
023:
024:        import java.net.URL;
025:        import java.util.Collection;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import org.jboss.ejb3.metamodel.AssemblyDescriptor;
029:        import org.jboss.ejb3.metamodel.CmrField;
030:        import org.jboss.ejb3.metamodel.ContainerTransaction;
031:        import org.jboss.ejb3.metamodel.EjbJarDD;
032:        import org.jboss.ejb3.metamodel.EjbJarDDObjectFactory;
033:        import org.jboss.ejb3.metamodel.EjbRelation;
034:        import org.jboss.ejb3.metamodel.EjbRelationshipRole;
035:        import org.jboss.ejb3.metamodel.EnterpriseBean;
036:        import org.jboss.ejb3.metamodel.EnterpriseBeans;
037:        import org.jboss.ejb3.metamodel.EntityEnterpriseBean;
038:        import org.jboss.ejb3.metamodel.JBossDDObjectFactory;
039:        import org.jboss.ejb3.metamodel.MessageDrivenBean;
040:        import org.jboss.ejb3.metamodel.MessageDrivenDestination;
041:        import org.jboss.ejb3.metamodel.Method;
042:        import org.jboss.ejb3.metamodel.MethodPermission;
043:        import org.jboss.ejb3.metamodel.RelationshipRoleSource;
044:        import org.jboss.ejb3.metamodel.Relationships;
045:        import org.jboss.ejb3.metamodel.SecurityIdentity;
046:        import org.jboss.ejb3.metamodel.Service;
047:        import org.jboss.ejb3.metamodel.SessionEnterpriseBean;
048:        import org.jboss.logging.Logger;
049:        import org.jboss.xb.binding.ObjectModelFactory;
050:        import org.jboss.xb.binding.Unmarshaller;
051:        import org.jboss.xb.binding.UnmarshallerFactory;
052:        import junit.framework.Test;
053:        import junit.framework.TestCase;
054:        import junit.framework.TestSuite;
055:
056:        import org.jboss.metamodel.descriptor.EjbLocalRef;
057:        import org.jboss.metamodel.descriptor.NameValuePair;
058:        import org.jboss.metamodel.descriptor.ResourceRef;
059:        import org.jboss.metamodel.descriptor.SecurityRole;
060:
061:        /**
062:         * JUnit TestCase for JbossXB usage for ejb-jar.xml deployment descriptor for
063:         * version 1.4 schema
064:         * 
065:         * @version <tt>$Revision: 57207 $</tt>
066:         * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
067:         */
068:
069:        public class EjbJarXmlTestCase extends TestCase {
070:
071:            private static final Logger log = Logger
072:                    .getLogger(EjbJarXmlTestCase.class);
073:
074:            public EjbJarXmlTestCase(String name) {
075:
076:                super (name);
077:
078:            }
079:
080:            // Tests
081:            public void testUnmarshalDDXsd() throws Exception {
082:                // create an object model factory
083:                ObjectModelFactory factory = new EjbJarDDObjectFactory();
084:                URL xmlUrl = getResourceUrl("dd/ejb-jar.xml");
085:                assertNotNull(xmlUrl);
086:                Unmarshaller unmarshaller = UnmarshallerFactory.newInstance()
087:                        .newUnmarshaller();
088:                EjbJarDD dd = (EjbJarDD) unmarshaller.unmarshal(xmlUrl
089:                        .openStream(), factory, null);
090:                assertNotNull(dd);
091:
092:                factory = new JBossDDObjectFactory(dd);
093:                xmlUrl = getResourceUrl("dd/jboss.xml");
094:                assertNotNull(xmlUrl);
095:                unmarshaller = UnmarshallerFactory.newInstance()
096:                        .newUnmarshaller();
097:                dd = (EjbJarDD) unmarshaller.unmarshal(xmlUrl.openStream(),
098:                        factory, null);
099:
100:                checkUnmarshalledDD(dd);
101:            }
102:
103:            public void testUnmarshalMdb() throws Exception {
104:                // create an object model factory
105:                ObjectModelFactory factory = new EjbJarDDObjectFactory();
106:                URL xmlUrl = getResourceUrl("dd/mdb/META-INF/ejb-jar.xml");
107:                assertNotNull(xmlUrl);
108:                Unmarshaller unmarshaller = UnmarshallerFactory.newInstance()
109:                        .newUnmarshaller();
110:                EjbJarDD dd = (EjbJarDD) unmarshaller.unmarshal(xmlUrl
111:                        .openStream(), factory, null);
112:                assertNotNull(dd);
113:
114:                factory = new JBossDDObjectFactory(dd);
115:                xmlUrl = getResourceUrl("dd/mdb/META-INF/jboss.xml");
116:                assertNotNull(xmlUrl);
117:                unmarshaller = UnmarshallerFactory.newInstance()
118:                        .newUnmarshaller();
119:                dd = (EjbJarDD) unmarshaller.unmarshal(xmlUrl.openStream(),
120:                        factory, null);
121:
122:                checkUnmarshalledMdb(dd);
123:            }
124:
125:            private void checkUnmarshalledDD(EjbJarDD dd) {
126:                log.debug("unmarshalled DD: " + dd);
127:
128:                assertEquals("2.1", dd.getVersion());
129:                assertEquals("DukesBankEJBJAR", dd.getDisplayName());
130:
131:                assertEquals("java:/jaas/dukesbank", dd.getSecurityDomain());
132:
133:                Iterator ejbs = dd.getEnterpriseBeans().getEnterpriseBeans()
134:                        .iterator();
135:                assertNotNull(ejbs);
136:                assertEquals(8, dd.getEnterpriseBeans().getEnterpriseBeans()
137:                        .size());
138:
139:                EnterpriseBean ejb = null;
140:
141:                ejb = (EnterpriseBean) ejbs.next();
142:                assertEquals("ServiceSix", ejb.getEjbName());
143:                assertEquals("org.jboss.ejb3.test.service.ServiceSixLocal", ejb
144:                        .getLocal());
145:                assertEquals("org.jboss.ejb3.test.service.ServiceSixRemote",
146:                        ejb.getRemote());
147:                assertTrue(ejb instanceof  Service);
148:                Service service = (Service) ejb;
149:                assertEquals(
150:                        "org.jboss.ejb3.test.service.ServiceSixManagement",
151:                        service.getManagement());
152:
153:                ejbs.next();
154:                ejb = (EnterpriseBean) ejbs.next();
155:                assertEquals("CustomerBean", ejb.getEjbName());
156:                assertTrue(ejb instanceof  EntityEnterpriseBean);
157:                assertEquals("Container", ((EntityEnterpriseBean) ejb)
158:                        .getPersistenceType());
159:
160:                Relationships relationships = dd.getRelationships();
161:                assertNotNull(relationships);
162:                List relations = relationships.getEjbRelations();
163:                assertEquals(2, relations.size());
164:                EjbRelation relation = (EjbRelation) relations.get(0);
165:                assertEquals("account-customer", relation.getEjbRelationName());
166:                List roles = relation.getEjbRelationshipRoles();
167:                assertEquals(2, roles.size());
168:                EjbRelationshipRole role = (EjbRelationshipRole) roles.get(0);
169:                assertEquals("customer-belongs-to-account", role
170:                        .getEjbRelationshipRoleName());
171:                assertEquals("Many", role.getMultiplicity());
172:                assertFalse(role.isCascadeDelete());
173:                RelationshipRoleSource source = role
174:                        .getRelationshipRoleSource();
175:                assertNotNull(source);
176:                assertEquals("CustomerBean", source.getEjbName());
177:                CmrField field = role.getCmrField();
178:                assertNotNull(field);
179:                assertEquals("accounts", field.getCmrFieldName());
180:                assertEquals("java.util.Collection", field.getCmrFieldType());
181:
182:                ejbs.next();
183:                ejbs.next();
184:                ejbs.next();
185:                ejb = (EnterpriseBean) ejbs.next();
186:                assertEquals("AccountControllerBean", ejb.getEjbName());
187:                assertEquals("java:/jaas/override", ejb.getSecurityDomain());
188:
189:                assertEquals("com.sun.ebank.ejb.account.AccountControllerHome",
190:                        ejb.getHome());
191:                assertEquals("com.sun.ebank.ejb.account.AccountController", ejb
192:                        .getRemote());
193:                assertEquals("com.sun.ebank.ejb.account.AccountControllerBean",
194:                        ejb.getEjbClass());
195:                log.info("ejb.getLocal() " + ejb.getLocal());
196:                assertNull(ejb.getLocal());
197:                assertNull(ejb.getLocalHome());
198:                assertTrue(ejb instanceof  SessionEnterpriseBean);
199:                SessionEnterpriseBean session = (SessionEnterpriseBean) ejb;
200:                assertEquals("Stateful", session.getSessionType());
201:                assertEquals(javax.ejb.TransactionManagementType.CONTAINER,
202:                        session.getTransactionManagementType());
203:                assertEquals("ebankAccountController", session.getJndiName());
204:                SecurityIdentity si = session.getSecurityIdentity();
205:                assertNotNull(si);
206:                assertTrue(si.isUseCallerIdentity());
207:                Collection ejblocalRefs = session.getEjbLocalRefs();
208:                assertEquals(3, ejblocalRefs.size());
209:                EjbLocalRef ejbLocalRef = (EjbLocalRef) ejblocalRefs.iterator()
210:                        .next();
211:                assertEquals("ejb/customer", ejbLocalRef.getEjbRefName());
212:                assertEquals("Entity", ejbLocalRef.getEjbRefType());
213:                assertEquals("com.sun.ebank.ejb.customer.LocalCustomerHome",
214:                        ejbLocalRef.getLocalHome());
215:                assertEquals("com.sun.ebank.ejb.customer.LocalCustomer",
216:                        ejbLocalRef.getLocal());
217:                assertEquals("CustomerBean", ejbLocalRef.getEjbLink());
218:                Collection resourceRefs = session.getResourceRefs();
219:                assertEquals(1, resourceRefs.size());
220:                ResourceRef resourceEnvRef = (ResourceRef) resourceRefs
221:                        .iterator().next();
222:                assertEquals("jdbc/BankDB", resourceEnvRef.getResRefName());
223:                assertEquals("javax.sql.DataSource", resourceEnvRef
224:                        .getResType());
225:                assertEquals("Container", resourceEnvRef.getResAuth());
226:                assertEquals("Shareable", resourceEnvRef.getResSharingScope());
227:
228:                AssemblyDescriptor descriptor = dd.getAssemblyDescriptor();
229:                assertNotNull(descriptor);
230:                List securityRoles = descriptor.getSecurityRoles();
231:                assertEquals(2, securityRoles.size());
232:                SecurityRole securityRole = (SecurityRole) securityRoles.get(0);
233:                assertEquals("bankCustomer", securityRole.getRoleName());
234:                List methodPermissions = descriptor.getMethodPermissions();
235:                assertEquals(7, methodPermissions.size());
236:                MethodPermission methodPermission = (MethodPermission) methodPermissions
237:                        .get(0);
238:                List roleNames = methodPermission.getRoleNames();
239:                assertNotNull(roleNames);
240:                assertEquals(1, roleNames.size());
241:                assertEquals("bankCustomer", roleNames.get(0));
242:                List<Method> methods = methodPermission.getMethods();
243:                assertNotNull(methods);
244:                assertEquals(methods.size(), 1);
245:                Method method = methods.get(0);
246:                assertEquals("CustomerBean", method.getEjbName());
247:                assertEquals("*", method.getMethodName());
248:                List containerTransactions = descriptor
249:                        .getContainerTransactions();
250:                assertEquals(7, containerTransactions.size());
251:                ContainerTransaction containerTransaction = (ContainerTransaction) containerTransactions
252:                        .get(0);
253:                assertEquals("Required", containerTransaction
254:                        .getTransAttribute());
255:                method = containerTransaction.getMethod();
256:                assertNotNull(method);
257:                assertEquals("AccountControllerBean", method.getEjbName());
258:                assertEquals("*", method.getMethodName());
259:            }
260:
261:            private void checkUnmarshalledMdb(EjbJarDD dd) {
262:                log.debug("unmarshalled DD: " + dd);
263:
264:                EnterpriseBeans ejbs = dd.getEnterpriseBeans();
265:                assertNotNull(ejbs);
266:                assertEquals(9, ejbs.getEnterpriseBeans().size());
267:                Iterator ejbIterator = ejbs.getEnterpriseBeans().iterator();
268:
269:                ejbIterator.next();
270:                ejbIterator.next();
271:                EnterpriseBean ejb = (EnterpriseBean) ejbIterator.next();
272:                assertEquals("ObjectMessageBean", ejb.getEjbName());
273:                assertEquals("org.jboss.ejb3.test.dd.mdb.ObjectMessageBean",
274:                        ejb.getEjbClass());
275:                assertTrue(ejb instanceof  MessageDrivenBean);
276:                MessageDrivenBean mdb = (MessageDrivenBean) ejb;
277:                NameValuePair property = (NameValuePair) mdb
278:                        .getActivationConfig().getActivationConfigProperties()
279:                        .get(0);
280:                assertEquals("AUTO_ACKNOWLEDGE", property.getValue());
281:                assertEquals("Bean", mdb.getTransactionType());
282:                MessageDrivenDestination destination = mdb
283:                        .getMessageDrivenDestination();
284:                assertNotNull(destination);
285:                assertEquals("javax.jms.Queue", destination
286:                        .getDestinationType());
287:            }
288:
289:            private static URL getResourceUrl(String name) {
290:                URL url = Thread.currentThread().getContextClassLoader()
291:                        .getResource(name);
292:                if (url == null) {
293:                    throw new IllegalStateException("Resource not found: "
294:                            + name);
295:                }
296:                return url;
297:            }
298:
299:            public static Test suite() throws Exception {
300:                return new TestSuite(EjbJarXmlTestCase.class);
301:            }
302:
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.