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.fs;
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/fs/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("geotools2e", ".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: // Ok, the file must exist
055: }
056: }
057:
058: /*
059: * Test for void FileSystemPageStore(File, DataDefinition)
060: */
061: public void testFileSystemPageStoreFileDataDefinition()
062: throws Exception {
063: File file = File.createTempFile("geotoolsf2", ".grx");
064: file.deleteOnExit();
065: DataDefinition dd = new DataDefinition("US-ASCII");
066:
067: try {
068: FileSystemPageStore fps = new FileSystemPageStore(file, dd);
069: fail("Cannot use an empty DataDefinition");
070: } catch (TreeException e) {
071: // OK
072: }
073:
074: dd.addField(Integer.class);
075:
076: FileSystemPageStore fps = new FileSystemPageStore(file, dd);
077: fps.close();
078: }
079:
080: /*
081: * Test for void FileSystemPageStore(File, DataDefinition, int, int, short)
082: */
083: public void testFileSystemPageStoreFileDataDefinitionintintshort()
084: throws Exception {
085: File file = File.createTempFile("geotools2g", ".grx");
086: file.deleteOnExit();
087: DataDefinition dd = new DataDefinition("US-ASCII");
088: dd.addField(Integer.class);
089:
090: FileSystemPageStore fps = null;
091:
092: try {
093: fps = new FileSystemPageStore(file, dd, 10, 10,
094: FileSystemPageStore.SPLIT_LINEAR);
095: fail("MinNodeEntries must be <= MaxNodeEntries / 2");
096: } catch (TreeException e) {
097: // OK
098: }
099:
100: try {
101: fps = new FileSystemPageStore(file, dd, 10, 5, (short) 1000);
102: fail("SplitAlgorithm not supported");
103: } catch (TreeException e) {
104: // OK
105: }
106:
107: fps = new FileSystemPageStore(file, dd, 50, 25,
108: FileSystemPageStore.SPLIT_QUADRATIC);
109: fps.close();
110:
111: OutputStream out = new FileOutputStream(file);
112: out.write(SecureRandom.getSeed(50));
113: out.close();
114:
115: try {
116: fps = new FileSystemPageStore(file, dd, 10, 5,
117: FileSystemPageStore.SPLIT_QUADRATIC);
118: fail("File must not exist");
119: } catch (TreeException e) {
120: // OK
121: }
122: }
123: }
|