001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
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;
009: * version 2.1 of the License.
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: package org.geotools.index.rtree.cachefs;
017:
018: import junit.framework.TestCase;
019: import org.geotools.index.DataDefinition;
020: import org.geotools.index.TreeException;
021: import java.io.File;
022: import java.io.FileOutputStream;
023: import java.io.OutputStream;
024: import java.security.SecureRandom;
025:
026: /**
027: * DOCUMENT ME!
028: *
029: * @author Tommaso Nolli
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/index/rtree/cachefs/FileSystemPageStoreTest.java $
031: */
032: public class FileSystemPageStoreTest extends TestCase {
033: /**
034: * Constructor for FileSystemPageStoreTest.
035: *
036: * @param arg0
037: */
038: public FileSystemPageStoreTest(String arg0) {
039: super (arg0);
040: }
041:
042: /*
043: * Test for void FileSystemPageStore(File)
044: */
045: public void testFileSystemPageStoreFile() throws Exception {
046: File file = File.createTempFile("geotools2a", ".grx");
047: file.deleteOnExit();
048:
049: try {
050: FileSystemPageStore fps = new FileSystemPageStore(file);
051: fail("Cannot create a FileSystemPageStore without a "
052: + "DataDefinition");
053: } catch (TreeException e) {
054: file.delete();
055: // Ok, the file must exist
056: }
057: }
058:
059: /*
060: * Test for void FileSystemPageStore(File, DataDefinition)
061: */
062: public void testFileSystemPageStoreFileDataDefinition()
063: throws Exception {
064: File file = File.createTempFile("geotools2b", ".grx");
065: file.deleteOnExit();
066: DataDefinition dd = new DataDefinition("US-ASCII");
067:
068: try {
069: FileSystemPageStore fps = new FileSystemPageStore(file, dd);
070: fail("Cannot use an empty DataDefinition");
071: } catch (TreeException e) {
072: // OK
073: }
074:
075: dd.addField(Integer.class);
076:
077: FileSystemPageStore fps = new FileSystemPageStore(file, dd);
078: fps.close();
079: }
080:
081: /*
082: * Test for void FileSystemPageStore(File, DataDefinition, int, int, short)
083: */
084: public void testFileSystemPageStoreFileDataDefinitionintintshort()
085: throws Exception {
086: File file = File.createTempFile("geotools2c", ".grx");
087: file.deleteOnExit();
088: DataDefinition dd = new DataDefinition("US-ASCII");
089: dd.addField(Integer.class);
090:
091: FileSystemPageStore fps = null;
092:
093: try {
094: fps = new FileSystemPageStore(file, dd, 10, 10,
095: FileSystemPageStore.SPLIT_LINEAR);
096: fail("MinNodeEntries must be <= MaxNodeEntries / 2");
097: } catch (TreeException e) {
098: // OK
099: }
100:
101: try {
102: fps = new FileSystemPageStore(file, dd, 10, 5, (short) 1000);
103: fail("SplitAlgorithm not supported");
104: } catch (TreeException e) {
105: // OK
106: }
107:
108: fps = new FileSystemPageStore(file, dd, 50, 25,
109: FileSystemPageStore.SPLIT_QUADRATIC);
110: fps.close();
111:
112: OutputStream out = new FileOutputStream(file);
113: out.write(SecureRandom.getSeed(50));
114: out.close();
115:
116: try {
117: fps = new FileSystemPageStore(file, dd, 10, 5,
118: FileSystemPageStore.SPLIT_QUADRATIC);
119: fail("File must not exist");
120: } catch (TreeException e) {
121: // OK
122: }
123: }
124: }
|