1 | package edu.iu.uis.sit.portal; |
2 | |
3 | import java.util.Properties; |
4 | |
5 | import org.apache.commons.dbcp.BasicDataSource; |
6 | import org.springframework.core.io.Resource; |
7 | |
8 | public class TestDataSource extends BasicDataSource { |
9 | |
10 | public TestDataSource(Resource properties) { |
11 | Properties propertiesFile = loadProperties(properties); |
12 | setUsername(propertiesFile.getProperty("jdbc.username")); |
13 | setPassword(propertiesFile.getProperty("jdbc.password")); |
14 | setDriverClassName(propertiesFile.getProperty("jdbc.driverClassName")); |
15 | setUrl(propertiesFile.getProperty("jdbc.url")); |
16 | } |
17 | |
18 | private Properties loadProperties(Resource properties) { |
19 | try { |
20 | Properties propertiesFile = new Properties(); |
21 | propertiesFile.load(properties.getInputStream()); |
22 | return propertiesFile; |
23 | } catch (Exception e) { |
24 | throw new RuntimeException("Error finding properties file."); |
25 | } |
26 | } |
27 | } |