1
2
3
4 package nl.b3p;
5
6 import static org.junit.jupiter.api.Assumptions.assumeFalse;
7
8 import java.io.IOException;
9 import java.util.Properties;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.junit.jupiter.api.AfterEach;
13 import org.junit.jupiter.api.BeforeAll;
14 import org.junit.jupiter.api.BeforeEach;
15 import org.junit.jupiter.api.TestInfo;
16
17
18
19
20
21
22 public abstract class AbstractDatabaseIntegrationTest {
23
24 private static final Log LOG = LogFactory.getLog(AbstractDatabaseIntegrationTest.class);
25
26
27
28
29 @BeforeAll
30 public static void checkDatabaseIsProvided() {
31
32
33
34 assumeFalse(
35 null == System.getProperty("database.properties.file"),
36 "Geen database omgeving aangegeven. Stel `database.properties.file` in.");
37 }
38
39
40
41
42
43
44 protected final Properties params = new Properties();
45
46
47 protected boolean isOracle;
48
49
50 protected boolean isPostgis;
51
52
53
54
55
56
57 @BeforeEach
58 public abstract void setUp() throws Exception;
59
60
61
62
63
64
65 @BeforeEach
66 public void loadProps() throws IOException {
67
68 params.load(
69 AbstractDatabaseIntegrationTest.class
70 .getClassLoader()
71 .getResourceAsStream(System.getProperty("database.properties.file")));
72 try {
73
74 params.load(
75 AbstractDatabaseIntegrationTest.class
76 .getClassLoader()
77 .getResourceAsStream("local." + System.getProperty("database.properties.file")));
78 } catch (IOException | NullPointerException e) {
79
80 }
81 isOracle = "oracle".equalsIgnoreCase(params.getProperty("dbtype"));
82 isPostgis = "postgis".equalsIgnoreCase(params.getProperty("dbtype"));
83
84 try {
85 Class.forName(params.getProperty("rsgb.jdbc.driverClassName"));
86 Class.forName(params.getProperty("staging.jdbc.driverClassName"));
87 Class.forName(params.getProperty("rsgbbgt.jdbc.driverClassName"));
88 Class.forName(params.getProperty("rsgbbrk.jdbc.driverClassName"));
89 Class.forName(params.getProperty("topnl.jdbc.driverClassName"));
90 } catch (ClassNotFoundException ex) {
91 LOG.error("Database driver niet gevonden.", ex);
92 }
93 }
94
95
96 @BeforeEach
97 public void startTest(TestInfo testInfo) {
98 LOG.info("==== Start test methode: " + testInfo.getDisplayName());
99 }
100
101
102 @AfterEach
103 public void endTest(TestInfo testInfo) {
104 LOG.info("==== Einde test methode: " + testInfo.getDisplayName());
105 }
106 }