Search in sources :

Example 11 with TestDatabase

use of org.apache.sis.test.sql.TestDatabase in project sis by apache.

the class EPSGInstallerTest method testCreationOnHSQLDB.

/**
 * Tests the creation of an EPSG database on HSQLDB.
 * This test is skipped if the SQL scripts are not found.
 *
 * @throws Exception if an error occurred while creating the database.
 */
@Test
public void testCreationOnHSQLDB() throws Exception {
    // Needs to be invoked first.
    final InstallationScriptProvider scripts = getScripts();
    try (TestDatabase db = TestDatabase.createOnHSQLDB("EPSGInstaller", false)) {
        createAndTest(db.source, scripts);
        verifyParameterValues(db.source);
    }
    loggings.assertNextLogContains("EPSG", "jdbc:hsqldb:mem:EPSGInstaller");
    loggings.assertNoUnexpectedLog();
}
Also used : TestDatabase(org.apache.sis.test.sql.TestDatabase) Test(org.junit.Test)

Example 12 with TestDatabase

use of org.apache.sis.test.sql.TestDatabase in project sis by apache.

the class SelectionClauseWriterTest method testOnDerby.

/**
 * Tests on Derby.
 *
 * @throws Exception if an error occurred while testing the database.
 */
@Test
public void testOnDerby() throws Exception {
    try (TestDatabase db = TestDatabase.create("SQLStore")) {
        db.executeSQL(SelectionClauseWriterTest.class, "CREATE TABLE TEST (ALPHA INTEGER, BETA INTEGER, GAMMA INTEGER, PI FLOAT);");
        final StorageConnector connector = new StorageConnector(db.source);
        connector.setOption(SchemaModifier.OPTION, this);
        try (DataStore store = new SQLStoreProvider().open(connector)) {
            table = (Table) store.findResource("TEST");
            testSimpleFilter();
            testGeometricFilter();
            testGeometricFilterWithTransform();
        }
    }
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) SQLStoreProvider(org.apache.sis.storage.sql.SQLStoreProvider) TestDatabase(org.apache.sis.test.sql.TestDatabase) DataStore(org.apache.sis.storage.DataStore) Test(org.junit.Test)

Example 13 with TestDatabase

use of org.apache.sis.test.sql.TestDatabase in project sis by apache.

the class SQLStoreTest method test.

/**
 * Runs all tests on a single database software. A temporary schema is created at the beginning of this method
 * and deleted after all tests finished. The schema is created and populated by the {@code Features.sql} script.
 *
 * @param  inMemory  whether the test database is in memory. If {@code true}, then the schema will be created
 *                   and will be the only schema to exist (ignoring system schema); i.e. we assume that there
 *                   is no ambiguity if we do not specify the schema in {@link SQLStore} constructor.
 */
private void test(final TestDatabase database, final boolean inMemory) throws Exception {
    final String[] scripts = { "CREATE SCHEMA " + SCHEMA + ';', "file:Features.sql" };
    if (!inMemory) {
        // Omit the "CREATE SCHEMA" statement if the schema already exists.
        scripts[0] = null;
    }
    try (TestDatabase tmp = database) {
        // TODO: omit `tmp` with JDK16.
        database.executeSQL(SQLStoreTest.class, scripts);
        final StorageConnector connector = new StorageConnector(database.source);
        final ResourceDefinition table = ResourceDefinition.table(null, inMemory ? null : SCHEMA, "Cities");
        testTableQuery(connector, table);
        /*
             * Verify using SQL statements instead of tables.
             */
        verifyFetchCityTableAsQuery(connector);
        verifyNestedSQLQuery(connector);
        verifyLimitOffsetAndColumnSelectionFromQuery(connector);
        verifyDistinctQuery(connector);
        /*
             * Test on the table again, but with cyclic associations enabled.
             */
        connector.setOption(SchemaModifier.OPTION, new SchemaModifier() {

            @Override
            public boolean isCyclicAssociationAllowed(TableReference dependency) {
                return true;
            }
        });
        isCyclicAssociationAllowed = true;
        testTableQuery(connector, table);
    }
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) TableReference(org.apache.sis.internal.sql.feature.TableReference) TestDatabase(org.apache.sis.test.sql.TestDatabase) SchemaModifier(org.apache.sis.internal.sql.feature.SchemaModifier)

Aggregations

TestDatabase (org.apache.sis.test.sql.TestDatabase)13 Test (org.junit.Test)11 Connection (java.sql.Connection)3 StorageConnector (org.apache.sis.storage.StorageConnector)3 SQLStoreProvider (org.apache.sis.storage.sql.SQLStoreProvider)2 Method (java.lang.reflect.Method)1 AbstractFeature (org.apache.sis.feature.AbstractFeature)1 SQLBuilder (org.apache.sis.internal.metadata.sql.SQLBuilder)1 GeometryGetterTest (org.apache.sis.internal.sql.feature.GeometryGetterTest)1 SchemaModifier (org.apache.sis.internal.sql.feature.SchemaModifier)1 TableReference (org.apache.sis.internal.sql.feature.TableReference)1 DataStore (org.apache.sis.storage.DataStore)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 ResourceDefinition (org.apache.sis.storage.sql.ResourceDefinition)1 SQLStore (org.apache.sis.storage.sql.SQLStore)1 SQLStoreTest (org.apache.sis.storage.sql.SQLStoreTest)1 Envelope (org.opengis.geometry.Envelope)1