KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > TypedCollectionsTest


1 package org.apache.ojb.broker;
2
3 import org.apache.ojb.broker.query.QueryByIdentity;
4 import org.apache.ojb.junit.PBTestCase;
5
6 /** This TestClass tests OJB facilities to work with typed collections.
7  */

8 public class TypedCollectionsTest extends PBTestCase
9 {
10     public static void main(String JavaDoc[] args)
11     {
12         String JavaDoc[] arr = {TypedCollectionsTest.class.getName()};
13         junit.textui.TestRunner.main(arr);
14     }
15
16     public TypedCollectionsTest(String JavaDoc name)
17
18     {
19         super(name);
20     }
21
22     /** Test support for 1-n relations modelled with Arrays*/
23     public void testArray() throws Exception JavaDoc
24     {
25         int i;
26         broker.beginTransaction();
27         for (i = 1; i < 4; i++)
28         {
29             ProductGroupWithArray example = new ProductGroupWithArray();
30             example.setId(i);
31             ProductGroupWithArray group =
32                 (ProductGroupWithArray) broker.getObjectByQuery(new QueryByIdentity(example));
33             assertEquals("should be equal", i, group.getId());
34             //System.out.println(group + "\n\n");
35

36             broker.delete(group);
37             broker.store(group);
38         }
39         broker.commitTransaction();
40     }
41
42     /** TestThreadsNLocks support for modelling 1-n relations with typed collections*/
43     public void testTypedCollection()
44     {
45         broker.beginTransaction();
46         for (int i = 1; i < 4; i++)
47         {
48             ProductGroupWithTypedCollection example = new ProductGroupWithTypedCollection();
49             example.setId(i);
50             ProductGroupWithTypedCollection group =
51                 (ProductGroupWithTypedCollection) broker.getObjectByQuery(
52                     new QueryByIdentity(example));
53             assertEquals("should be equal", i, group.getId());
54             //System.out.println(group + "\n\n");
55

56             broker.delete(group);
57             broker.store(group);
58         }
59         broker.commitTransaction();
60     }
61 }
62
Popular Tags