Source Code Cross Referenced for SimpleUnitTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » cmp2 » simple » 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 » testsuite » org.jboss.test.cmp2.simple 
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.test.cmp2.simple;
023:
024:        import java.math.BigDecimal;
025:        import java.sql.Time;
026:        import java.sql.Timestamp;
027:        import java.util.Collection;
028:        import java.util.Calendar;
029:        import java.util.HashMap;
030:        import java.util.Hashtable;
031:        import java.util.Properties;
032:        import javax.naming.InitialContext;
033:        import javax.ejb.DuplicateKeyException;
034:
035:        import org.apache.log4j.Logger;
036:
037:        import junit.framework.Test;
038:        import org.jboss.test.JBossTestCase;
039:        import org.jboss.test.util.ejb.EJBTestCase;
040:
041:        /** Basic cmp2 tests
042:         * 
043:         * @author alex@jboss.org
044:         * @author Scott.Stark@jboss.org
045:         * @version $Revision: 57211 $
046:         */
047:        public class SimpleUnitTestCase extends EJBTestCase {
048:            private static Logger log = Logger
049:                    .getLogger(SimpleUnitTestCase.class);
050:
051:            public static Test suite() throws Exception {
052:                return JBossTestCase.getDeploySetup(SimpleUnitTestCase.class,
053:                        "cmp2-simple.jar");
054:            }
055:
056:            public SimpleUnitTestCase(String name) {
057:                super (name);
058:
059:                Calendar c = Calendar.getInstance();
060:                c.clear(); // Must clear time components
061:                c.set(1981, 4, 5);
062:                sqlDateValue = new java.sql.Date(c.getTime().getTime());
063:
064:                c = Calendar.getInstance();
065:                c.clear(); // Must set date components to epoch
066:                c.set(Calendar.HOUR_OF_DAY, 22);
067:                c.set(Calendar.MINUTE, 33);
068:                c.set(Calendar.SECOND, 44);
069:                // java.sql.Time does not have a millisecond component
070:                timeValue = new java.sql.Time(c.getTime().getTime());
071:
072:                objectValue = new HashMap();
073:                ((HashMap) objectValue).put("boolean", booleanObject);
074:                ((HashMap) objectValue).put("byte", byteObject);
075:                ((HashMap) objectValue).put("short", shortObject);
076:                ((HashMap) objectValue).put("int", integerObject);
077:                ((HashMap) objectValue).put("long", longObject);
078:                ((HashMap) objectValue).put("float", floatObject);
079:                ((HashMap) objectValue).put("double", doubleObject);
080:                ((HashMap) objectValue).put("string", stringValue);
081:                ((HashMap) objectValue).put("utilDate", utilDateValue);
082:                ((HashMap) objectValue).put("sqlDate", sqlDateValue);
083:                ((HashMap) objectValue).put("time", timeValue);
084:                ((HashMap) objectValue).put("timestamp", timestampValue);
085:                ((HashMap) objectValue).put("bigDecimal", bigDecimalValue);
086:            }
087:
088:            private SimpleHome getSimpleHome() {
089:                try {
090:                    InitialContext jndiContext = new InitialContext();
091:
092:                    return (SimpleHome) jndiContext
093:                            .lookup("cmp2/simple/Simple");
094:                } catch (Exception e) {
095:                    log.debug("failed", e);
096:                    fail("Exception in getSimpleHome: " + e.getMessage());
097:                }
098:                return null;
099:            }
100:
101:            private Simple simple;
102:            private final boolean booleanPrimitive = true;
103:            private final Boolean booleanObject = Boolean.FALSE;
104:            private final byte bytePrimitive = (byte) 11;
105:            private final Byte byteObject = new Byte((byte) 22);
106:            private final short shortPrimitive = (short) 33;
107:            private final Short shortObject = new Short((short) 44);
108:            private final int integerPrimitive = 55;
109:            private final Integer integerObject = new Integer(66);
110:            private final long longPrimitive = 77;
111:            private final Long longObject = new Long(88);
112:            private final float floatPrimitive = 11.11f;
113:            private final Float floatObject = new Float(22.22f);
114:            private final double doublePrimitive = 33.33;
115:            private final Double doubleObject = new Double(44.44);
116:            private final String stringValue = "test string value";
117:            private final java.util.Date utilDateValue = new java.util.Date(
118:                    1111);
119:            private final java.sql.Date sqlDateValue;
120:            private final Time timeValue;
121:            private final Timestamp timestampValue = new Timestamp(4444);
122:            private final BigDecimal bigDecimalValue = new BigDecimal(
123:                    "12345678.1234");
124:            private final byte[] byteArrayValue = "byte array test".getBytes();
125:            private final Object objectValue;
126:            private final ValueClass valueClass = new ValueClass(111, 999);
127:            private final Hashtable hashtable = new Hashtable();
128:
129:            public void testBooleanPrimitive() throws Exception {
130:                assertEquals(booleanPrimitive, simple.getBooleanPrimitive());
131:            }
132:
133:            public void testBooleanObject() throws Exception {
134:                assertEquals(booleanObject, simple.getBooleanObject());
135:            }
136:
137:            public void testBytePrimitive() throws Exception {
138:                assertEquals(bytePrimitive, simple.getBytePrimitive());
139:            }
140:
141:            public void testByteObject() throws Exception {
142:                assertEquals(byteObject, simple.getByteObject());
143:            }
144:
145:            public void testShortPrimitive() throws Exception {
146:                assertEquals(shortPrimitive, simple.getShortPrimitive());
147:            }
148:
149:            public void testShortObject() throws Exception {
150:                assertEquals(shortObject, simple.getShortObject());
151:            }
152:
153:            public void testIntegerPrimitive() throws Exception {
154:                assertEquals(integerPrimitive, simple.getIntegerPrimitive());
155:            }
156:
157:            public void testIntegerObject() throws Exception {
158:                assertEquals(integerObject, simple.getIntegerObject());
159:            }
160:
161:            public void testLongPrimitive() throws Exception {
162:                assertEquals(longPrimitive, simple.getLongPrimitive());
163:            }
164:
165:            public void testLongObject() throws Exception {
166:                assertEquals(longObject, simple.getLongObject());
167:            }
168:
169:            public void testFloatPrimitive() throws Exception {
170:                assertEquals(floatPrimitive, simple.getFloatPrimitive(), 0);
171:            }
172:
173:            public void testFloatObject() throws Exception {
174:                assertEquals(floatObject, simple.getFloatObject());
175:            }
176:
177:            public void testDoublePrimitive() throws Exception {
178:                assertEquals(doublePrimitive, simple.getDoublePrimitive(), 0);
179:            }
180:
181:            public void testDoubleObject() throws Exception {
182:                assertEquals(doubleObject, simple.getDoubleObject());
183:            }
184:
185:            public void testStringValue() throws Exception {
186:                assertEquals(stringValue, simple.getStringValue());
187:            }
188:
189:            public void testUtilDateValue() throws Exception {
190:                assertTrue("expected :<" + simple.getUtilDateValue()
191:                        + "> but was <" + utilDateValue + ">", utilDateValue
192:                        .compareTo(simple.getUtilDateValue()) == 0);
193:            }
194:
195:            public void testSqlDateValue() throws Exception {
196:                assertTrue("expected :<" + simple.getSqlDateValue()
197:                        + "> but was <" + sqlDateValue + ">", sqlDateValue
198:                        .compareTo(simple.getSqlDateValue()) == 0);
199:            }
200:
201:            public void testTimeValue() throws Exception {
202:                assertTrue("expected :<" + simple.getTimeValue()
203:                        + "> but was <" + timeValue + ">", timeValue
204:                        .compareTo(simple.getTimeValue()) == 0);
205:            }
206:
207:            public void testTimestampValue() throws Exception {
208:                assertTrue("expected :<" + simple.getTimestampValue()
209:                        + "> but was <" + timestampValue + ">", timestampValue
210:                        .compareTo(simple.getTimestampValue()) == 0);
211:            }
212:
213:            public void testBigDecimalValue() throws Exception {
214:                assertTrue(
215:                        "expected :<" + simple.getBigDecimalValue()
216:                                + "> but was <" + bigDecimalValue + ">",
217:                        bigDecimalValue.compareTo(simple.getBigDecimalValue()) == 0);
218:            }
219:
220:            public void testByteArrayValue() throws Exception {
221:                byte[] array = simple.getByteArrayValue();
222:                assertEquals(byteArrayValue.length, array.length);
223:                for (int i = 0; i < array.length; i++) {
224:                    assertEquals(byteArrayValue[i], array[i]);
225:                }
226:            }
227:
228:            public void testValueClass() throws Exception {
229:                ValueClass vc = simple.getValueClass();
230:                log.info("getValueClass class: " + vc.getClass().getName());
231:                log.info("getValueClass classloader: "
232:                        + vc.getClass().getClassLoader());
233:                log
234:                        .info("ValueClass class: "
235:                                + valueClass.getClass().getName());
236:                log.info("ValueClass classloader: "
237:                        + valueClass.getClass().getClassLoader());
238:                assertEquals(valueClass, vc);
239:            }
240:
241:            public void testObjectValue() throws Exception {
242:                Object v = simple.getObjectValue();
243:                log.info("getObjectValue class: " + v.getClass().getName());
244:                log.info("getObjectValue classloader: "
245:                        + v.getClass().getClassLoader());
246:                log.info("objectValue class: "
247:                        + objectValue.getClass().getName());
248:                log.info("objectValue classloader: "
249:                        + objectValue.getClass().getClassLoader());
250:                assertEquals(objectValue, v);
251:            }
252:
253:            public void testLiteralToLiteral() throws Exception {
254:                SimpleHome simpleHome = getSimpleHome();
255:                Collection c;
256:
257:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
258:                        + "FROM simple s " + "WHERE TRUE=TRUE", new Object[0]);
259:                assertTrue(c.size() == 1);
260:
261:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
262:                        + "FROM simple s " + "WHERE 1.2=1.2", new Object[0]);
263:                assertTrue(c.size() == 1);
264:
265:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
266:                        + "FROM simple s " + "WHERE 'funk'='funk'",
267:                        new Object[0]);
268:                assertTrue(c.size() == 1);
269:            }
270:
271:            public void testUtilDateBetween() throws Exception {
272:                SimpleHome simpleHome = getSimpleHome();
273:                Collection c;
274:
275:                java.util.Date utilDateBefore = new java.util.Date(100);
276:                java.util.Date utilDateAfter = new java.util.Date(2000);
277:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
278:                        + "FROM simple s "
279:                        + "WHERE s.utilDateValue BETWEEN ?1 AND ?2",
280:                        new Object[] { utilDateBefore, utilDateAfter });
281:                assertTrue(c.size() == 1);
282:            }
283:
284:            public void testSQLDateBetween() throws Exception {
285:                SimpleHome simpleHome = getSimpleHome();
286:                Collection c;
287:                Calendar calendar;
288:
289:                calendar = Calendar.getInstance();
290:                calendar.clear(); // Must clear time components
291:                calendar.set(1981, 4, 3);
292:                java.sql.Date sqlDateBefore = new java.sql.Date(calendar
293:                        .getTime().getTime());
294:
295:                calendar = Calendar.getInstance();
296:                calendar.clear(); // Must clear time components
297:                calendar.set(1981, 4, 6);
298:                java.sql.Date sqlDateAfter = new java.sql.Date(calendar
299:                        .getTime().getTime());
300:
301:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
302:                        + "FROM simple s "
303:                        + "WHERE s.sqlDateValue BETWEEN ?1 AND ?2",
304:                        new Object[] { sqlDateBefore, sqlDateAfter });
305:                assertTrue(c.size() == 1);
306:            }
307:
308:            public void testTimeBetween() throws Exception {
309:                SimpleHome simpleHome = getSimpleHome();
310:                Collection c;
311:                Calendar calendar;
312:
313:                calendar = Calendar.getInstance();
314:                calendar.clear(); // Must set date components to epoch
315:                calendar.set(Calendar.HOUR_OF_DAY, 21);
316:                calendar.set(Calendar.MINUTE, 33);
317:                calendar.set(Calendar.SECOND, 44);
318:                // java.sql.Time does not have a millisecond component
319:                Time timeBefore = new java.sql.Time(calendar.getTime()
320:                        .getTime());
321:
322:                calendar = Calendar.getInstance();
323:                calendar.clear(); // Must set date components to epoch
324:                calendar.set(Calendar.HOUR_OF_DAY, 23);
325:                calendar.set(Calendar.MINUTE, 33);
326:                calendar.set(Calendar.SECOND, 44);
327:                // java.sql.Time does not have a millisecond component
328:                Time timeAfter = new java.sql.Time(calendar.getTime().getTime());
329:
330:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
331:                        + "FROM simple s "
332:                        + "WHERE s.timeValue BETWEEN ?1 AND ?2", new Object[] {
333:                        timeBefore, timeAfter });
334:                assertTrue(c.size() == 1);
335:
336:            }
337:
338:            public void testTimestampBetween() throws Exception {
339:                SimpleHome simpleHome = getSimpleHome();
340:                Collection c;
341:
342:                Timestamp timestampBefore = new Timestamp(1111);
343:                Timestamp timestampAfter = new Timestamp(8888);
344:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
345:                        + "FROM simple s "
346:                        + "WHERE s.timestampValue BETWEEN ?1 AND ?2",
347:                        new Object[] { timestampBefore, timestampAfter });
348:                assertTrue(c.size() == 1);
349:            }
350:
351:            public void testTimestampComparison() throws Exception {
352:                SimpleHome simpleHome = getSimpleHome();
353:                Collection c;
354:
355:                Timestamp timestampBefore = new Timestamp(1111);
356:                Timestamp timestampAfter = new Timestamp(8888);
357:                c = simpleHome
358:                        .selectDynamic(
359:                                "SELECT OBJECT(s) "
360:                                        + "FROM simple s "
361:                                        + "WHERE s.timestampValue >= ?1 AND s.timestampValue <= ?2",
362:                                new Object[] { timestampBefore, timestampAfter });
363:                assertTrue(c.size() == 1);
364:            }
365:
366:            public void testTimestampIn() throws Exception {
367:                SimpleHome simpleHome = getSimpleHome();
368:                Collection c;
369:
370:                Timestamp timestampBefore = new Timestamp(1111);
371:                Timestamp timestampAfter = new Timestamp(8888);
372:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
373:                        + "FROM simple s "
374:                        + "WHERE s.timestampValue IN(?1, ?2, ?3)",
375:                        new Object[] { timestampBefore, timestampAfter,
376:                                timestampValue });
377:                assertTrue(c.size() == 1);
378:            }
379:
380:            public void testStringBetween() throws Exception {
381:                SimpleHome simpleHome = getSimpleHome();
382:                Collection c;
383:
384:                c = simpleHome
385:                        .selectDynamic(
386:                                "SELECT OBJECT(s) "
387:                                        + "FROM simple s "
388:                                        + "WHERE UCASE(s.stringValue) BETWEEN UCASE(?1) AND UCASE(?2)",
389:                                new Object[] { "aaaaa", "zzzzz" });
390:                assertTrue(c.size() == 1);
391:            }
392:
393:            public void testStringComparison() throws Exception {
394:                SimpleHome simpleHome = getSimpleHome();
395:                Collection c;
396:
397:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
398:                        + "FROM simple s "
399:                        + "WHERE UCASE(s.stringValue) >= UCASE(?1) AND "
400:                        + "  UCASE(s.stringValue) <= UCASE(?2)", new Object[] {
401:                        "aaaaa", "zzzzz" });
402:                assertTrue(c.size() == 1);
403:            }
404:
405:            public void testStringIn() throws Exception {
406:                SimpleHome simpleHome = getSimpleHome();
407:                Collection c;
408:
409:                c = simpleHome
410:                        .selectDynamic(
411:                                "SELECT OBJECT(s) "
412:                                        + "FROM simple s "
413:                                        + "WHERE UCASE(s.stringValue) IN(UCASE(?1), UCASE(?2), "
414:                                        + "  UCASE('" + stringValue + "'))",
415:                                new Object[] { "aaaaa", "zzzzz" });
416:                assertTrue(c.size() == 1);
417:            }
418:
419:            public void testLike() throws Exception {
420:                SimpleHome simpleHome = getSimpleHome();
421:                Collection c;
422:
423:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
424:                        + "FROM simple s "
425:                        + "WHERE UCASE(s.stringValue) LIKE UCASE(?1)",
426:                        new Object[] { "% string %" });
427:                assertTrue(c.size() == 1);
428:            }
429:
430:            public void testNumericIn() throws Exception {
431:                SimpleHome simpleHome = getSimpleHome();
432:                Collection c;
433:
434:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
435:                        + "FROM simple s " + "WHERE SQRT(s.longPrimitive) "
436:                        + "  IN(SQRT(?1), SQRT(?2), SQRT( " + longPrimitive
437:                        + " ) )", new Object[] { new Long(23094),
438:                        new Long(20984) });
439:                assertTrue(c.size() == 1);
440:            }
441:
442:            public void testNumbericComparison() throws Exception {
443:                SimpleHome simpleHome = getSimpleHome();
444:                Collection c;
445:
446:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
447:                        + "FROM simple s "
448:                        + "WHERE SQRT(s.longPrimitive) >= SQRT(?1) AND "
449:                        + "  SQRT(s.longPrimitive) <= SQRT(?2)", new Object[] {
450:                        new Long(22), new Long(20984) });
451:                assertTrue(c.size() == 1);
452:            }
453:
454:            public void testConcatFunction() throws Exception {
455:                SimpleHome simpleHome = getSimpleHome();
456:                Collection c;
457:
458:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
459:                        + "FROM simple s " + "WHERE CONCAT(?1, ?2) = ?3",
460:                        new Object[] { "foo", "bar", "foobar" });
461:                assertTrue(c.size() == 1);
462:            }
463:
464:            public void testLengthFunction() throws Exception {
465:                SimpleHome simpleHome = getSimpleHome();
466:                Collection c;
467:
468:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
469:                        + "FROM simple s " + "WHERE LENGTH(?1) = ?2",
470:                        new Object[] { "12345", new Integer(5) });
471:                assertTrue(c.size() == 1);
472:            }
473:
474:            public void testSelectValueClass() throws Exception {
475:                SimpleHome simpleHome = getSimpleHome();
476:                Collection c = simpleHome.selectValueClass();
477:                assertEquals(1, c.size());
478:
479:                ValueClass v = (ValueClass) c.iterator().next();
480:                assertEquals(valueClass, v);
481:            }
482:
483:            public void testLocateFunction() throws Exception {
484:                SimpleHome simpleHome = getSimpleHome();
485:                Collection c;
486:
487:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
488:                        + "FROM simple s " + "WHERE LOCATE(?1, ?2, ?3) = ?4",
489:                        new Object[] { "x", "1x34x67x90", new Integer(3),
490:                                new Integer(5) });
491:                assertTrue(c.size() == 1);
492:
493:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
494:                        + "FROM simple s " + "WHERE LOCATE(?1, ?2) = ?3",
495:                        new Object[] { "x", "1x34x67x90", new Integer(2) });
496:                assertTrue(c.size() == 1);
497:
498:                c = simpleHome.selectDynamic("SELECT OBJECT(s) "
499:                        + "FROM simple s " + "WHERE LOCATE(?1, ?2, ?3) = ?4",
500:                        new Object[] { "z", "1x34x67x90", new Integer(3),
501:                                new Integer(0) });
502:                assertTrue(c.size() == 1);
503:            }
504:
505:            /* Uncomment when we upgrade to Hypersonic 1.7
506:            public void testSubstringFunction() throws Exception
507:            {
508:               SimpleHome simpleHome = getSimpleHome();
509:               Collection c;
510:
511:               c = simpleHome.selectDynamic(
512:                     "SELECT OBJECT(s) " +
513:                     "FROM simple s " +
514:                     "WHERE SUBSTRING(?1, ?2, ?3) = ?4",
515:                     new Object[]{
516:                        "1234587890",
517:                        new Integer(5),
518:                        new Integer(3),
519:                        "567"}
520:                     );
521:               assertTrue(c.size() == 1);
522:
523:               c = simpleHome.selectDynamic(
524:                     "SELECT OBJECT(s) " +
525:                     "FROM simple s " +
526:                     "WHERE SUBSTRING(?1, ?2) = ?3",
527:                     new Object[]{
528:                        "1234587890",
529:                        new Integer(5),
530:                        "567890"}
531:                     );
532:               assertTrue(c.size() == 1);
533:            }
534:             */
535:
536:            public void testFindWithByteArray() throws Exception {
537:                SimpleHome simpleHome = getSimpleHome();
538:                Collection c = simpleHome.findWithByteArray(byteArrayValue);
539:                assertEquals(1, c.size());
540:
541:                Simple s = (Simple) c.iterator().next();
542:                assertTrue(s.isIdentical(simple));
543:
544:                assertEquals(booleanPrimitive, s.getBooleanPrimitive());
545:                assertEquals(booleanObject, s.getBooleanObject());
546:                assertEquals(bytePrimitive, s.getBytePrimitive());
547:                assertEquals(byteObject, s.getByteObject());
548:                assertEquals(shortPrimitive, s.getShortPrimitive());
549:                assertEquals(shortObject, s.getShortObject());
550:                assertEquals(integerPrimitive, s.getIntegerPrimitive());
551:                assertEquals(integerObject, s.getIntegerObject());
552:                assertEquals(longPrimitive, s.getLongPrimitive());
553:                assertEquals(longObject, s.getLongObject());
554:                assertEquals(floatPrimitive, s.getFloatPrimitive(), 0);
555:                assertEquals(floatObject, s.getFloatObject());
556:                assertEquals(doublePrimitive, s.getDoublePrimitive(), 0);
557:                assertEquals(doubleObject, s.getDoubleObject());
558:                assertEquals(stringValue, s.getStringValue());
559:                assertTrue("expected :<" + simple.getUtilDateValue()
560:                        + "> but was <" + utilDateValue + ">", utilDateValue
561:                        .compareTo(simple.getUtilDateValue()) == 0);
562:                assertTrue("expected :<" + simple.getSqlDateValue()
563:                        + "> but was <" + sqlDateValue + ">", sqlDateValue
564:                        .compareTo(simple.getSqlDateValue()) == 0);
565:                assertTrue("expected :<" + simple.getTimeValue()
566:                        + "> but was <" + timeValue + ">", timeValue
567:                        .compareTo(simple.getTimeValue()) == 0);
568:                assertTrue("expected :<" + simple.getTimestampValue()
569:                        + "> but was <" + timestampValue + ">", timestampValue
570:                        .compareTo(simple.getTimestampValue()) == 0);
571:                assertTrue(
572:                        "expected :<" + simple.getBigDecimalValue()
573:                                + "> but was <" + bigDecimalValue + ">",
574:                        bigDecimalValue.compareTo(simple.getBigDecimalValue()) == 0);
575:
576:                byte[] array = simple.getByteArrayValue();
577:                assertEquals(byteArrayValue.length, array.length);
578:                for (int i = 0; i < array.length; i++) {
579:                    assertEquals(byteArrayValue[i], array[i]);
580:                }
581:
582:                assertEquals(valueClass, simple.getValueClass());
583:                assertEquals(objectValue, simple.getObjectValue());
584:            }
585:
586:            public void testDuplicateKey() throws Exception {
587:                try {
588:                    SimpleHome simpleHome = getSimpleHome();
589:                    simpleHome.create("simple");
590:                    fail("Did not get DuplicateKeyException");
591:                } catch (DuplicateKeyException e) {
592:                    // OK
593:                }
594:            }
595:
596:            public void testHashtable() throws Exception {
597:                simple.addToHashtable("key1", "value1");
598:                simple.addToHashtable("key2", "value2");
599:                Hashtable result = simple.getHashtable();
600:                assertEquals(2, result.size());
601:            }
602:
603:            public void testOptionAUpdate() throws Exception {
604:                InitialContext ctx = new InitialContext();
605:                SimpleHome home = (SimpleHome) ctx
606:                        .lookup("cmp2/simple/SimpleA");
607:                Simple simpleA = null;
608:                try {
609:                    simpleA = home.findByPrimaryKey("simpleA");
610:                } catch (Exception e) {
611:                    simpleA = home.create("simpleA");
612:                }
613:
614:                simpleA.setIntegerPrimitive(47);
615:                int i = simpleA.getIntegerPrimitive();
616:                assertTrue("i == 47 ", i == 47);
617:            }
618:
619:            public void setUpEJB(Properties props) throws Exception {
620:                SimpleHome simpleHome = getSimpleHome();
621:
622:                boolean wasCreated = false;
623:                try {
624:                    simple = simpleHome.findByPrimaryKey("simple");
625:                } catch (Exception e) {
626:                }
627:
628:                if (simple == null) {
629:                    simple = simpleHome.create("simple");
630:                    wasCreated = true;
631:                }
632:
633:                simple.setBooleanPrimitive(booleanPrimitive);
634:                simple.setBooleanObject(booleanObject);
635:                simple.setBytePrimitive(bytePrimitive);
636:                simple.setByteObject(byteObject);
637:                simple.setShortPrimitive(shortPrimitive);
638:                simple.setShortObject(shortObject);
639:                simple.setIntegerPrimitive(integerPrimitive);
640:                simple.setIntegerObject(integerObject);
641:                simple.setLongPrimitive(longPrimitive);
642:                simple.setLongObject(longObject);
643:                simple.setFloatPrimitive(floatPrimitive);
644:                simple.setFloatObject(floatObject);
645:                simple.setDoublePrimitive(doublePrimitive);
646:                simple.setDoubleObject(doubleObject);
647:                simple.setStringValue(stringValue);
648:                simple.setUtilDateValue(utilDateValue);
649:                simple.setSqlDateValue(sqlDateValue);
650:                simple.setTimeValue(timeValue);
651:                simple.setTimestampValue(timestampValue);
652:                if (wasCreated) {
653:                    simple.setBigDecimalValue(bigDecimalValue);
654:                    simple.setByteArrayValue(byteArrayValue);
655:                    simple.setObjectValue(objectValue);
656:                    simple.setValueClass(valueClass);
657:                    simple.setHashtable(hashtable);
658:                }
659:            }
660:
661:            public void tearDownEJB(Properties props) throws Exception {
662:                simple.remove();
663:            }
664:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.