KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > soda > SodaExamples


1 package org.apache.ojb.soda;
2
3 import junit.framework.TestCase;
4 import org.apache.ojb.broker.Article;
5 import org.apache.ojb.broker.PBFactoryException;
6 import org.apache.ojb.broker.PersistenceBroker;
7 import org.apache.ojb.broker.PersistenceBrokerFactory;
8 import org.apache.ojb.broker.query.Criteria;
9 import org.apache.ojb.broker.query.QueryFactory;
10 import org.apache.ojb.broker.util.logging.Logger;
11 import org.apache.ojb.broker.util.logging.LoggerFactory;
12 import org.odbms.ObjectSet;
13 import org.odbms.Query;
14
15 /**
16  * Insert the type's description here.
17  * Creation date: (06.12.2000 21:47:56)
18  * @author Thomas Mahler
19  */

20 public class SodaExamples extends TestCase
21 {
22     PersistenceBroker broker;
23
24     private static Class JavaDoc CLASS = SodaExamples.class;
25
26     private Logger logger;
27
28     /**
29      * BrokerTests constructor comment.
30      * @param name java.lang.String
31      */

32     public SodaExamples(String JavaDoc name)
33     
34     {
35         super(name);
36         logger = LoggerFactory.getLogger("soda");
37     }
38
39     /**
40      * Insert the method's description here.
41      * Creation date: (23.12.2000 18:30:38)
42      * @param args java.lang.String[]
43      */

44     public static void main(String JavaDoc[] args)
45     {
46         String JavaDoc[] arr = { CLASS.getName()};
47         junit.textui.TestRunner.main(arr);
48     }
49
50     /**
51      * Insert the method's description here.
52      * Creation date: (06.12.2000 21:58:53)
53      */

54     public void setUp() throws PBFactoryException
55     {
56         broker = PersistenceBrokerFactory.defaultPersistenceBroker();
57     }
58
59     /**
60      * Insert the method's description here.
61      * Creation date: (06.12.2000 21:59:14)
62      */

63     public void tearDown()
64     {
65         broker.close();
66     }
67
68     protected org.apache.ojb.broker.query.Query ojbQuery()
69     {
70         Criteria crit = null;
71         org.apache.ojb.broker.query.Query q = QueryFactory.newQuery(Article.class, crit);
72         return q;
73     }
74
75     /**
76      * Insert the method's description here.
77      * Creation date: (06.12.2000 21:51:22)
78      */

79     public void testWithFakedQuery()
80     {
81         try
82         {
83             Query q = broker.query();
84             // we are faking a soda query here:
85
((QueryImpl) q).setOjbQuery(ojbQuery());
86             int limit = 13;
87             q.limitSize(limit);
88             ObjectSet oSet = q.execute();
89             logger.info("Size of ObjectSet: " + oSet.size());
90             assertEquals(limit,oSet.size());
91             int count = 0;
92             while (oSet.hasNext())
93             {
94                 count++;
95                 oSet.next();
96             }
97             assertEquals(limit, count);
98             oSet.reset();
99             count = 0;
100             while (oSet.hasNext())
101             {
102                 count++;
103                 oSet.next();
104             }
105             assertEquals(limit, count);
106             
107         }
108         catch (Throwable JavaDoc t)
109         {
110             logger.error(t);
111             fail(t.getMessage());
112         }
113     }
114
115     /**
116      * Insert the method's description here.
117      * Creation date: (06.12.2000 21:51:22)
118      */

119     public void testWithFakedQueryPreEmpt()
120     {
121         try
122         {
123             Query q = broker.query();
124             // we are faking a soda query here:
125
((QueryImpl) q).setOjbQuery(ojbQuery());
126             int limit = 13;
127             q.limitSize(limit);
128             ObjectSet oSet = q.execute();
129             logger.info("Size of ObjectSet: " + oSet.size());
130             assertEquals(limit,oSet.size());
131             int count = 0;
132             for (int i=0; i<7; i++)
133             {
134                 count++;
135                 oSet.next();
136             }
137             oSet.reset();
138             count = 0;
139             while (oSet.hasNext())
140             {
141                 count++;
142                 oSet.next();
143             }
144             assertEquals(limit, count);
145             
146         }
147         catch (Throwable JavaDoc t)
148         {
149             logger.error(t);
150             fail(t.getMessage());
151         }
152     }
153
154     /**
155      * Insert the method's description here.
156      * Creation date: (06.12.2000 21:51:22)
157      */

158     public void testWithFakedQueryPreEmptUnlimited()
159     {
160         try
161         {
162             Query q = broker.query();
163             // we are faking a soda query here:
164
((QueryImpl) q).setOjbQuery(ojbQuery());
165             
166             ObjectSet oSet = q.execute();
167             logger.info("Size of ObjectSet: " + oSet.size());
168             
169             int count = 0;
170             for (int i=0; i<7; i++)
171             {
172                 count++;
173                 oSet.next();
174             }
175             oSet.reset();
176             count = 0;
177             while (oSet.hasNext())
178             {
179                 count++;
180                 oSet.next();
181             }
182             assertEquals(oSet.size(), count);
183             
184         }
185         catch (Throwable JavaDoc t)
186         {
187             logger.error(t);
188             fail(t.getMessage());
189         }
190     }
191
192 }
193
Popular Tags