77import org .junit .After ;
88import org .junit .Before ;
99
10+ import java .io .IOException ;
11+ import java .io .InputStream ;
1012import java .sql .Connection ;
1113import java .sql .DriverManager ;
14+ import java .util .Properties ;
1215
1316public abstract class TransactionalTestBase {
1417
1518 protected Connection connection ;
1619
1720 @ Before
1821 public void setUp () throws Exception {
19- //connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=TestDatabase", "philipp", "test_pwd");
20- connection = DriverManager .getConnection ("jdbc:sqlserver://localhost;instanceName=MSSQLSERVER2017;databaseName=TestDatabase;" , "philipp" , "test_pwd" );
22+ Properties properties = getConfigProperties ();
23+
24+ String dbUrl = properties .getProperty ("db.url" );
25+ String dbUser = properties .getProperty ("db.user" );
26+ String dbPassword = properties .getProperty ("db.password" );
27+
28+ connection = DriverManager .getConnection (dbUrl , dbUser , dbPassword );
2129
2230 onSetUpBeforeTransaction ();
2331 connection .setAutoCommit (false ); // Start the Transaction:
@@ -41,4 +49,15 @@ protected void onSetUpBeforeTransaction() throws Exception {}
4149 protected void onTearDownInTransaction () throws Exception {}
4250
4351 protected void onTearDownAfterTransaction () throws Exception {}
52+
53+ private static Properties getConfigProperties () throws Exception {
54+ try (InputStream inputStream = TransactionalTestBase .class .getClassLoader ().getResourceAsStream ("config.properties" )) {
55+
56+ Properties prop = new Properties ();
57+
58+ prop .load (inputStream );
59+
60+ return prop ;
61+ }
62+ }
4463}
0 commit comments