📄 mifdatastoretest.java
字号:
/*
* GeoTools - OpenSource mapping toolkit
* http://geotools.org
* (C) 2005-2006, GeoTools Project Managment Committee (PMC)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.data.mif;
import java.io.IOException;
import java.sql.Date;
import java.util.HashMap;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.geotools.data.DefaultQuery;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureReader;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.FeatureWriter;
import org.geotools.data.Transaction;
import org.geotools.feature.AttributeTypeBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.filter.Filter;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
/**
* DOCUMENT ME!
*
* @author Luca S. Percich, AMA-MI
* @source $URL: http://svn.geotools.org/trunk/modules/unsupported/mif/src/test/java/org/geotools/data/mif/MIFDataStoreTest.java $
*/
public class MIFDataStoreTest extends TestCase {
private MIFDataStore ds;
/**
* DOCUMENT ME!
*
* @param args DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
public static void main(java.lang.String[] args) throws Exception {
junit.textui.TestRunner.run(new TestSuite(MIFDataStoreTest.class));
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
MIFTestUtils.cleanFiles();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
MIFTestUtils.cleanFiles();
super.tearDown();
}
/**
* Utility method for instantiating a MIFDataStore
*
* @param initPath DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
protected boolean initDS(String initPath) {
try {
initPath = MIFTestUtils.fileName(initPath);
HashMap params = MIFTestUtils.getParams("mif", initPath, null);
ds = new MIFDataStore(initPath, params);
assertNotNull(ds);
return true;
} catch (Exception e) {
fail(e.getMessage());
return false;
}
}
/**
* See if all the MIF in data dir are recognized
*/
public void testOpenDir() {
initDS("");
try {
assertNotNull(ds.getSchema("grafo"));
assertNotNull(ds.getSchema("nodi"));
assertNotNull(ds.getSchema("mixed"));
} catch (IOException e) {
fail(e.getMessage());
}
}
/**
*/
public void testCreateSchema() {
initDS("");
try {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("newschema");
AttributeTypeBuilder atb = new AttributeTypeBuilder();
atb.setName("obj");
atb.setBinding(LineString.class);
atb.setNillable(true);
builder.add(atb.buildDescriptor("obj"));
atb.setName("charfield");
atb.setBinding(String.class);
atb.setNillable(false);
atb.setLength(25);
atb.setDefaultValue("");
builder.add(atb.buildDescriptor("charfield"));
atb.setName("intfield");
atb.setBinding(Integer.class);
atb.setLength(0);
atb.setDefaultValue(0);
builder.add(atb.buildDescriptor("intfield"));
atb.setName("datefield");
atb.setBinding(Date.class);
atb.setDefaultValue(null);
builder.add(atb.buildDescriptor("datefield"));
atb.setName("doublefield");
atb.setBinding(Double.class);
atb.setDefaultValue(0d);
builder.add(atb.buildDescriptor("doublefield"));
atb.setName("floatfield");
atb.setBinding(Float.class);
atb.setDefaultValue(0f);
builder.add(atb.buildDescriptor("floatfield"));
atb.setName("boolfield");
atb.setBinding(Boolean.class);
atb.setDefaultValue(false);
builder.add(atb.buildDescriptor("boolfield"));
SimpleFeatureType newFT = builder.buildFeatureType();
ds.createSchema(newFT);
SimpleFeatureType builtFT = ds.getSchema("newschema");
assertEquals(builtFT, newFT);
} catch (Exception e) {
fail(e.getMessage());
}
}
/**
*/
public void testCreateSchemaBadGeometry() {
initDS("");
try {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("newschema");
AttributeTypeBuilder atb = new AttributeTypeBuilder();
atb.setName("charfield");
atb.setBinding(String.class);
atb.setNillable(false);
atb.setLength(25);
atb.setDefaultValue("");
builder.add(atb.buildDescriptor("charfield"));
atb.setName("intfield");
atb.setBinding(Integer.class);
atb.setLength(0);
atb.setDefaultValue(0);
builder.add(atb.buildDescriptor("intfield"));
atb.setName("obj");
atb.setBinding(LineString.class);
atb.setNillable(true);
builder.add(atb.buildDescriptor("obj"));
SimpleFeatureType newFT = builder.buildFeatureType();
ds.createSchema(newFT);
fail("SchemaException expected"); // Geometry must be the first field
} catch (Exception e) {
}
}
/**
*/
public void testCreateSchemaTwoGeometry() {
initDS("");
try {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("newschema");
AttributeTypeBuilder atb = new AttributeTypeBuilder();
atb.setName("obj");
atb.setBinding(LineString.class);
atb.setNillable(true);
builder.add(atb.buildDescriptor("obj"));
atb.setName("charfield");
atb.setBinding(String.class);
atb.setNillable(false);
atb.setLength(25);
atb.setDefaultValue("");
builder.add(atb.buildDescriptor("charfield"));
atb.setName("obj2");
atb.setBinding(LineString.class);
atb.setNillable(false);
atb.setDefaultValue(null);
builder.add(atb.buildDescriptor("obj2"));
atb.setName("intfield");
atb.setBinding(Integer.class);
atb.setLength(0);
atb.setDefaultValue(0);
builder.add(atb.buildDescriptor("intfield"));
SimpleFeatureType newFT = builder.buildFeatureType();
ds.createSchema(newFT);
fail("SchemaException expected"); // Only one geometry
} catch (Exception e) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -