001: package org.apache.ojb.soda;
002:
003: import junit.framework.TestCase;
004: import org.apache.ojb.broker.Article;
005: import org.apache.ojb.broker.PBFactoryException;
006: import org.apache.ojb.broker.PersistenceBroker;
007: import org.apache.ojb.broker.PersistenceBrokerFactory;
008: import org.apache.ojb.broker.query.Criteria;
009: import org.apache.ojb.broker.query.QueryFactory;
010: import org.apache.ojb.broker.util.logging.Logger;
011: import org.apache.ojb.broker.util.logging.LoggerFactory;
012: import org.odbms.ObjectSet;
013: import org.odbms.Query;
014:
015: /**
016: * Insert the type's description here.
017: * Creation date: (06.12.2000 21:47:56)
018: * @author Thomas Mahler
019: */
020: public class SodaExamples extends TestCase {
021: PersistenceBroker broker;
022:
023: private static Class CLASS = SodaExamples.class;
024:
025: private Logger logger;
026:
027: /**
028: * BrokerTests constructor comment.
029: * @param name java.lang.String
030: */
031: public SodaExamples(String name)
032:
033: {
034: super (name);
035: logger = LoggerFactory.getLogger("soda");
036: }
037:
038: /**
039: * Insert the method's description here.
040: * Creation date: (23.12.2000 18:30:38)
041: * @param args java.lang.String[]
042: */
043: public static void main(String[] args) {
044: String[] arr = { CLASS.getName() };
045: junit.textui.TestRunner.main(arr);
046: }
047:
048: /**
049: * Insert the method's description here.
050: * Creation date: (06.12.2000 21:58:53)
051: */
052: public void setUp() throws PBFactoryException {
053: broker = PersistenceBrokerFactory.defaultPersistenceBroker();
054: }
055:
056: /**
057: * Insert the method's description here.
058: * Creation date: (06.12.2000 21:59:14)
059: */
060: public void tearDown() {
061: broker.close();
062: }
063:
064: protected org.apache.ojb.broker.query.Query ojbQuery() {
065: Criteria crit = null;
066: org.apache.ojb.broker.query.Query q = QueryFactory.newQuery(
067: Article.class, crit);
068: return q;
069: }
070:
071: /**
072: * Insert the method's description here.
073: * Creation date: (06.12.2000 21:51:22)
074: */
075: public void testWithFakedQuery() {
076: try {
077: Query q = broker.query();
078: // we are faking a soda query here:
079: ((QueryImpl) q).setOjbQuery(ojbQuery());
080: int limit = 13;
081: q.limitSize(limit);
082: ObjectSet oSet = q.execute();
083: logger.info("Size of ObjectSet: " + oSet.size());
084: assertEquals(limit, oSet.size());
085: int count = 0;
086: while (oSet.hasNext()) {
087: count++;
088: oSet.next();
089: }
090: assertEquals(limit, count);
091: oSet.reset();
092: count = 0;
093: while (oSet.hasNext()) {
094: count++;
095: oSet.next();
096: }
097: assertEquals(limit, count);
098:
099: } catch (Throwable t) {
100: logger.error(t);
101: fail(t.getMessage());
102: }
103: }
104:
105: /**
106: * Insert the method's description here.
107: * Creation date: (06.12.2000 21:51:22)
108: */
109: public void testWithFakedQueryPreEmpt() {
110: try {
111: Query q = broker.query();
112: // we are faking a soda query here:
113: ((QueryImpl) q).setOjbQuery(ojbQuery());
114: int limit = 13;
115: q.limitSize(limit);
116: ObjectSet oSet = q.execute();
117: logger.info("Size of ObjectSet: " + oSet.size());
118: assertEquals(limit, oSet.size());
119: int count = 0;
120: for (int i = 0; i < 7; i++) {
121: count++;
122: oSet.next();
123: }
124: oSet.reset();
125: count = 0;
126: while (oSet.hasNext()) {
127: count++;
128: oSet.next();
129: }
130: assertEquals(limit, count);
131:
132: } catch (Throwable t) {
133: logger.error(t);
134: fail(t.getMessage());
135: }
136: }
137:
138: /**
139: * Insert the method's description here.
140: * Creation date: (06.12.2000 21:51:22)
141: */
142: public void testWithFakedQueryPreEmptUnlimited() {
143: try {
144: Query q = broker.query();
145: // we are faking a soda query here:
146: ((QueryImpl) q).setOjbQuery(ojbQuery());
147:
148: ObjectSet oSet = q.execute();
149: logger.info("Size of ObjectSet: " + oSet.size());
150:
151: int count = 0;
152: for (int i = 0; i < 7; i++) {
153: count++;
154: oSet.next();
155: }
156: oSet.reset();
157: count = 0;
158: while (oSet.hasNext()) {
159: count++;
160: oSet.next();
161: }
162: assertEquals(oSet.size(), count);
163:
164: } catch (Throwable t) {
165: logger.error(t);
166: fail(t.getMessage());
167: }
168: }
169:
170: }
|