Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 9d9a747

Browse files
committed
#77 Now supports properties starting with "marklogic."
1 parent 605e13e commit 9d9a747

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/main/java/com/marklogic/mgmt/util/PropertySourceFactory.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public abstract class PropertySourceFactory extends LoggingObject {
99

1010
private PropertySource propertySource;
11+
private boolean checkWithMarklogicPrefix = true;
1112

1213
protected PropertySourceFactory() {
1314
this(new SystemPropertySource());
@@ -17,11 +18,31 @@ public PropertySourceFactory(PropertySource propertySource) {
1718
this.propertySource = propertySource;
1819
}
1920

21+
/**
22+
* If checkWithMarklogicPrefix is set to true, and a property with the given name is not found, this method will
23+
* check for a property with "marklogic." + the property name. This allows for Spring Boot-style properties, where
24+
* it's usually helpful to be able to prefix everything with "marklogic.".
25+
*
26+
* @param name
27+
* @return
28+
*/
2029
protected String getProperty(String name) {
21-
return propertySource.getProperty(name);
30+
String val = propertySource.getProperty(name);
31+
if (val != null) {
32+
return val;
33+
}
34+
return checkWithMarklogicPrefix ? propertySource.getProperty("marklogic." + name) : null;
2235
}
2336

2437
public void setPropertySource(PropertySource propertySource) {
2538
this.propertySource = propertySource;
2639
}
40+
41+
public boolean isCheckWithMarklogicPrefix() {
42+
return checkWithMarklogicPrefix;
43+
}
44+
45+
public void setCheckWithMarklogicPrefix(boolean applyMarklogicPrefix) {
46+
this.checkWithMarklogicPrefix = applyMarklogicPrefix;
47+
}
2748
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.marklogic.appdeployer;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import com.marklogic.mgmt.util.SimplePropertySource;
7+
8+
public class DefaultAppConfigFactoryTest extends Assert {
9+
10+
private DefaultAppConfigFactory sut;
11+
12+
@Test
13+
public void gradleStyleProperties() {
14+
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlHost", "somehost", "mlUsername", "someuser"));
15+
AppConfig config = sut.newAppConfig();
16+
assertEquals("somehost", config.getHost());
17+
assertEquals("someuser", config.getRestAdminUsername());
18+
}
19+
20+
@Test
21+
public void springStyleProperties() {
22+
sut = new DefaultAppConfigFactory(
23+
new SimplePropertySource("marklogic.mlHost", "springhost", "marklogic.mlUsername", "springuser"));
24+
AppConfig config = sut.newAppConfig();
25+
assertEquals("springhost", config.getHost());
26+
assertEquals("springuser", config.getRestAdminUsername());
27+
}
28+
29+
@Test
30+
public void unrecognizedProperties() {
31+
sut = new DefaultAppConfigFactory(new SimplePropertySource("foo.mlHost", "host", "foo.mlUsername", "user"));
32+
AppConfig config = sut.newAppConfig();
33+
assertEquals("Should use default", "localhost", config.getHost());
34+
assertEquals("Should use default", "admin", config.getRestAdminUsername());
35+
}
36+
}

0 commit comments

Comments
 (0)