Source Code Cross Referenced for SodaTest.java in  » Database-DBMS » db4o-6.4 » com » db4o » test » legacy » soda » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db4o 6.4 » com.db4o.test.legacy.soda 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.test.legacy.soda;
022:
023:        import java.lang.reflect.*;
024:
025:        import com.db4o.*;
026:        import com.db4o.foundation.*;
027:        import com.db4o.internal.*;
028:        import com.db4o.query.*;
029:        import com.db4o.test.legacy.soda.*;
030:        import com.db4o.test.legacy.soda.arrays.object.*;
031:        import com.db4o.test.legacy.soda.arrays.typed.*;
032:        import com.db4o.test.legacy.soda.arrays.untyped.*;
033:        import com.db4o.test.legacy.soda.classes.simple.*;
034:        import com.db4o.test.legacy.soda.classes.typedhierarchy.*;
035:        import com.db4o.test.legacy.soda.classes.untypedhierarchy.*;
036:        import com.db4o.test.legacy.soda.collections.*;
037:        import com.db4o.test.legacy.soda.deepOR.*;
038:        import com.db4o.test.legacy.soda.engines.db4o.*;
039:        import com.db4o.test.legacy.soda.experiments.*;
040:        import com.db4o.test.legacy.soda.joins.typed.*;
041:        import com.db4o.test.legacy.soda.joins.untyped.*;
042:        import com.db4o.test.legacy.soda.ordered.*;
043:        import com.db4o.test.legacy.soda.wrapper.typed.*;
044:        import com.db4o.test.legacy.soda.wrapper.untyped.*;
045:        import com.db4o.test.util.*;
046:
047:        public class SodaTest {
048:
049:            private static final STEngine[] ENGINES = new STEngine[] { new STDb4o(),
050:            // new STDb4oClientServer()
051:            };
052:
053:            public static final STClass[] CLASSES = new STClass[] {
054:                    new STArrayListT(), new STArrayListU(), new STArrMixed(),
055:                    new STArrStringO(), new STArrStringON(),
056:                    new STArrStringT(), new STArrStringTN(),
057:                    new STArrStringU(), new STArrStringUN(),
058:                    new STArrIntegerO(), new STArrIntegerON(),
059:                    new STArrIntegerT(), new STArrIntegerTN(),
060:                    new STArrIntegerU(), new STArrIntegerUN(),
061:                    new STArrIntegerWT(), new STArrIntegerWTON(),
062:                    new STArrIntegerWUON(), new STBoolean(), new STBooleanWT(),
063:                    new STBooleanWU(), new STByte(), new STByteWT(),
064:                    new STByteWU(), new STCaseInsensitive(), new STChar(),
065:                    new STCharWT(), new STCharWU(), new STDate(),
066:                    new STDateU(), new STDouble(), new STDoubleWT(),
067:                    new STDoubleWU(), new STETH1(), new STFloat(),
068:                    new STFloatWT(), new STFloatWU(), new STHashSetT(),
069:                    new STHashSetU(), new STHashtableD(), new STHashtableED(),
070:                    new STHashtableET(), new STHashtableEU(),
071:                    new STHashtableT(), new STHashtableU(),
072:                    new STIdentityEvaluation(), new STInteger(),
073:                    new STIntegerWT(), new STIntegerWU(), new STLinkedListT(),
074:                    new STLinkedListU(), new STLong(), new STLongWT(),
075:                    new STLongWU(), new STNullOnPath(), new STOrContains(),
076:                    new STOrT(), new STOrU(), new STOString(),
077:                    new STOInteger(), new STOIntegerWT(),
078:                    new STOwnCollectionT(), new STOwnCollectionW(),
079:                    new STRTH1(), new STSDFT1(), new STShort(),
080:                    new STShortWT(), new STShortWU(), new STString(),
081:                    new STStringU(), new STRUH1(), new STTH1(),
082:                    new STTreeSetT(), new STTreeSetU(), new STUH1(),
083:                    new STVectorD(), new STVectorED(), new STVectorT(),
084:                    new STVectorU(), new STVectorET(), new STVectorEU(),
085:
086:                    // Take a look at this one!!!
087:                    new STMagic(), };
088:
089:            protected static final boolean quiet = false;
090:            protected static STEngine engine;
091:            private static int testCases;
092:            private STClass currentTestClass;
093:            protected static Collection4 failedTestClasses = new Collection4();
094:            private final TCompare comparer = new TCompare();
095:            static long time;
096:
097:            public static void main(String[] args) {
098:                time = System.currentTimeMillis();
099:                SodaTest st = new SodaTest();
100:                st.run(CLASSES, ENGINES, quiet);
101:                st.completed();
102:            }
103:
104:            protected void completed() {
105:                time = System.currentTimeMillis() - time;
106:                System.out.println(name() + " completed. " + time + " ms");
107:                System.out.println("Test cases: " + testCases);
108:            }
109:
110:            protected String name() {
111:                return "S.O.D.A. functionality test";
112:            }
113:
114:            protected static void begin() {
115:                failedTestClasses = new Collection4();
116:                testCases = 0;
117:            }
118:
119:            public void run(STClass[] classes, STEngine[] engines,
120:                    boolean a_quiet) {
121:                begin();
122:                setSodaTestOn(classes);
123:
124:                for (int i = 0; i < engines.length; i++) {
125:                    engine = engines[i];
126:                    engine.reset();
127:                    engine.open();
128:                    store(classes);
129:                    engine.commit();
130:                    engine.close();
131:                    engine.open();
132:                    test(classes);
133:                    engine.close();
134:                    engine.reset();
135:                }
136:
137:                if (failedTestClasses.size() > 0) {
138:                    System.err.println("\nFailed test classes:\n");
139:                    Iterator4 i = failedTestClasses.iterator();
140:                    while (i.moveNext()) {
141:                        System.err.println(i.current().getClass().getName());
142:                    }
143:                    System.err.println("\n");
144:                }
145:            }
146:
147:            protected void store(STClass[] classes) {
148:                for (int i = 0; i < classes.length; i++) {
149:                    if (jdkOK(classes[i])) {
150:                        Object[] objects = classes[i].store();
151:                        if (objects != null) {
152:                            for (int j = 0; j < objects.length; j++) {
153:                                engine.store(objects[j]);
154:                            }
155:                        }
156:                    }
157:                }
158:            }
159:
160:            /** dynamic execution of all public methods that begin with "test" in all CLASSES */
161:            protected void test(STClass[] classes) {
162:                for (int i = 0; i < classes.length; i++) {
163:                    if (jdkOK(classes[i])) {
164:                        System.out.println("  S.O.D.A. testing "
165:                                + classes[i].getClass().getName());
166:                        currentTestClass = classes[i];
167:                        Method[] methods = classes[i].getClass()
168:                                .getDeclaredMethods();
169:                        for (int j = 0; j < methods.length; j++) {
170:                            Method method = methods[j];
171:                            if (method.getName().startsWith("test")) {
172:                                try {
173:                                    method.invoke(classes[i], null);
174:                                } catch (Exception e) {
175:                                    e.printStackTrace();
176:                                }
177:                            }
178:                        }
179:                    }
180:                }
181:            }
182:
183:            protected static boolean jdkOK(Object obj) {
184:                return Platform4.jdk().ver() >= 2
185:                        || STClass1.class.isAssignableFrom(obj.getClass());
186:            }
187:
188:            public Query query() {
189:                return engine.query();
190:            }
191:
192:            public void expectOne(Query query, Object object) {
193:                expect(query, new Object[] { object });
194:            }
195:
196:            public void expectNone(Query query) {
197:                expect(query, null);
198:            }
199:
200:            public void expect(Query query, Object[] results) {
201:                expect(query, results, false);
202:            }
203:
204:            public void expectOrdered(Query query, Object[] results) {
205:                expect(query, results, true);
206:            }
207:
208:            private void expect(Query query, Object[] results, boolean ordered) {
209:                testCases++;
210:                ObjectSet set = query.execute();
211:                if (results == null || results.length == 0) {
212:                    if (set.size() > 0) {
213:                        error("No content expected.");
214:                    }
215:                    return;
216:                }
217:                int j = 0;
218:                if (set.size() == results.length) {
219:                    while (set.hasNext()) {
220:                        Object obj = set.next();
221:                        boolean found = false;
222:                        if (ordered) {
223:                            if (comparer.isEqual(results[j], obj)) {
224:                                results[j] = null;
225:                                found = true;
226:                            }
227:                            j++;
228:                        } else {
229:                            for (int i = 0; i < results.length; i++) {
230:                                if (results[i] != null) {
231:                                    if (comparer.isEqual(results[i], obj)) {
232:                                        results[i] = null;
233:                                        found = true;
234:                                        break;
235:                                    }
236:                                }
237:                            }
238:                        }
239:                        if (!found) {
240:                            error("Object not expected: " + obj);
241:                        }
242:                    }
243:                    for (int i = 0; i < results.length; i++) {
244:                        if (results[i] != null) {
245:                            error("Expected object not returned: " + results[i]);
246:                        }
247:                    }
248:                } else {
249:                    error("Unexpected size returned.\nExpected: "
250:                            + results.length + " Returned: " + set.size());
251:                }
252:            }
253:
254:            public void error(String msg) {
255:                if (!failedTestClasses.contains(currentTestClass)) {
256:                    failedTestClasses.add(currentTestClass);
257:                }
258:                if (!quiet) {
259:                    System.err.println(msg);
260:                    new ExpectationFailed().printStackTrace();
261:                    System.err.println();
262:                }
263:            }
264:
265:            public static int failedClassesSize() {
266:                return failedTestClasses.size();
267:            }
268:
269:            public static int testCaseCount() {
270:                return testCases;
271:            }
272:
273:            public void log(Query query) {
274:                ObjectSet set = query.execute();
275:                while (set.hasNext()) {
276:                    TLogger.log(set.next());
277:                }
278:            }
279:
280:            protected void setSodaTestOn(STClass[] classes) {
281:                for (int i = 0; i < classes.length; i++) {
282:                    try {
283:                        Field field = classes[i].getClass().getDeclaredField(
284:                                "st");
285:                        try {
286:                            Platform4.setAccessible(field);
287:                        } catch (Throwable t) {
288:                            // JDK 1.x has no setAccessible
289:                        }
290:                        field.set(classes[i], this );
291:                    } catch (Exception e) {
292:                        System.err.println("Add the following line to Class "
293:                                + classes[i].getClass().getName());
294:                        System.err
295:                                .println("public static transient SodaTest st;");
296:                    }
297:                }
298:            }
299:
300:        }
301:
302:        class ExpectationFailed extends Exception {
303:            ExpectationFailed() {
304:            }
305:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.