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 drjava.smyle.*;
028: import drjava.smyle.core.StoreRegistry;
029: import drjava.smyle.core.DiskStore;
030: import drjava.util.*;
031:
032: public class SmyleTest extends TestCase {
033: public SmyleTest(String name) {
034: super (name);
035: }
036:
037: public void testTwoStoresOnSameDir() throws Exception {
038: // use two different names for the same dir
039: Store store1 = Smyle.createEmptyStore("temp/db");
040: Store store2 = Smyle.openStore("temp/../temp/db");
041:
042: try {
043: assert("Stores should be identical", store1 == store2);
044: } finally {
045: store1.close();
046: store2.close();
047: }
048: }
049:
050: public void testTwoStoresOnDifferentDirs() throws Exception {
051: // use two different dirs
052: Store store2 = Smyle.createEmptyStore("temp/db2");
053: store2.close();
054: Store store1 = Smyle.createEmptyStore("temp/db");
055: store2 = Smyle.openStore("temp/db2");
056:
057: try {
058: assert("Stores should not be identical", store1 != store2);
059: } finally {
060: store1.close();
061: store2.close();
062: }
063: }
064:
065: public void testStoreForgottenOnClose() throws Exception {
066: Store store1 = Smyle.createEmptyStore("temp/db");
067: store1.close();
068: Store store2 = Smyle.openStore("temp/db");
069:
070: try {
071: assert("Stores should not be identical", store1 != store2);
072: } finally {
073: store2.close();
074: }
075: }
076:
077: public void testStoreRegistryIsSynchronized() throws Exception {
078: SynchronisationTester
079: .assertPublicMethodsAreSynchronized(StoreRegistry.class);
080: }
081:
082: public void testReadOnlyStore() throws Exception {
083: // create and open store, bypassing registry
084: Store store = new DiskStore(new File("temp/db"));
085:
086: // open read-only store while normal store is already open
087: Store store2 = Smyle.openStoreReadOnly("temp/db");
088:
089: try {
090: store2.mutableSnapshot();
091: fail("No exception");
092: } catch (ReadOnlyException e) {
093: // ok
094: }
095:
096: store2.close();
097: store.close();
098: }
099:
100: public void testStoreExists() throws Exception {
101: assertEquals(false, Smyle.storeExists("temp/nostorehere"));
102:
103: Smyle.createEmptyStore("temp/db").close();
104: Store store = Smyle.openStore("temp/db");
105: assertEquals(true, Smyle.storeExists("temp/db"));
106: assertEquals(true, Smyle.storeInUse("temp/db"));
107: store.close();
108: assertEquals(true, Smyle.storeExists("temp/db"));
109: assertEquals(false, Smyle.storeInUse("temp/db"));
110: }
111: }
|