use of org.apache.sis.test.sql.TestDatabase in project sis by apache.
the class EPSGInstallerTest method testCreationOnPostgreSQL.
/**
* Tests the creation of an EPSG database on PostgreSQL. This test requires a PostgreSQL server
* running on {@code "localhost"} with an empty database named {@code "SpatialMetadataTest"}.
* See {@linkplain TestDatabase#createOnPostgreSQL here} for more information.
*
* @throws Exception if an error occurred while creating the database.
*
* @since 0.8
*/
@Test
public void testCreationOnPostgreSQL() throws Exception {
// Needs to be invoked first.
final InstallationScriptProvider scripts = getScripts();
try (TestDatabase db = TestDatabase.createOnPostgreSQL("EPSG", false)) {
createAndTest(db.source, scripts);
verifyParameterValues(db.source);
}
loggings.assertNextLogContains("EPSG", "jdbc:postgresql://localhost/SpatialMetadataTest");
loggings.assertNoUnexpectedLog();
}
use of org.apache.sis.test.sql.TestDatabase in project sis by apache.
the class DataScriptFormatter method main.
/**
* Compacts the {@code Data.sql} file provided by EPSG. This method expects two arguments.
* The first argument is the file of the SQL script to read, which must exist.
* The second argument is the file where to write the compacted SQL script,
* which will be overwritten without warning if it exists.
* The values of those arguments are typically:
*
* <ol>
* <li>{@code $EPSG_SCRIPTS/PostgreSQL_Table_Script.sql}</li>
* <li>{@code sis-epsg/src/main/resources/org/apache/sis/referencing/factory/sql/epsg/Data.sql}</li>
* </ol>
*
* @param arguments the source files and the destination file.
* @throws Exception if an error occurred while reading of writing the file.
*/
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void main(String[] arguments) throws Exception {
if (arguments.length != 2) {
System.err.println("Expected two arguments: source SQL file and target SQL file.");
return;
}
try (TestDatabase db = TestDatabase.create("dummy");
Connection c = db.source.getConnection()) {
final DataScriptFormatter f = new DataScriptFormatter(c);
f.run(Paths.get(arguments[0]), Paths.get(arguments[1]));
}
}
use of org.apache.sis.test.sql.TestDatabase in project sis by apache.
the class PostgresTest method testSpatialFeatures.
/**
* Tests reading and writing features and rasters.
*
* @throws Exception if an error occurred while testing the database.
*/
@Test
public void testSpatialFeatures() throws Exception {
try (TestDatabase database = TestDatabase.createOnPostgreSQL(SQLStoreTest.SCHEMA, true)) {
database.executeSQL(PostgresTest.class, "file:SpatialFeatures.sql");
final StorageConnector connector = new StorageConnector(database.source);
connector.setOption(OptionKey.GEOMETRY_LIBRARY, GeometryLibrary.JTS);
final ResourceDefinition table = ResourceDefinition.table(null, SQLStoreTest.SCHEMA, "SpatialData");
try (SQLStore store = new SQLStore(new SQLStoreProvider(), connector, table)) {
/*
* Invoke the private `model()` method. We have to use reflection because the class
* is not in the same package and we do not want to expose the method in public API.
*/
final Method modelAccessor = SQLStore.class.getDeclaredMethod("model");
modelAccessor.setAccessible(true);
final Postgres<?> pg = (Postgres<?>) modelAccessor.invoke(store);
try (Connection connection = database.source.getConnection();
ExtendedInfo info = new ExtendedInfo(pg, connection)) {
testInfoStatements(info);
testGeometryGetter(info, connection);
testRasterReader(TestRaster.USHORT, info, connection);
}
/*
* Tests through public API.
*/
final FeatureSet resource = store.findResource("SpatialData");
try (Stream<AbstractFeature> features = resource.features(false)) {
features.forEach(PostgresTest::validate);
}
final Envelope envelope = resource.getEnvelope().get();
assertEquals(envelope.getMinimum(0), -72, 1);
assertEquals(envelope.getMaximum(1), 43, 1);
}
}
}
use of org.apache.sis.test.sql.TestDatabase in project sis by apache.
the class ScriptRunnerTest method testOnDerby.
/**
* Tests {@link ScriptRunner} with an in-memory Derby database.
* This method delegates its work to all other methods in this class that expect a {@link ScriptRunner} argument.
*
* @throws SQLException if an error occurred while executing the script runner.
*/
@Test
public void testOnDerby() throws SQLException {
try (TestDatabase db = TestDatabase.create("ScriptRunner");
Connection c = db.source.getConnection()) {
final ScriptRunner sr = new ScriptRunner(c, 3);
testSupportedFlags(sr);
testRegularExpressions(sr);
}
}
use of org.apache.sis.test.sql.TestDatabase in project sis by apache.
the class EPSGInstallerTest method testCreationOnH2.
/**
* Tests the creation of an EPSG database on H2.
* This test is skipped if the SQL scripts are not found.
*
* @throws Exception if an error occurred while creating the database.
*/
@Test
public void testCreationOnH2() throws Exception {
// Needs to be invoked first.
final InstallationScriptProvider scripts = getScripts();
try (TestDatabase db = TestDatabase.createOnH2("EPSGInstaller")) {
createAndTest(db.source, scripts);
verifyParameterValues(db.source);
}
loggings.assertNextLogContains("EPSG", "jdbc:h2:mem:EPSGInstaller");
loggings.assertNoUnexpectedLog();
}
Aggregations