Trying to create a Test database for HSQLDB via Gradle Task :-(

// This shit does not work and will never work
// task createTestDb(dependsOn: assemble, description: ‘Creates local hsql database for tests’, type: CubaDbCreation) {
// driver = ‘org.hsqldb.jdbcDriver’
// dbUrl = ‘jdbc:hsqldb:file:C:/git/cuba/app/build/hsqldb.test/app_test’
// masterUrl = ‘jdbc:hsqldb:file:C:/git/cuba/app/build/hsqldb.test/app_test_master’ // URL of a master DB to connect to for creating the application DB
// dropDbSql = ‘DROP SCHEMA PUBLIC CASCADE;’ // Drop database statement
// // dropDbSql = ‘DROP table SYS_DB_CHANGELOG;’ // Drop database statement
// createDbSql = ‘DROP table SYS_DB_CHANGELOG; SELECT CURRENT_DATE AS today, CURRENT_TIME AS now FROM (VALUES(0));’ // Create database statement
// timeStampType = ‘datetime’ // Date and time datatype - needed for SYS_DB_CHANGELOG table creation
// dbUser = ‘sa’
// dbPassword = ‘’
// }

To make a long story short, I need the gradle task for Integration testing, but it seems impossible to create a test database for HSQLDB.
Any Ideas?

Probably you didn’t start a HSQLDB server. Use startDb task before running createTestDb.
Be careful with server ports, because Studio runs an HSQL server on 9001 when a project using HSQLDB is opened.

1 Like

Thank you Konstantin, this works!
According to your hint, I set the test hsqldb server port to 9002.
For reference, I appended the working gradle code below.

   
 task startTestDb(type: CubaHsqlStart) {
        dbName = 'app_test'
        dbPort = 9002
    }    

    task createTestDb(dependsOn: assemble, description: 'Creates local hsql database for tests', type: CubaDbCreation) {
        dbms = 'hsql'
        dbmsVersion = 'null'
        host = 'localhost'
        dbName = 'app_test'
        dbUser = 'sa'
        dbPassword = ''
    }

I think you should specify the port in createTestDb too. It has no separate property for it, so try to do it in the host property:


task createTestDb(dependsOn: assemble, description: 'Creates local hsql database for tests', type: CubaDbCreation) {
        dbms = 'hsql'
        host = 'localhost:9002'
        dbName = 'app_test'
        dbUser = 'sa'
        dbPassword = ''
    }

Your code may now work without port because you may have a project opened in Studio and it runs HSQL on the default port.

Cool, thanks for pointing that out!
It worked before because I created the test database first without CUBA running.