forked from andrewharmellaw/archaius-spring-adapter
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from motusllc/allow_duplicate_definitions
Allow duplicate placeholder configs if desired
- Loading branch information
Showing
9 changed files
with
174 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/groovy/com/capgemini/archaius/spring/SpringDuplicateDefinitionIsNotOkSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.capgemini.archaius.spring | ||
|
||
import org.springframework.beans.factory.BeanCreationException | ||
import org.springframework.context.support.ClassPathXmlApplicationContext | ||
import org.springframework.test.context.ActiveProfiles | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author: Scott Rankin | ||
* @version: 1.0 | ||
*/ | ||
@ActiveProfiles('default') | ||
class SpringDuplicateDefinitionIsNotOkSpec extends Specification { | ||
|
||
def "missing spring properties files is not ok if IgnoreResourceNotFound property set to false" () { | ||
when: | ||
ctx = new ClassPathXmlApplicationContext('spring/springDuplicateDefinitionIsNotOkTest.xml') | ||
then: | ||
BeanCreationException bce = thrown() | ||
bce.cause.message == 'Failed properties: Property \'locations\' threw exception; nested exception is ' + | ||
'java.lang.IllegalStateException: Archaius is already configured with a property source/sources.' | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/groovy/com/capgemini/archaius/spring/SpringDuplicateDefinitionIsOkSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.capgemini.archaius.spring | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.context.ActiveProfiles | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author: Scott Rankin | ||
* @version: 1.0 | ||
*/ | ||
@ActiveProfiles('default') | ||
@ContextConfiguration(locations = 'classpath:spring/springDuplicateDefinitionIsOkTest.xml') | ||
class SpringDuplicateDefinitionIsOkSpec extends Specification { | ||
@Autowired | ||
@Qualifier('configOne') | ||
private final ArchaiusPropertyPlaceholderConfigurer configOne | ||
|
||
@Autowired | ||
@Qualifier('configTwo') | ||
private final ArchaiusPropertyPlaceholderConfigurer configTwo | ||
|
||
def 'Duplicate definitions OK and config one loads properties' () { | ||
expect: | ||
configOne.resolvePlaceholder('var2', null, 0) == 'MY SECOND VAR' | ||
} | ||
|
||
def 'Duplicate definitions OK and config two does not load its specified properties' () { | ||
expect: | ||
configTwo.resolvePlaceholder('var3', null, 0) == null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var1=${mvn.var1} | ||
var2=MY SECOND VAR (THIS ONE WINS) | ||
|
||
var3=THIS IS THE THIRD | ||
|
27 changes: 27 additions & 0 deletions
27
src/test/resources/spring/springDuplicateDefinitionIsNotOkTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<!-- Config loading via Spring-Archaius--> | ||
<bean class="com.capgemini.archaius.spring.ArchaiusPropertyPlaceholderConfigurer"> | ||
<property name="locations"> | ||
<list> | ||
<value>classpath:/META-INF/system.properties</value> | ||
<value>classpath:/META-INF/even-more-system.properties</value> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
<bean class="com.capgemini.archaius.spring.ArchaiusPropertyPlaceholderConfigurer"> | ||
<property name="locations"> | ||
<list> | ||
<value>classpath:/META-INF/system.properties</value> | ||
<value>classpath:/META-INF/even-more-system.properties</value> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
</beans> |
29 changes: 29 additions & 0 deletions
29
src/test/resources/spring/springDuplicateDefinitionIsOkTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<!-- Config loading via Spring-Archaius--> | ||
<bean class="com.capgemini.archaius.spring.ArchaiusPropertyPlaceholderConfigurer" | ||
id="configOne"> | ||
<property name="allowMultiplePlaceholders" value="true"/> | ||
<property name="locations"> | ||
<list> | ||
<value>classpath:/META-INF/system.properties</value> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
<bean class="com.capgemini.archaius.spring.ArchaiusPropertyPlaceholderConfigurer" | ||
id="configTwo"> | ||
<property name="allowMultiplePlaceholders" value="true"/> | ||
<property name="locations"> | ||
<list> | ||
<value>classpath:/META-INF/even-more-system.properties</value> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
</beans> |