forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DbSettingConfigSourceIT.java
47 lines (37 loc) · 1.62 KB
/
DbSettingConfigSourceIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"));
}
}