Source Code Cross Referenced for EvolveTestBase.java in  » JMX » je » com » sleepycat » persist » test » 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 » JMX » je » com.sleepycat.persist.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2000,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: EvolveTestBase.java,v 1.5.2.7 2008/01/07 15:14:35 cwl Exp $
007:         */
008:        package com.sleepycat.persist.test;
009:
010:        import java.io.File;
011:        import java.util.Enumeration;
012:
013:        import junit.framework.TestCase;
014:        import junit.framework.TestSuite;
015:
016:        import com.sleepycat.je.DatabaseException;
017:        import com.sleepycat.je.Environment;
018:        import com.sleepycat.je.EnvironmentConfig;
019:        import com.sleepycat.persist.EntityStore;
020:        import com.sleepycat.persist.StoreConfig;
021:        import com.sleepycat.persist.model.AnnotationModel;
022:        import com.sleepycat.persist.model.EntityModel;
023:        import com.sleepycat.persist.raw.RawStore;
024:
025:        /**
026:         * Base class for EvolveTest and EvolveTestInit.
027:         *
028:         * @author Mark Hayes
029:         */
030:        public abstract class EvolveTestBase extends TestCase {
031:
032:            /*
033:             * When adding a evolve test class, three places need to be changed:
034:             * 1) Add the unmodified class to EvolveClass.java.original.
035:             * 2) Add the modified class to EvolveClass.java.
036:             * 3) Add the class name to the ALL list below as a pair of strings.  The
037:             * first string in each pair is the name of the original class, and the
038:             * second string is the name of the evolved class or null if the evolved
039:             * name is the same as the original.  The index in the list identifies a
040:             * test case, and the class at that position identifies the old and new
041:             * class to use for the test.
042:             */
043:            private static final String[] ALL = {
044:                    "DeletedEntity1_ClassRemoved",
045:                    "DeletedEntity1_ClassRemoved_NoMutation",
046:                    "DeletedEntity2_ClassRemoved",
047:                    "DeletedEntity2_ClassRemoved_WithDeleter",
048:                    "DeletedEntity3_AnnotRemoved_NoMutation", null,
049:                    "DeletedEntity4_AnnotRemoved_WithDeleter", null,
050:                    "DeletedEntity5_EntityToPersist_NoMutation", null,
051:                    "DeletedEntity6_EntityToPersist_WithDeleter", null,
052:                    "DeletedPersist1_ClassRemoved_NoMutation", null,
053:                    "DeletedPersist2_ClassRemoved_WithDeleter", null,
054:                    "DeletedPersist3_AnnotRemoved_NoMutation", null,
055:                    "DeletedPersist4_AnnotRemoved_WithDeleter", null,
056:                    "DeletedPersist5_PersistToEntity_NoMutation", null,
057:                    "DeletedPersist6_PersistToEntity_WithDeleter", null,
058:                    "RenamedEntity1_NewEntityName",
059:                    "RenamedEntity1_NewEntityName_NoMutation",
060:                    "RenamedEntity2_NewEntityName",
061:                    "RenamedEntity2_NewEntityName_WithRenamer",
062:                    "DeleteSuperclass1_NoMutation", null,
063:                    "DeleteSuperclass2_WithConverter", null,
064:                    "DeleteSuperclass3_WithDeleter", null,
065:                    "DeleteSuperclass4_NoFields", null,
066:                    "DeleteSuperclass5_Top", null, "InsertSuperclass1_Between",
067:                    null, "InsertSuperclass2_Top", null,
068:                    "DisallowNonKeyField_PrimitiveToObject", null,
069:                    "DisallowNonKeyField_ObjectToPrimitive", null,
070:                    "DisallowNonKeyField_ObjectToSubtype", null,
071:                    "DisallowNonKeyField_ObjectToUnrelatedSimple", null,
072:                    "DisallowNonKeyField_ObjectToUnrelatedOther", null,
073:                    "DisallowNonKeyField_byte2boolean", null,
074:                    "DisallowNonKeyField_short2byte", null,
075:                    "DisallowNonKeyField_int2short", null,
076:                    "DisallowNonKeyField_long2int", null,
077:                    "DisallowNonKeyField_float2long", null,
078:                    "DisallowNonKeyField_double2float", null,
079:                    "DisallowNonKeyField_Byte2byte", null,
080:                    "DisallowNonKeyField_Character2char", null,
081:                    "DisallowNonKeyField_Short2short", null,
082:                    "DisallowNonKeyField_Integer2int", null,
083:                    "DisallowNonKeyField_Long2long", null,
084:                    "DisallowNonKeyField_Float2float", null,
085:                    "DisallowNonKeyField_Double2double", null,
086:                    "DisallowNonKeyField_float2BigInt", null,
087:                    "DisallowNonKeyField_BigInt2long", null,
088:                    "DisallowSecKeyField_byte2short", null,
089:                    "DisallowSecKeyField_char2int", null,
090:                    "DisallowSecKeyField_short2int", null,
091:                    "DisallowSecKeyField_int2long", null,
092:                    "DisallowSecKeyField_long2float", null,
093:                    "DisallowSecKeyField_float2double", null,
094:                    "DisallowSecKeyField_Byte2short2", null,
095:                    "DisallowSecKeyField_Character2int", null,
096:                    "DisallowSecKeyField_Short2int2", null,
097:                    "DisallowSecKeyField_Integer2long", null,
098:                    "DisallowSecKeyField_Long2float2", null,
099:                    "DisallowSecKeyField_Float2double2", null,
100:                    "DisallowSecKeyField_int2BigInt", null,
101:                    "DisallowPriKeyField_byte2short", null,
102:                    "DisallowPriKeyField_char2int", null,
103:                    "DisallowPriKeyField_short2int", null,
104:                    "DisallowPriKeyField_int2long", null,
105:                    "DisallowPriKeyField_long2float", null,
106:                    "DisallowPriKeyField_float2double", null,
107:                    "DisallowPriKeyField_Byte2short2", null,
108:                    "DisallowPriKeyField_Character2int", null,
109:                    "DisallowPriKeyField_Short2int2", null,
110:                    "DisallowPriKeyField_Integer2long", null,
111:                    "DisallowPriKeyField_Long2float2", null,
112:                    "DisallowPriKeyField_Float2double2", null,
113:                    "DisallowPriKeyField_Long2BigInt", null,
114:                    "DisallowCompositeKeyField_byte2short", null,
115:                    "AllowPriKeyField_Byte2byte2", null,
116:                    "AllowPriKeyField_byte2Byte", null,
117:                    "AllowFieldTypeChanges", null, "ConvertExample1_Entity",
118:                    null, "ConvertExample2_Person", null,
119:                    "ConvertExample3_Person", null, "ConvertExample4_Entity",
120:                    null, "ConvertExample5_Entity", null,
121:                    "AllowFieldAddDelete", null, "ProxiedClass_Entity", null,
122:                    "DisallowChangeProxyFor", null, "DisallowDeleteProxyFor",
123:                    null, "ArrayNameChange_Entity", null,
124:                    "AddEnumConstant_Entity", null,
125:                    "DeleteEnumConstant_NoMutation", null,
126:                    "DisallowChangeKeyRelate", null, "AllowChangeKeyMetadata",
127:                    null, "AllowAddSecondary", null, "FieldAddAndConvert",
128:                    null, };
129:
130:            File envHome;
131:            Environment env;
132:            EntityStore store;
133:            RawStore rawStore;
134:            EntityStore newStore;
135:            String caseClsName;
136:            Class caseCls;
137:            EvolveCase caseObj;
138:            String caseLabel;
139:
140:            static TestSuite getSuite(Class testClass) throws Exception {
141:
142:                TestSuite suite = new TestSuite();
143:                for (int i = 0; i < ALL.length; i += 2) {
144:                    String originalClsName = ALL[i];
145:                    String evolvedClsName = ALL[i + 1];
146:                    if (evolvedClsName == null) {
147:                        evolvedClsName = originalClsName;
148:                    }
149:                    TestSuite baseSuite = new TestSuite(testClass);
150:                    Enumeration e = baseSuite.tests();
151:                    while (e.hasMoreElements()) {
152:                        EvolveTestBase test = (EvolveTestBase) e.nextElement();
153:                        test.init(originalClsName, evolvedClsName);
154:                        suite.addTest(test);
155:                    }
156:                }
157:                return suite;
158:            }
159:
160:            private void init(String originalClsName, String evolvedClsName)
161:                    throws Exception {
162:
163:                String caseClsName = useEvolvedClass() ? evolvedClsName
164:                        : originalClsName;
165:                caseClsName = "com.sleepycat.persist.test.EvolveClasses$"
166:                        + caseClsName;
167:
168:                this .caseClsName = caseClsName;
169:                this .caseCls = Class.forName(caseClsName);
170:                this .caseObj = (EvolveCase) caseCls.newInstance();
171:                this .caseLabel = evolvedClsName;
172:            }
173:
174:            abstract boolean useEvolvedClass();
175:
176:            File getTestInitHome(boolean evolved) {
177:                return new File(System.getProperty("testevolvedir"),
178:                        (evolved ? "evolved" : "original") + '/' + caseLabel);
179:            }
180:
181:            @Override
182:            public void tearDown() {
183:
184:                /* Set test name for reporting; cannot be done in the ctor or setUp. */
185:                setName(caseLabel + '-' + getName());
186:
187:                if (env != null) {
188:                    try {
189:                        closeAll();
190:                    } catch (Throwable e) {
191:                        System.out.println("During tearDown: " + e);
192:                    }
193:                }
194:                envHome = null;
195:                env = null;
196:                store = null;
197:                caseCls = null;
198:                caseObj = null;
199:                caseLabel = null;
200:
201:                /* Do not delete log files so they can be used by 2nd phase of test. */
202:            }
203:
204:            void openEnv() throws DatabaseException {
205:
206:                EnvironmentConfig config = new EnvironmentConfig();
207:                config.setAllowCreate(true);
208:                config.setTransactional(true);
209:                env = new Environment(envHome, config);
210:            }
211:
212:            /**
213:             * Returns true if the store was opened successfully.  Returns false if the
214:             * store could not be opened because an exception was expected -- this is
215:             * not a test failure but no further tests for an EntityStore may be run.
216:             */
217:            private boolean openStore(StoreConfig config) throws Exception {
218:
219:                config.setTransactional(true);
220:                config.setMutations(caseObj.getMutations());
221:
222:                EntityModel model = new AnnotationModel();
223:                config.setModel(model);
224:                caseObj.configure(model, config);
225:
226:                String expectException = caseObj.getStoreOpenException();
227:                try {
228:                    store = new EntityStore(env, EvolveCase.STORE_NAME, config);
229:                    if (expectException != null) {
230:                        fail("Expected: " + expectException);
231:                    }
232:                } catch (Exception e) {
233:                    if (expectException != null) {
234:                        //e.printStackTrace();
235:                        EvolveCase.checkEquals(expectException, e.toString());
236:                        return false;
237:                    } else {
238:                        throw e;
239:                    }
240:                }
241:                return true;
242:            }
243:
244:            boolean openStoreReadOnly() throws Exception {
245:
246:                StoreConfig config = new StoreConfig();
247:                config.setReadOnly(true);
248:                return openStore(config);
249:            }
250:
251:            boolean openStoreReadWrite() throws Exception {
252:
253:                StoreConfig config = new StoreConfig();
254:                config.setAllowCreate(true);
255:                return openStore(config);
256:            }
257:
258:            void openRawStore() throws DatabaseException {
259:
260:                rawStore = new RawStore(env, EvolveCase.STORE_NAME, null);
261:            }
262:
263:            void closeStore() throws DatabaseException {
264:
265:                if (store != null) {
266:                    store.close();
267:                    store = null;
268:                }
269:            }
270:
271:            void openNewStore() throws Exception {
272:
273:                StoreConfig config = new StoreConfig();
274:                config.setAllowCreate(true);
275:                config.setTransactional(true);
276:
277:                EntityModel model = new AnnotationModel();
278:                config.setModel(model);
279:                caseObj.configure(model, config);
280:
281:                newStore = new EntityStore(env, "new", config);
282:            }
283:
284:            void closeNewStore() throws DatabaseException {
285:
286:                if (newStore != null) {
287:                    newStore.close();
288:                    newStore = null;
289:                }
290:            }
291:
292:            void closeRawStore() throws DatabaseException {
293:
294:                if (rawStore != null) {
295:                    rawStore.close();
296:                    rawStore = null;
297:                }
298:            }
299:
300:            void closeEnv() throws DatabaseException {
301:
302:                if (env != null) {
303:                    env.close();
304:                    env = null;
305:                }
306:            }
307:
308:            void closeAll() throws DatabaseException {
309:
310:                closeStore();
311:                closeRawStore();
312:                closeNewStore();
313:                closeEnv();
314:            }
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.