Source Code Cross Referenced for F_Dass.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » clients » entity » 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 » JOnAS 4.8.6 » org.objectweb.jonas.jtests.clients.entity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         * --------------------------------------------------------------------------
021:         * $Id: F_Dass.java 7533 2005-10-19 15:55:05Z durieuxp $
022:         * --------------------------------------------------------------------------
023:         */
024:
025:        package org.objectweb.jonas.jtests.clients.entity;
026:
027:        import java.rmi.RemoteException;
028:        import java.util.Collection;
029:        import java.util.Iterator;
030:        import javax.ejb.EJBObject;
031:        import javax.ejb.FinderException;
032:        import javax.ejb.RemoveException;
033:        import javax.naming.NamingException;
034:        import javax.rmi.PortableRemoteObject;
035:        import junit.framework.Assert;
036:        import junit.framework.Test;
037:        import junit.framework.TestSuite;
038:        import org.objectweb.jonas.jtests.beans.relation.dass.DassHome;
039:        import org.objectweb.jonas.jtests.beans.relation.dass.P1Remote;
040:        import org.objectweb.jonas.jtests.beans.relation.dass.P1HomeRemote;
041:        import org.objectweb.jonas.jtests.beans.relation.dass.P2Remote;
042:        import org.objectweb.jonas.jtests.beans.relation.dass.P2HomeRemote;
043:        import org.objectweb.jonas.jtests.beans.relation.dass.P3Remote;
044:        import org.objectweb.jonas.jtests.beans.relation.dass.P3HomeRemote;
045:        import org.objectweb.jonas.jtests.beans.relation.dass.P4Remote;
046:        import org.objectweb.jonas.jtests.beans.relation.dass.P4HomeRemote;
047:        import org.objectweb.jonas.jtests.beans.relation.dass.ARemote;
048:        import org.objectweb.jonas.jtests.beans.relation.dass.AHomeRemote;
049:        import org.objectweb.jonas.jtests.beans.relation.dass.BRemote;
050:        import org.objectweb.jonas.jtests.beans.relation.dass.BHomeRemote;
051:        import org.objectweb.jonas.jtests.util.JTestCase;
052:
053:        /**
054:         * This test suite tests specifics mapping used in some applications
055:         * for example, cmr field and cmp field mapped on the same table column
056:         * @author Philippe Durieux
057:         */
058:        public class F_Dass extends JTestCase {
059:
060:            /**
061:             * Reference on the remote Home's
062:             */
063:            private static P1HomeRemote p1home = null;
064:            private static P2HomeRemote p2home = null;
065:            private static P3HomeRemote p3home = null;
066:            private static P4HomeRemote p4home = null;
067:            private static AHomeRemote ahome = null;
068:            private static BHomeRemote bhome = null;
069:
070:            /**
071:             * Standard constructor
072:             */
073:            public F_Dass(String name) {
074:                super (name);
075:            }
076:
077:            protected boolean isInit = false;
078:
079:            /**
080:             * setup is called before each test case.
081:             * If not initialized, load the dass bean and lookup the Home.
082:             */
083:            protected void setUp() {
084:                super .setUp();
085:                if (!isInit) {
086:                    useBeans("dass", false);
087:                    try {
088:                        p1home = (P1HomeRemote) PortableRemoteObject.narrow(
089:                                ictx.lookup("relation_dass_P1Home"),
090:                                P1HomeRemote.class);
091:                        p2home = (P2HomeRemote) PortableRemoteObject.narrow(
092:                                ictx.lookup("relation_dass_P2Home"),
093:                                P2HomeRemote.class);
094:                        p3home = (P3HomeRemote) PortableRemoteObject.narrow(
095:                                ictx.lookup("relation_dass_P3Home"),
096:                                P3HomeRemote.class);
097:                        p4home = (P4HomeRemote) PortableRemoteObject.narrow(
098:                                ictx.lookup("relation_dass_P4Home"),
099:                                P4HomeRemote.class);
100:                        ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx
101:                                .lookup("relation_dass_AHome"),
102:                                AHomeRemote.class);
103:                        bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx
104:                                .lookup("relation_dass_BHome"),
105:                                BHomeRemote.class);
106:                    } catch (NamingException e) {
107:                        fail("Cannot get bean home: " + e.getMessage());
108:                    }
109:                    isInit = true;
110:                }
111:            }
112:
113:            /**
114:             * teardown is called after each test case.
115:             * Notes for debugging :
116:             * To see DataBase state after a test is passed :
117:             * Replace the cleanall() by sync(false).
118:             */
119:            protected void tearDown() throws Exception {
120:                cleanall();
121:                //sync(false);
122:            }
123:
124:            /**
125:             * Cleanup all the dass after each test, to make tests independant.
126:             * Use transaction to avoid known bugs during cleanup.
127:             * (With no transaction -> 1 remove will fail)
128:             */
129:            private void cleanall() throws Exception {
130:                debug("remove all beans");
131:
132:                // In case there is a problem during remove, we must unload
133:                // the bean to restart properly.
134:                try {
135:                    cleanAllBeans(ahome);
136:                    cleanAllBeans(bhome);
137:                    cleanAllBeans(p1home);
138:                    cleanAllBeans(p2home);
139:                    cleanAllBeans(p3home);
140:                    cleanAllBeans(p4home);
141:                } catch (Exception e) {
142:                    error("Exception in cleanup: " + e);
143:                    unloadBeans("dass");
144:                    isInit = false;
145:                }
146:            }
147:
148:            private void cleanAllBeans(DassHome home) throws RemoteException,
149:                    RemoveException {
150:                try {
151:                    Collection c = home.findAll();
152:                    for (Iterator i = c.iterator(); i.hasNext();) {
153:                        EJBObject p = (EJBObject) i.next();
154:                        p.remove();
155:                    }
156:                } catch (FinderException e) {
157:                }
158:            }
159:
160:            // ---------------------------------------------------------------
161:            // Set of the tests that are passed automatically.
162:            // ---------------------------------------------------------------
163:
164:            public void testCreateA() throws Exception {
165:                ahome.create("A1");
166:            }
167:
168:            public void testCreateB() throws Exception {
169:                bhome.create("B1");
170:            }
171:
172:            /**
173:             * This test fails, normally, because:
174:             * - setting the cmr field doesn't work because it's also a cmp field.
175:             * - the cmp field is not changed, so this means that the cmr field is readonly.
176:             * Jonas should throw an exception when we try to modify this kind of cmr field.
177:             */
178:            public void _testCreateA2B() throws Exception {
179:                ARemote a1 = ahome.create("A1");
180:                bhome.create("B1");
181:                a1.assignB("B1");
182:                String cmrval = a1.getBcmrvalue();
183:                assertTrue("Bad cmr value:" + cmrval, "B1".equals(cmrval));
184:            }
185:
186:            public void _testCreateA2BTx() throws Exception {
187:                try {
188:                    utx.begin();
189:                    _testCreateA2B();
190:                } finally {
191:                    try {
192:                        utx.commit();
193:                    } catch (Exception ii) {
194:                    }
195:                }
196:            }
197:
198:            /**
199:             * Simple example with 2 beans with the same pk and a cmr on this pk.
200:             * looks like a bean mapped on 2 tables.
201:             */
202:            public void testCreateP1P2() throws Exception {
203:                P1Remote p1 = p1home.create("P", "100");
204:                P2Remote p2 = p2home.create("P");
205:                String val = p2.getP1Value();
206:                assertTrue("Cannot access bean P1", "100".equals(val));
207:            }
208:
209:            /**
210:             * Complex example of beans with cmr mapped on fields of the primary key.
211:             * Note that the primary key is composite.
212:             */
213:            public void testCreateP3() throws Exception {
214:                P1Remote p1 = p1home.create("P", "100");
215:                P4Remote p4 = p4home.create("P", "102");
216:                P3Remote p3 = p3home.create("P3", "P");
217:                String val = p3.getP1Value();
218:                assertTrue("Cannot access bean P1", "100".equals(val));
219:                val = p3.getP4Value();
220:                assertTrue("Cannot access bean P4", "102".equals(val));
221:            }
222:
223:            /**
224:             * Run all the tests of this suite.
225:             */
226:            public static Test suite() {
227:                return new TestSuite(F_Dass.class);
228:            }
229:
230:            public static void main(String args[]) throws Exception {
231:                String testtorun = null;
232:
233:                // Get args
234:                for (int argn = 0; argn < args.length; argn++) {
235:                    String sarg = args[argn];
236:                    if (sarg.equals("-n")) {
237:                        testtorun = args[++argn];
238:                    }
239:                }
240:                if (testtorun == null) {
241:                    junit.textui.TestRunner.run(suite());
242:                } else {
243:                    junit.textui.TestRunner.run(new F_Dass(testtorun));
244:                }
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.