forked from IQSS/dataverse
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration testing for DbSettingConfigSource to ensure data retr…
…ieval works. Fixing a typo, too. IQSS#7457
- Loading branch information
1 parent
e1cb339
commit 8790313
Showing
4 changed files
with
75 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
47 changes: 47 additions & 0 deletions
47
src/test/java/edu/harvard/iq/dataverse/settings/source/DbSettingConfigSourceIT.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,47 @@ | ||
package edu.harvard.iq.dataverse.settings.source; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.postgresql.ds.PGSimpleDataSource; | ||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import javax.naming.Context; | ||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
import javax.sql.DataSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@Testcontainers | ||
@Tag("testcontainers") | ||
class DbSettingConfigSourceTest { | ||
|
||
@Container | ||
static JdbcDatabaseContainer dbContainer = new PostgreSQLContainer("postgres:"+System.getProperty("postgresql.server.version", "9.6")) | ||
.withInitScript("sql/dbsetting-config-source-testdata.sql") | ||
.withDatabaseName("dataverse"); | ||
|
||
static DbSettingConfigSource dbSource; | ||
|
||
@BeforeAll | ||
static void setUp() throws NamingException { | ||
// create the datasource | ||
PGSimpleDataSource ds = new PGSimpleDataSource(); | ||
ds.setURL(dbContainer.getJdbcUrl()); | ||
ds.setUser(dbContainer.getUsername()); | ||
ds.setPassword(dbContainer.getPassword()); | ||
|
||
// create the config source | ||
dbSource = new DbSettingConfigSource(ds); | ||
} | ||
|
||
@Test | ||
void testDataRetrieval() { | ||
assertEquals("foobar@example.org", dbSource.getValue("dataverse.settings.fromdb.SystemEmail")); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/test/resources/sql/dbsetting-config-source-testdata.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,11 @@ | ||
CREATE TABLE Setting ( | ||
id char(5) CONSTRAINT firstkey PRIMARY KEY, | ||
name varchar(40) NOT NULL, | ||
content varchar(40) NOT NULL, | ||
lang varchar(40) DEFAULT NULL | ||
); | ||
|
||
INSERT INTO Setting (id, name, content) | ||
VALUES | ||
(1, 'SystemEmail', 'foobar@example.org') | ||
ON CONFLICT DO NOTHING; |