KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > simple > SimpleUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.simple;
23
24 import java.math.BigDecimal JavaDoc;
25 import java.sql.Time JavaDoc;
26 import java.sql.Timestamp JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Calendar JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Properties JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.ejb.DuplicateKeyException JavaDoc;
34
35 import org.jboss.logging.Logger;
36
37 import junit.framework.Test;
38 import org.jboss.test.JBossTestCase;
39 import org.jboss.test.util.ejb.EJBTestCase;
40
41 /** Basic cmp2 tests
42  *
43  * @author alex@jboss.org
44  * @author Scott.Stark@jboss.org
45  * @version $Revision: 58115 $
46  */

47 public class SimpleUnitTestCase extends EJBTestCase
48 {
49    private static Logger log = Logger.getLogger(SimpleUnitTestCase.class);
50
51    public static Test suite() throws Exception JavaDoc
52    {
53       return JBossTestCase.getDeploySetup(
54          SimpleUnitTestCase.class, "cmp2-simple.jar");
55    }
56
57    public SimpleUnitTestCase(String JavaDoc name)
58    {
59       super(name);
60
61       Calendar JavaDoc c = Calendar.getInstance();
62       c.clear(); // Must clear time components
63
c.set(1981, 4, 5);
64       sqlDateValue = new java.sql.Date JavaDoc(c.getTime().getTime());
65
66       c = Calendar.getInstance();
67       c.clear(); // Must set date components to epoch
68
c.set(Calendar.HOUR_OF_DAY, 22);
69       c.set(Calendar.MINUTE, 33);
70       c.set(Calendar.SECOND, 44);
71 // java.sql.Time does not have a millisecond component
72
timeValue = new java.sql.Time JavaDoc(c.getTime().getTime());
73
74       objectValue = new HashMap JavaDoc();
75       ((HashMap JavaDoc) objectValue).put("boolean", booleanObject);
76       ((HashMap JavaDoc) objectValue).put("byte", byteObject);
77       ((HashMap JavaDoc) objectValue).put("short", shortObject);
78       ((HashMap JavaDoc) objectValue).put("int", integerObject);
79       ((HashMap JavaDoc) objectValue).put("long", longObject);
80       ((HashMap JavaDoc) objectValue).put("float", floatObject);
81       ((HashMap JavaDoc) objectValue).put("double", doubleObject);
82       ((HashMap JavaDoc) objectValue).put("string", stringValue);
83       ((HashMap JavaDoc) objectValue).put("utilDate", utilDateValue);
84       ((HashMap JavaDoc) objectValue).put("sqlDate", sqlDateValue);
85       ((HashMap JavaDoc) objectValue).put("time", timeValue);
86       ((HashMap JavaDoc) objectValue).put("timestamp", timestampValue);
87       ((HashMap JavaDoc) objectValue).put("bigDecimal", bigDecimalValue);
88    }
89
90    private SimpleHome getSimpleHome()
91    {
92       try
93       {
94          InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
95
96          return (SimpleHome) jndiContext.lookup("cmp2/simple/Simple");
97       }
98       catch (Exception JavaDoc e)
99       {
100          log.debug("failed", e);
101          fail("Exception in getSimpleHome: " + e.getMessage());
102       }
103       return null;
104    }
105
106    private Simple simple;
107    private final boolean booleanPrimitive = true;
108    private final Boolean JavaDoc booleanObject = Boolean.FALSE;
109    private final byte bytePrimitive = (byte) 11;
110    private final Byte JavaDoc byteObject = new Byte JavaDoc((byte) 22);
111    private final short shortPrimitive = (short) 33;
112    private final Short JavaDoc shortObject = new Short JavaDoc((short) 44);
113    private final int integerPrimitive = 55;
114    private final Integer JavaDoc integerObject = new Integer JavaDoc(66);
115    private final long longPrimitive = 77;
116    private final Long JavaDoc longObject = new Long JavaDoc(88);
117    private final float floatPrimitive = 11.11f;
118    private final Float JavaDoc floatObject = new Float JavaDoc(22.22f);
119    private final double doublePrimitive = 33.33;
120    private final Double JavaDoc doubleObject = new Double JavaDoc(44.44);
121    private final String JavaDoc stringValue = "test string value";
122    private final java.util.Date JavaDoc utilDateValue = new java.util.Date JavaDoc(1111);
123    private final java.sql.Date JavaDoc sqlDateValue;
124    private final Time JavaDoc timeValue;
125    private final Timestamp JavaDoc timestampValue = new Timestamp JavaDoc(4444);
126    private final BigDecimal JavaDoc bigDecimalValue = new BigDecimal JavaDoc("12345678.1234");
127    private final byte[] byteArrayValue = "byte array test".getBytes();
128    private final Object JavaDoc objectValue;
129    private final ValueClass valueClass = new ValueClass(111, 999);
130    private final Hashtable JavaDoc hashtable = new Hashtable JavaDoc();
131
132    public void testBooleanPrimitive() throws Exception JavaDoc
133    {
134       assertEquals(booleanPrimitive, simple.getBooleanPrimitive());
135    }
136
137    public void testBooleanObject() throws Exception JavaDoc
138    {
139       assertEquals(booleanObject, simple.getBooleanObject());
140    }
141
142    public void testBytePrimitive() throws Exception JavaDoc
143    {
144       assertEquals(bytePrimitive, simple.getBytePrimitive());
145    }
146
147    public void testByteObject() throws Exception JavaDoc
148    {
149       assertEquals(byteObject, simple.getByteObject());
150    }
151
152    public void testShortPrimitive() throws Exception JavaDoc
153    {
154       assertEquals(shortPrimitive, simple.getShortPrimitive());
155    }
156
157    public void testShortObject() throws Exception JavaDoc
158    {
159       assertEquals(shortObject, simple.getShortObject());
160    }
161
162    public void testIntegerPrimitive() throws Exception JavaDoc
163    {
164       assertEquals(integerPrimitive, simple.getIntegerPrimitive());
165    }
166
167    public void testIntegerObject() throws Exception JavaDoc
168    {
169       assertEquals(integerObject, simple.getIntegerObject());
170    }
171
172    public void testLongPrimitive() throws Exception JavaDoc
173    {
174       assertEquals(longPrimitive, simple.getLongPrimitive());
175    }
176
177    public void testLongObject() throws Exception JavaDoc
178    {
179       assertEquals(longObject, simple.getLongObject());
180    }
181
182    public void testFloatPrimitive() throws Exception JavaDoc
183    {
184       assertEquals(floatPrimitive, simple.getFloatPrimitive(), 0);
185    }
186
187    public void testFloatObject() throws Exception JavaDoc
188    {
189       assertEquals(floatObject, simple.getFloatObject());
190    }
191
192    public void testDoublePrimitive() throws Exception JavaDoc
193    {
194       assertEquals(doublePrimitive, simple.getDoublePrimitive(), 0);
195    }
196
197    public void testDoubleObject() throws Exception JavaDoc
198    {
199       assertEquals(doubleObject, simple.getDoubleObject());
200    }
201
202    public void testStringValue() throws Exception JavaDoc
203    {
204       assertEquals(stringValue, simple.getStringValue());
205    }
206
207    public void testUtilDateValue() throws Exception JavaDoc
208    {
209       assertTrue(
210          "expected :<" + simple.getUtilDateValue() + "> but was <" +
211          utilDateValue + ">",
212          utilDateValue.compareTo(simple.getUtilDateValue()) == 0);
213    }
214
215    public void testSqlDateValue() throws Exception JavaDoc
216    {
217       assertTrue(
218          "expected :<" + simple.getSqlDateValue() + "> but was <" +
219          sqlDateValue + ">",
220          sqlDateValue.compareTo(simple.getSqlDateValue()) == 0);
221    }
222
223    public void testTimeValue() throws Exception JavaDoc
224    {
225       assertTrue(
226          "expected :<" + simple.getTimeValue() + "> but was <" +
227          timeValue + ">",
228          timeValue.compareTo(simple.getTimeValue()) == 0);
229    }
230
231    public void testTimestampValue() throws Exception JavaDoc
232    {
233       assertTrue(
234          "expected :<" + simple.getTimestampValue() + "> but was <" +
235          timestampValue + ">",
236          timestampValue.compareTo(simple.getTimestampValue()) == 0);
237    }
238
239    public void testBigDecimalValue() throws Exception JavaDoc
240    {
241       assertTrue(
242          "expected :<" + simple.getBigDecimalValue() + "> but was <" +
243          bigDecimalValue + ">",
244          bigDecimalValue.compareTo(simple.getBigDecimalValue()) == 0);
245    }
246
247    public void testByteArrayValue() throws Exception JavaDoc
248    {
249       byte[] array = simple.getByteArrayValue();
250       assertEquals(byteArrayValue.length, array.length);
251       for (int i = 0; i < array.length; i++)
252       {
253          assertEquals(byteArrayValue[i], array[i]);
254       }
255    }
256
257    public void testValueClass() throws Exception JavaDoc
258    {
259       ValueClass vc = simple.getValueClass();
260       log.info("getValueClass class: " + vc.getClass().getName());
261       log.info("getValueClass classloader: " + vc.getClass().getClassLoader());
262       log.info("ValueClass class: " + valueClass.getClass().getName());
263       log.info("ValueClass classloader: " + valueClass.getClass().getClassLoader());
264       assertEquals(valueClass, vc);
265    }
266
267    public void testObjectValue() throws Exception JavaDoc
268    {
269       Object JavaDoc v = simple.getObjectValue();
270       log.info("getObjectValue class: " + v.getClass().getName());
271       log.info("getObjectValue classloader: " + v.getClass().getClassLoader());
272       log.info("objectValue class: " + objectValue.getClass().getName());
273       log.info("objectValue classloader: " + objectValue.getClass().getClassLoader());
274       assertEquals(objectValue, v);
275    }
276
277    public void testLiteralToLiteral() throws Exception JavaDoc
278    {
279       SimpleHome simpleHome = getSimpleHome();
280       Collection JavaDoc c;
281
282       c = simpleHome.selectDynamic(
283          "SELECT OBJECT(s) " +
284          "FROM simple s " +
285          "WHERE TRUE=TRUE",
286          new Object JavaDoc[0]);
287       assertTrue(c.size() == 1);
288
289       c = simpleHome.selectDynamic(
290          "SELECT OBJECT(s) " +
291          "FROM simple s " +
292          "WHERE 1.2=1.2",
293          new Object JavaDoc[0]);
294       assertTrue(c.size() == 1);
295
296       c = simpleHome.selectDynamic(
297          "SELECT OBJECT(s) " +
298          "FROM simple s " +
299          "WHERE 'funk'='funk'",
300          new Object JavaDoc[0]);
301       assertTrue(c.size() == 1);
302    }
303
304    public void testUtilDateBetween() throws Exception JavaDoc
305    {
306       SimpleHome simpleHome = getSimpleHome();
307       Collection JavaDoc c;
308
309       java.util.Date JavaDoc utilDateBefore = new java.util.Date JavaDoc(100);
310       java.util.Date JavaDoc utilDateAfter = new java.util.Date JavaDoc(2000);
311       c = simpleHome.selectDynamic(
312          "SELECT OBJECT(s) " +
313          "FROM simple s " +
314          "WHERE s.utilDateValue BETWEEN ?1 AND ?2",
315          new Object JavaDoc[]{utilDateBefore, utilDateAfter});
316       assertTrue(c.size() == 1);
317    }
318
319    public void testSQLDateBetween() throws Exception JavaDoc
320    {
321       SimpleHome simpleHome = getSimpleHome();
322       Collection JavaDoc c;
323       Calendar JavaDoc calendar;
324
325       calendar = Calendar.getInstance();
326       calendar.clear(); // Must clear time components
327
calendar.set(1981, 4, 3);
328       java.sql.Date JavaDoc sqlDateBefore =
329          new java.sql.Date JavaDoc(calendar.getTime().getTime());
330
331       calendar = Calendar.getInstance();
332       calendar.clear(); // Must clear time components
333
calendar.set(1981, 4, 6);
334       java.sql.Date JavaDoc sqlDateAfter =
335          new java.sql.Date JavaDoc(calendar.getTime().getTime());
336
337       c = simpleHome.selectDynamic(
338          "SELECT OBJECT(s) " +
339          "FROM simple s " +
340          "WHERE s.sqlDateValue BETWEEN ?1 AND ?2",
341          new Object JavaDoc[]{sqlDateBefore, sqlDateAfter});
342       assertTrue(c.size() == 1);
343    }
344
345    public void testTimeBetween() throws Exception JavaDoc
346    {
347       SimpleHome simpleHome = getSimpleHome();
348       Collection JavaDoc c;
349       Calendar JavaDoc calendar;
350
351       calendar = Calendar.getInstance();
352       calendar.clear(); // Must set date components to epoch
353
calendar.set(Calendar.HOUR_OF_DAY, 21);
354       calendar.set(Calendar.MINUTE, 33);
355       calendar.set(Calendar.SECOND, 44);
356       // java.sql.Time does not have a millisecond component
357
Time JavaDoc timeBefore = new java.sql.Time JavaDoc(calendar.getTime().getTime());
358
359       calendar = Calendar.getInstance();
360       calendar.clear(); // Must set date components to epoch
361
calendar.set(Calendar.HOUR_OF_DAY, 23);
362       calendar.set(Calendar.MINUTE, 33);
363       calendar.set(Calendar.SECOND, 44);
364       // java.sql.Time does not have a millisecond component
365
Time JavaDoc timeAfter = new java.sql.Time JavaDoc(calendar.getTime().getTime());
366
367       c = simpleHome.selectDynamic(
368          "SELECT OBJECT(s) " +
369          "FROM simple s " +
370          "WHERE s.timeValue BETWEEN ?1 AND ?2",
371          new Object JavaDoc[]{timeBefore, timeAfter});
372       assertTrue(c.size() == 1);
373
374    }
375
376    public void testTimestampBetween() throws Exception JavaDoc
377    {
378       SimpleHome simpleHome = getSimpleHome();
379       Collection JavaDoc c;
380
381       Timestamp JavaDoc timestampBefore = new Timestamp JavaDoc(1111);
382       Timestamp JavaDoc timestampAfter = new Timestamp JavaDoc(8888);
383       c = simpleHome.selectDynamic(
384          "SELECT OBJECT(s) " +
385          "FROM simple s " +
386          "WHERE s.timestampValue BETWEEN ?1 AND ?2",
387          new Object JavaDoc[]{timestampBefore, timestampAfter});
388       assertTrue(c.size() == 1);
389    }
390
391    public void testTimestampComparison() throws Exception JavaDoc
392    {
393       SimpleHome simpleHome = getSimpleHome();
394       Collection JavaDoc c;
395
396       Timestamp JavaDoc timestampBefore = new Timestamp JavaDoc(1111);
397       Timestamp JavaDoc timestampAfter = new Timestamp JavaDoc(8888);
398       c = simpleHome.selectDynamic(
399          "SELECT OBJECT(s) " +
400          "FROM simple s " +
401          "WHERE s.timestampValue >= ?1 AND s.timestampValue <= ?2",
402          new Object JavaDoc[]{timestampBefore, timestampAfter});
403       assertTrue(c.size() == 1);
404    }
405
406    public void testTimestampIn() throws Exception JavaDoc
407    {
408       SimpleHome simpleHome = getSimpleHome();
409       Collection JavaDoc c;
410
411       Timestamp JavaDoc timestampBefore = new Timestamp JavaDoc(1111);
412       Timestamp JavaDoc timestampAfter = new Timestamp JavaDoc(8888);
413       c = simpleHome.selectDynamic(
414          "SELECT OBJECT(s) " +
415          "FROM simple s " +
416          "WHERE s.timestampValue IN(?1, ?2, ?3)",
417          new Object JavaDoc[]{timestampBefore, timestampAfter, timestampValue});
418       assertTrue(c.size() == 1);
419    }
420
421
422    public void testStringBetween() throws Exception JavaDoc
423    {
424       SimpleHome simpleHome = getSimpleHome();
425       Collection JavaDoc c;
426
427       c = simpleHome.selectDynamic(
428          "SELECT OBJECT(s) " +
429          "FROM simple s " +
430          "WHERE UCASE(s.stringValue) BETWEEN UCASE(?1) AND UCASE(?2)",
431          new Object JavaDoc[]{"aaaaa", "zzzzz"});
432       assertTrue(c.size() == 1);
433    }
434
435    public void testStringComparison() throws Exception JavaDoc
436    {
437       SimpleHome simpleHome = getSimpleHome();
438       Collection JavaDoc c;
439
440       c = simpleHome.selectDynamic(
441          "SELECT OBJECT(s) " +
442          "FROM simple s " +
443          "WHERE UCASE(s.stringValue) >= UCASE(?1) AND " +
444          " UCASE(s.stringValue) <= UCASE(?2)",
445          new Object JavaDoc[]{"aaaaa", "zzzzz"});
446       assertTrue(c.size() == 1);
447    }
448
449    public void testStringIn() throws Exception JavaDoc
450    {
451       SimpleHome simpleHome = getSimpleHome();
452       Collection JavaDoc c;
453
454       c = simpleHome.selectDynamic(
455          "SELECT OBJECT(s) " +
456          "FROM simple s " +
457          "WHERE UCASE(s.stringValue) IN(UCASE(?1), UCASE(?2), " +
458          " UCASE('" + stringValue + "'))",
459          new Object JavaDoc[]{"aaaaa", "zzzzz"});
460       assertTrue(c.size() == 1);
461    }
462
463    public void testLike() throws Exception JavaDoc
464    {
465       SimpleHome simpleHome = getSimpleHome();
466       Collection JavaDoc c;
467
468       c = simpleHome.selectDynamic(
469          "SELECT OBJECT(s) " +
470          "FROM simple s " +
471          "WHERE UCASE(s.stringValue) LIKE UCASE(?1)",
472          new Object JavaDoc[]{"% string %"});
473       assertTrue(c.size() == 1);
474    }
475
476    public void testNumericIn() throws Exception JavaDoc
477    {
478       SimpleHome simpleHome = getSimpleHome();
479       Collection JavaDoc c;
480
481       c = simpleHome.selectDynamic(
482          "SELECT OBJECT(s) " +
483          "FROM simple s " +
484          "WHERE SQRT(s.longPrimitive) " +
485          " IN(SQRT(?1), SQRT(?2), SQRT( " + longPrimitive + " ) )",
486          new Object JavaDoc[]{new Long JavaDoc(23094), new Long JavaDoc(20984)});
487       assertTrue(c.size() == 1);
488    }
489
490    public void testNumbericComparison() throws Exception JavaDoc
491    {
492       SimpleHome simpleHome = getSimpleHome();
493       Collection JavaDoc c;
494
495       c = simpleHome.selectDynamic(
496          "SELECT OBJECT(s) " +
497          "FROM simple s " +
498          "WHERE SQRT(s.longPrimitive) >= SQRT(?1) AND " +
499          " SQRT(s.longPrimitive) <= SQRT(?2)",
500          new Object JavaDoc[]{new Long JavaDoc(22), new Long JavaDoc(20984)});
501       assertTrue(c.size() == 1);
502    }
503
504    public void testConcatFunction() throws Exception JavaDoc
505    {
506       SimpleHome simpleHome = getSimpleHome();
507       Collection JavaDoc c;
508
509       c = simpleHome.selectDynamic(
510          "SELECT OBJECT(s) " +
511          "FROM simple s " +
512          "WHERE CONCAT(?1, ?2) = ?3",
513          new Object JavaDoc[]{
514             "foo",
515             "bar",
516             "foobar"}
517       );
518       assertTrue(c.size() == 1);
519    }
520
521    public void testLengthFunction() throws Exception JavaDoc
522    {
523       SimpleHome simpleHome = getSimpleHome();
524       Collection JavaDoc c;
525
526       c = simpleHome.selectDynamic(
527          "SELECT OBJECT(s) " +
528          "FROM simple s " +
529          "WHERE LENGTH(?1) = ?2",
530          new Object JavaDoc[]{
531             "12345",
532             new Integer JavaDoc(5)}
533       );
534       assertTrue(c.size() == 1);
535    }
536
537    public void testSelectValueClass() throws Exception JavaDoc
538    {
539       SimpleHome simpleHome = getSimpleHome();
540       Collection JavaDoc c = simpleHome.selectValueClass();
541       assertEquals(1, c.size());
542
543       ValueClass v = (ValueClass) c.iterator().next();
544       assertEquals(valueClass, v);
545    }
546
547    public void testLocateFunction() throws Exception JavaDoc
548    {
549       SimpleHome simpleHome = getSimpleHome();
550       Collection JavaDoc c;
551
552       c = simpleHome.selectDynamic(
553          "SELECT OBJECT(s) " +
554          "FROM simple s " +
555          "WHERE LOCATE(?1, ?2, ?3) = ?4",
556          new Object JavaDoc[]{
557             "x",
558             "1x34x67x90",
559             new Integer JavaDoc(3),
560             new Integer JavaDoc(5)}
561       );
562       assertTrue(c.size() == 1);
563
564       c = simpleHome.selectDynamic(
565          "SELECT OBJECT(s) " +
566          "FROM simple s " +
567          "WHERE LOCATE(?1, ?2) = ?3",
568          new Object JavaDoc[]{
569             "x",
570             "1x34x67x90",
571             new Integer JavaDoc(2)}
572       );
573       assertTrue(c.size() == 1);
574
575       c = simpleHome.selectDynamic(
576          "SELECT OBJECT(s) " +
577          "FROM simple s " +
578          "WHERE LOCATE(?1, ?2, ?3) = ?4",
579          new Object JavaDoc[]{
580             "z",
581             "1x34x67x90",
582             new Integer JavaDoc(3),
583             new Integer JavaDoc(0)}
584       );
585       assertTrue(c.size() == 1);
586    }
587    
588    /* Uncomment when we upgrade to Hypersonic 1.7
589    public void testSubstringFunction() throws Exception
590    {
591       SimpleHome simpleHome = getSimpleHome();
592       Collection c;
593
594       c = simpleHome.selectDynamic(
595             "SELECT OBJECT(s) " +
596             "FROM simple s " +
597             "WHERE SUBSTRING(?1, ?2, ?3) = ?4",
598             new Object[]{
599                "1234587890",
600                new Integer(5),
601                new Integer(3),
602                "567"}
603             );
604       assertTrue(c.size() == 1);
605
606       c = simpleHome.selectDynamic(
607             "SELECT OBJECT(s) " +
608             "FROM simple s " +
609             "WHERE SUBSTRING(?1, ?2) = ?3",
610             new Object[]{
611                "1234587890",
612                new Integer(5),
613                "567890"}
614             );
615       assertTrue(c.size() == 1);
616    }
617    */

618
619    public void testFindWithByteArray() throws Exception JavaDoc
620    {
621       SimpleHome simpleHome = getSimpleHome();
622       Collection JavaDoc c = simpleHome.findWithByteArray(byteArrayValue);
623       assertEquals(1, c.size());
624
625       Simple s = (Simple) c.iterator().next();
626       assertTrue(s.isIdentical(simple));
627
628       assertEquals(booleanPrimitive, s.getBooleanPrimitive());
629       assertEquals(booleanObject, s.getBooleanObject());
630       assertEquals(bytePrimitive, s.getBytePrimitive());
631       assertEquals(byteObject, s.getByteObject());
632       assertEquals(shortPrimitive, s.getShortPrimitive());
633       assertEquals(shortObject, s.getShortObject());
634       assertEquals(integerPrimitive, s.getIntegerPrimitive());
635       assertEquals(integerObject, s.getIntegerObject());
636       assertEquals(longPrimitive, s.getLongPrimitive());
637       assertEquals(longObject, s.getLongObject());
638       assertEquals(floatPrimitive, s.getFloatPrimitive(), 0);
639       assertEquals(floatObject, s.getFloatObject());
640       assertEquals(doublePrimitive, s.getDoublePrimitive(), 0);
641       assertEquals(doubleObject, s.getDoubleObject());
642       assertEquals(stringValue, s.getStringValue());
643       assertTrue(
644          "expected :<" + simple.getUtilDateValue() + "> but was <" +
645          utilDateValue + ">",
646          utilDateValue.compareTo(simple.getUtilDateValue()) == 0);
647       assertTrue(
648          "expected :<" + simple.getSqlDateValue() + "> but was <" +
649          sqlDateValue + ">",
650          sqlDateValue.compareTo(simple.getSqlDateValue()) == 0);
651       assertTrue(
652          "expected :<" + simple.getTimeValue() + "> but was <" +
653          timeValue + ">",
654          timeValue.compareTo(simple.getTimeValue()) == 0);
655       assertTrue(
656          "expected :<" + simple.getTimestampValue() + "> but was <" +
657          timestampValue + ">",
658          timestampValue.compareTo(simple.getTimestampValue()) == 0);
659       assertTrue(
660          "expected :<" + simple.getBigDecimalValue() + "> but was <" +
661          bigDecimalValue + ">",
662          bigDecimalValue.compareTo(simple.getBigDecimalValue()) == 0);
663
664       byte[] array = simple.getByteArrayValue();
665       assertEquals(byteArrayValue.length, array.length);
666       for (int i = 0; i < array.length; i++)
667       {
668          assertEquals(byteArrayValue[i], array[i]);
669       }
670
671       assertEquals(valueClass, simple.getValueClass());
672       assertEquals(objectValue, simple.getObjectValue());
673    }
674
675    public void testDuplicateKey() throws Exception JavaDoc
676    {
677       try
678       {
679          SimpleHome simpleHome = getSimpleHome();
680          simpleHome.create("simple");
681          fail("Did not get DuplicateKeyException");
682       }
683       catch (DuplicateKeyException JavaDoc e)
684       {
685          // OK
686
}
687    }
688
689    public void testHashtable() throws Exception JavaDoc
690    {
691       simple.addToHashtable("key1", "value1");
692       simple.addToHashtable("key2", "value2");
693       Hashtable JavaDoc result = simple.getHashtable();
694       assertEquals(2, result.size());
695    }
696
697    public void testOptionAUpdate() throws Exception JavaDoc
698    {
699       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
700       SimpleHome home = (SimpleHome) ctx.lookup("cmp2/simple/SimpleA");
701       Simple simpleA = null;
702       try
703       {
704          simpleA = home.findByPrimaryKey("simpleA");
705       }
706       catch (Exception JavaDoc e)
707       {
708          simpleA = home.create("simpleA");
709       }
710
711       simpleA.setIntegerPrimitive(47);
712       int i = simpleA.getIntegerPrimitive();
713       assertTrue("i == 47 ", i == 47);
714    }
715
716    public void setUpEJB(Properties JavaDoc props) throws Exception JavaDoc
717    {
718       SimpleHome simpleHome = getSimpleHome();
719
720       boolean wasCreated = false;
721       try
722       {
723          simple = simpleHome.findByPrimaryKey("simple");
724       }
725       catch (Exception JavaDoc e)
726       {
727       }
728
729       if (simple == null)
730       {
731          simple = simpleHome.create("simple");
732          wasCreated = true;
733       }
734
735       simple.setBooleanPrimitive(booleanPrimitive);
736       simple.setBooleanObject(booleanObject);
737       simple.setBytePrimitive(bytePrimitive);
738       simple.setByteObject(byteObject);
739       simple.setShortPrimitive(shortPrimitive);
740       simple.setShortObject(shortObject);
741       simple.setIntegerPrimitive(integerPrimitive);
742       simple.setIntegerObject(integerObject);
743       simple.setLongPrimitive(longPrimitive);
744       simple.setLongObject(longObject);
745       simple.setFloatPrimitive(floatPrimitive);
746       simple.setFloatObject(floatObject);
747       simple.setDoublePrimitive(doublePrimitive);
748       simple.setDoubleObject(doubleObject);
749       simple.setStringValue(stringValue);
750       simple.setUtilDateValue(utilDateValue);
751       simple.setSqlDateValue(sqlDateValue);
752       simple.setTimeValue(timeValue);
753       simple.setTimestampValue(timestampValue);
754       if (wasCreated)
755       {
756          simple.setBigDecimalValue(bigDecimalValue);
757          simple.setByteArrayValue(byteArrayValue);
758          simple.setObjectValue(objectValue);
759          simple.setValueClass(valueClass);
760          simple.setHashtable(hashtable);
761       }
762    }
763
764    public void tearDownEJB(Properties JavaDoc props) throws Exception JavaDoc
765    {
766       simple.remove();
767    }
768 }
769
Popular Tags