001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle.tests;
024:
025: import java.io.*;
026: import junit.framework.*;
027: import java.util.*;
028: import drjava.util.*;
029: import drjava.gjutil.*;
030: import drjava.smyle.*;
031: import drjava.smyle.testtypes.*;
032: import drjava.smyle.core.Disk;
033: import drjava.smyle.core.FileSystemDisk;
034: import drjava.smyle.core.DiskStore;
035: import drjava.smyle.meta.*;
036: import org.artsProject.mcop.core.*;
037: import drjava.gjutil.Factory;
038: import org.artsProject.util.*;
039:
040: class StoreTestBase extends TestCase {
041: Factory<Store> storeCreator, storeOpener;
042: boolean canRotate;
043: Store store;
044: Snapshot snapshot;
045: Table<Person> table;
046:
047: Song constantSorrow = new Song("The Soggy Bottom Boys",
048: "I Am A Man Of Constant Sorrow");
049:
050: static final boolean debug = false;
051:
052: Person john = new Person("John", 23),
053: anne = new Person("Anne", 21),
054: jane = new Person("Jane", 23), oldJohn = new Person("John",
055: 52);
056:
057: static final int male = 0, female = 1;
058:
059: public StoreTestBase(String name) {
060: super (name);
061: }
062:
063: public void init(Factory<Store> storeCreator,
064: Factory<Store> storeOpener, boolean canRotate) {
065: this .storeCreator = storeCreator;
066: this .storeOpener = storeOpener;
067: this .canRotate = canRotate;
068: }
069:
070: public void setUp() throws Exception {
071: createStore(true);
072: }
073:
074: void createStore(boolean wipe) throws Exception {
075: store = (wipe ? storeCreator : storeOpener).produce();
076: getNewSnapshot();
077: }
078:
079: void rotate() throws Exception {
080: if (store != null)
081: store.close();
082: createStore(false);
083: }
084:
085: public void tearDown() throws Exception {
086: if (store != null)
087: store.close();
088: }
089:
090: void getNewSnapshot() throws Exception {
091: snapshot = store.mutableSnapshot();
092: table = snapshot.getTable("people", Person.getTypeInfo());
093: }
094:
095: void commitAndGetNewSnapshot() throws Exception {
096: snapshot.commit();
097: getNewSnapshot();
098: }
099:
100: void commitAndRotate() throws Exception {
101: snapshot.commit();
102: rotate();
103: }
104: }
|