-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
quarkus.datasource.devservices.init-script-path
- This enables specifying a SQL initialization script for Dev Services Databases Added tests
- Loading branch information
Showing
11 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...kus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceWithInitScriptTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.jdbc.postgresql.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
|
||
import javax.inject.Inject; | ||
import javax.sql.DataSource; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DevServicesPostgresqlDatasourceWithInitScriptTestCase { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(javaArchive -> javaArchive.addAsResource("init-db.sql")) | ||
.overrideConfigKey("quarkus.datasource.db-kind", "postgresql") | ||
.overrideConfigKey("quarkus.datasource.devservices.init-script-path", "init-db.sql"); | ||
|
||
@Inject | ||
DataSource ds; | ||
|
||
@Test | ||
@DisplayName("Test if init-script-path executed successfully") | ||
public void testDatasource() throws Exception { | ||
int result = 0; | ||
try (Connection con = ds.getConnection(); | ||
CallableStatement cs = con.prepareCall("SELECT my_func()"); | ||
ResultSet rs = cs.executeQuery()) { | ||
if (rs.next()) { | ||
result = rs.getInt(1); | ||
} | ||
} | ||
assertEquals(100, result, "The init script should have been executed"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
extensions/jdbc/jdbc-postgresql/deployment/src/test/resources/init-db.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE OR REPLACE FUNCTION my_func() RETURNS integer LANGUAGE plpgsql as $func$ BEGIN return 100; END $func$; |