Source Code Cross Referenced for A_EtypeOutildate.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:         * --------------------------------------------------------------------------
022:         * $Id: A_EtypeOutildate.java 9732 2006-10-12 15:26:04Z coqp $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas.jtests.clients.entity;
027:
028:        import java.util.Collection;
029:        import java.util.Date;
030:        import java.util.Iterator;
031:        import javax.ejb.FinderException;
032:
033:        import org.objectweb.jonas.jtests.beans.etype.outildate.Outildate;
034:        import org.objectweb.jonas.jtests.beans.etype.outildate.OutildateHome;
035:        import org.objectweb.jonas.jtests.util.JTestCase;
036:
037:        /**
038:         * This set of test are common to CMP version 1 and CMP version 2
039:         * NOTE: In fact, this type is not supported in CMP1.
040:         * These are tests about java.lang.Utildate field of entity bean .
041:         * Beans used: etype/outildate
042:         * @author Helene Joanin
043:         */
044:        public abstract class A_EtypeOutildate extends JTestCase {
045:
046:            private static final long ONE_HOUR = 60L * 60L * 1000L;
047:            private static final long ONE_DAY = 24L * ONE_HOUR;
048:
049:            public A_EtypeOutildate(String name) {
050:                super (name);
051:            }
052:
053:            protected void setUp() {
054:                super .setUp();
055:            }
056:
057:            /**
058:             * Return OutildateHome.
059:             */
060:            abstract public OutildateHome getHome();
061:
062:            /**
063:             * findByPrimaryKey() test
064:             */
065:            public void testUtilDateFindByPk() throws Exception {
066:                String pk = "pk1";
067:                Outildate bean = getHome().findByPrimaryKey(pk);
068:                assertEquals("Pk", pk, bean.getPk());
069:            }
070:
071:            /**
072:             * findByF1() test
073:             */
074:            public void testUtilDateFindByF1() throws Exception {
075:                Date d5 = new Date(5 * ONE_DAY);
076:                Collection cBeans = getHome().findByF1(d5);
077:                int nb = 0;
078:                Iterator iBeans = cBeans.iterator();
079:                while (iBeans.hasNext()) {
080:                    Outildate bean = (Outildate) javax.rmi.PortableRemoteObject
081:                            .narrow(iBeans.next(), Outildate.class);
082:                    Date f1 = bean.getF1();
083:                    // This assert may fail because of TIME ZONE problem ??
084:                    //   F1 expected:<Tue Jan 06 01:00:00 CET 1970> but was:<1970-01-06>
085:                    // assertEquals("F1", d5, f1);
086:                    if ((f1.getTime() - d5.getTime() > 2 * ONE_HOUR)
087:                            || (f1.getTime() - d5.getTime() < -2 * ONE_HOUR)) {
088:                        // The two dates differs than more 2 HOURS -> error
089:                        assertEquals("F1", d5, f1);
090:                    }
091:                    nb++;
092:                }
093:                assertEquals("Beans number: ", 2, nb);
094:            }
095:
096:            /**
097:             * getF1() test
098:             */
099:            public void testUtilDateGetF1() throws Exception {
100:                String pk = "pk2";
101:                Outildate bean = getHome().findByPrimaryKey(pk);
102:                Date d2 = new Date(2 * ONE_DAY);
103:                Date f1 = bean.getF1();
104:                assertEquals("Pk", pk, bean.getPk());
105:                // The following assert may fail because of TIME ZONE problem ??
106:                //   F1 expected:<Sat Jan 03 01:00:00 CET 1970> but was:<1970-01-03>
107:                // assertEquals("F1", new Date(2*ONE_DAY), f1);
108:                if ((f1.getTime() - d2.getTime() > 2 * ONE_HOUR)
109:                        || (f1.getTime() - d2.getTime() < -2 * ONE_HOUR)) {
110:                    // The two dates differs than more 2 HOURS -> error
111:                    assertEquals("F1", d2, f1);
112:                }
113:            }
114:
115:            /**
116:             * getF1Null() test: f1 with a 'null' value
117:             */
118:            public void testUtilDateGetF1Null() throws Exception {
119:                String pk = "pknull";
120:                Outildate bean = getHome().findByPrimaryKey(pk);
121:                Date f1 = bean.getF1();
122:                assertEquals("Pk", pk, bean.getPk());
123:                assertNull("F1 not null", f1);
124:            }
125:
126:            /**
127:             * setF1() test
128:             */
129:            public void testUtilDateSetF1() throws Exception {
130:                String pk = "pk3";
131:                Outildate bean = getHome().findByPrimaryKey(pk);
132:                Date f1 = new Date(30 * ONE_DAY);
133:                bean.setF1(f1);
134:                assertEquals("Pk", pk, bean.getPk());
135:                assertEquals("F1", f1, bean.getF1());
136:                //cleaning
137:                bean.setF1(new Date(3 * ONE_DAY));
138:            }
139:
140:            /**
141:             * setF1Null() test: f1 with a 'null' value
142:             */
143:            public void testUtilDateSetF1Null() throws Exception {
144:                String pk = "pkchangenull";
145:                Outildate bean = getHome().findByPrimaryKey(pk);
146:                bean.setF1(null);
147:                assertEquals("Pk", pk, bean.getPk());
148:                assertNull("F1", bean.getF1());
149:            }
150:
151:            /**
152:             * create() test
153:             */
154:            public void testUtilDateCreate() throws Exception {
155:                String pk = "pkcreated";
156:                Date f1 = new Date(1959 * ONE_DAY);
157:                Outildate bean = getHome().create(pk, f1);
158:                assertEquals("Pk", pk, bean.getPk());
159:                assertEquals("F1", f1, bean.getF1());
160:                bean = getHome().findByPrimaryKey(pk);
161:                // cleaning
162:                bean.remove();
163:            }
164:
165:            /**
166:             * remove() test
167:             */
168:            public void testUtilDateRemove() throws Exception {
169:                String pk = "pktoremove";
170:                Outildate bean = getHome().findByPrimaryKey(pk);
171:                Date f1 = bean.getF1();
172:                bean.remove();
173:                try {
174:                    getHome().findByPrimaryKey(pk);
175:                    fail("not removed");
176:                } catch (FinderException e) {
177:                    // ok
178:                }
179:                // cleaning
180:                getHome().create(pk, f1);
181:            }
182:
183:            /**
184:             * Test the EJB-QL: SELECT OBJECT(o) FROM jt2_outildate o WHERE o.f1 < ?1
185:             */
186:            public void testUtilDateLessThen() throws Exception {
187:                Date d3 = new Date(3 * ONE_DAY);
188:                Collection cBeans = getHome().findByF1LessThen(d3);
189:                Iterator iBeans = cBeans.iterator();
190:                int nb = 0;
191:                while (iBeans.hasNext()) {
192:                    Outildate bean = (Outildate) javax.rmi.PortableRemoteObject
193:                            .narrow(iBeans.next(), Outildate.class);
194:                    Date f = bean.getF1();
195:                    assertTrue("Pk=" + bean.getPk() + ",f1=" + f, f
196:                            .compareTo(d3) < 0);
197:                    nb++;
198:                }
199:                assertEquals("Beans number: ", 2, nb);
200:            }
201:
202:            /**
203:             * Test the EJB-QL: SELECT OBJECT(o) FROM jt2_outildate o WHERE o.f1 <= ?1
204:             */
205:            public void testUtilDateLessOrEqualThen() throws Exception {
206:                Date d3 = new Date(3 * ONE_DAY);
207:                Collection cBeans = getHome().findByF1LessOrEqualThen(d3);
208:                Iterator iBeans = cBeans.iterator();
209:                int nb = 0;
210:                while (iBeans.hasNext()) {
211:                    Outildate bean = (Outildate) javax.rmi.PortableRemoteObject
212:                            .narrow(iBeans.next(), Outildate.class);
213:                    Date f = bean.getF1();
214:                    assertTrue("Pk=" + bean.getPk() + ",f1=" + f, f
215:                            .compareTo(d3) <= 0);
216:                    nb++;
217:                }
218:                assertEquals("Beans number: ", 3, nb);
219:            }
220:
221:            /**
222:             * Test the EJB-QL: SELECT OBJECT(o) FROM jt2_outildate o
223:             *    WHERE (?1 is null or o.f1 < ?1)
224:             *   and (?2 is null or o.f1 > ?2)
225:             *   and (?3 is null or o.pk = ?3)
226:             *   must reproduce bug #306178
227:             */
228:            public void testUtilDateWithThreeArgs() throws Exception {
229:                Date d5 = new Date(5 * ONE_DAY);
230:                Date d1 = new Date(ONE_DAY);
231:                Collection cBeans = getHome().findWithThreeArgs(d5, d1, "pk4");
232:                assertEquals("Beans number: ", 1, cBeans.size());
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.