Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit 1966c38

Browse files
author
Thomas Risberg
committed
DATAJDBC-45 adding resolution of system properties for property file locations
1 parent edd52a0 commit 1966c38

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

spring-data-oracle-test/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
/*.iml
33
/build/
44
/.gradle/
5+
/out/
6+
/*.ipr
7+
/*.iws

spring-data-oracle-test/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: "java"
2+
apply plugin: "idea"
3+
apply plugin: "eclipse"
24

35
test {
46
systemProperty 'javax.xml.parsers.DocumentBuilderFactory', 'com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl'

spring-data-oracle-test/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ springRetryVersion = 1.0.0.RELEASE
1212
junitVersion = 4.10
1313
aspectjVersion = 1.6.11.RELEASE
1414

15-
sdJdbcVersion = 1.0.0.BUILD-SNAPSHOT
15+
sdJdbcVersion = 1.1.0.BUILD-SNAPSHOT

spring-data-oracle/src/main/java/org/springframework/data/jdbc/config/oracle/PoolingDataSourceBeanDefinitionParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.core.io.Resource;
3030
import org.springframework.core.io.ResourceLoader;
3131
import org.springframework.util.StringUtils;
32+
import org.springframework.util.SystemPropertyUtils;
3233
import org.springframework.util.xml.DomUtils;
3334
import org.w3c.dom.Element;
3435

@@ -159,7 +160,8 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
159160
// look for property files
160161
if (StringUtils.hasText(propertyFileLocation)) {
161162
logger.debug("Using properties location: " + propertyFileLocation);
162-
Resource r = rl.getResource(propertyFileLocation);
163+
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(propertyFileLocation);
164+
Resource r = rl.getResource(resolvedLocation);
163165
logger.debug("Loading properties from resource: " + r);
164166
PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
165167
factoryBean.setLocation(r);

spring-data-oracle/src/test/java/org/springframework/data/jdbc/config/oracle/DataOrclNamespaceTests.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222
import org.springframework.beans.factory.xml.XmlBeanFactory;
2323
import org.springframework.core.io.ClassPathResource;
2424

25+
import javax.xml.bind.SchemaOutputResolver;
26+
2527
/**
28+
* Tests for Oracle namespace
29+
*
30+
* Note: Tests should be run with working directory set as spring-data-jdbc-ext/spring-data-oracle
31+
*
2632
* @author Thomas Risberg
2733
*/
2834
public class DataOrclNamespaceTests extends TestCase {
2935

3036
private XmlBeanFactory beanFactory;
3137

38+
{
39+
// set ${test.home} for property file location resolution
40+
String pwd = System.getProperty("user.dir");
41+
String path = "/src/test/";
42+
System.setProperty("test.home", pwd + path);
43+
}
44+
3245
protected void setUp() throws Exception {
3346
this.beanFactory = new XmlBeanFactory(new ClassPathResource("test-data-orcl-namespace.xml", getClass()));
3447
}
@@ -38,13 +51,18 @@ public void testSimpleDataSourceDefinition() throws Exception {
3851
assertEquals("not the correct class", "oracle.jdbc.pool.OracleDataSource", bean.getClass().getName());
3952
}
4053

41-
public void testPropertyFileDataSourceDefinition() throws Exception {
42-
Object bean = this.beanFactory.getBean("propertyFileDataSource");
54+
public void testClasspathPropertyFileDataSourceDefinition() throws Exception {
55+
Object bean = this.beanFactory.getBean("classpathPropertyFileDataSource");
56+
assertEquals("not the correct class", "oracle.jdbc.pool.OracleDataSource", bean.getClass().getName());
57+
}
58+
59+
public void testLocalPropertyFileDataSourceDefinition() throws Exception {
60+
Object bean = this.beanFactory.getBean("localPropertyFileDataSource");
4361
assertEquals("not the correct class", "oracle.jdbc.pool.OracleDataSource", bean.getClass().getName());
4462
}
4563

4664
public void testConectionPropertiesDataSourceDefinition() throws Exception {
47-
Object bean = this.beanFactory.getBean("connectionPpropertiesDataSource");
65+
Object bean = this.beanFactory.getBean("connectionPropertiesDataSource");
4866
assertEquals("not the correct class", "oracle.jdbc.pool.OracleDataSource", bean.getClass().getName());
4967
assertTrue("connection properties not found", ((OracleDataSource)bean).getConnectionProperties().size() > 0);
5068
assertTrue("cache properties not found", ((OracleDataSource)bean).getConnectionCacheProperties().size() > 0);

spring-data-oracle/src/test/resources/org/springframework/data/jdbc/config/oracle/test-data-orcl-namespace.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<orcl:pooling-datasource id="simpleDataSource"
1414
url="jdbc:" username="spring" password="test"/>
1515

16-
<orcl:pooling-datasource id="propertyFileDataSource"
16+
<orcl:pooling-datasource id="classpathPropertyFileDataSource"
1717
url="jdbc:"
1818
properties-location="classpath:org/springframework/data/jdbc/config/oracle/test-orcl.properties">
1919
<orcl:connection-properties>
@@ -23,7 +23,17 @@
2323
</orcl:connection-properties>
2424
</orcl:pooling-datasource>
2525

26-
<orcl:pooling-datasource id="connectionPpropertiesDataSource"
26+
<orcl:pooling-datasource id="localPropertyFileDataSource"
27+
url="jdbc:"
28+
properties-location="file:${test.home}/resources/org/springframework/data/jdbc/config/oracle/test-orcl.properties">
29+
<orcl:connection-properties>
30+
xxx=/test
31+
yyy=OK
32+
zzz=1024
33+
</orcl:connection-properties>
34+
</orcl:pooling-datasource>
35+
36+
<orcl:pooling-datasource id="connectionPropertiesDataSource"
2737
url="jdbc:"
2838
connection-caching-enabled="true">
2939
<orcl:connection-properties>

0 commit comments

Comments
 (0)