01: package org.apache.ojb.broker;
02:
03: import org.apache.ojb.broker.query.QueryByIdentity;
04: import org.apache.ojb.junit.PBTestCase;
05:
06: /** This TestClass tests OJB facilities to work with typed collections.
07: */
08: public class TypedCollectionsTest extends PBTestCase {
09: public static void main(String[] args) {
10: String[] arr = { TypedCollectionsTest.class.getName() };
11: junit.textui.TestRunner.main(arr);
12: }
13:
14: public TypedCollectionsTest(String name)
15:
16: {
17: super (name);
18: }
19:
20: /** Test support for 1-n relations modelled with Arrays*/
21: public void testArray() throws Exception {
22: int i;
23: broker.beginTransaction();
24: for (i = 1; i < 4; i++) {
25: ProductGroupWithArray example = new ProductGroupWithArray();
26: example.setId(i);
27: ProductGroupWithArray group = (ProductGroupWithArray) broker
28: .getObjectByQuery(new QueryByIdentity(example));
29: assertEquals("should be equal", i, group.getId());
30: //System.out.println(group + "\n\n");
31:
32: broker.delete(group);
33: broker.store(group);
34: }
35: broker.commitTransaction();
36: }
37:
38: /** TestThreadsNLocks support for modelling 1-n relations with typed collections*/
39: public void testTypedCollection() {
40: broker.beginTransaction();
41: for (int i = 1; i < 4; i++) {
42: ProductGroupWithTypedCollection example = new ProductGroupWithTypedCollection();
43: example.setId(i);
44: ProductGroupWithTypedCollection group = (ProductGroupWithTypedCollection) broker
45: .getObjectByQuery(new QueryByIdentity(example));
46: assertEquals("should be equal", i, group.getId());
47: //System.out.println(group + "\n\n");
48:
49: broker.delete(group);
50: broker.store(group);
51: }
52: broker.commitTransaction();
53: }
54: }
|