Skip to content

Commit ebc715a

Browse files
groldanaaime
authored andcommitted
GeoWebCacheEnvironment.resolveValueIfEnabled doesn't parse booleans from resolved value
Fix a bug where GeoWebCacheEnvironment.resolveValueIfEnabled(String, Class) won't use the resolved value from the env variable or system property when a boolean is requested.
1 parent 83e6d72 commit ebc715a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public <T> Optional<T> resolveValueIfEnabled(final String value, Class<T> type)
178178
} else if (type.isAssignableFrom(Boolean.class)) {
179179
if (!validateBoolean(resultValue))
180180
throw new IllegalArgumentException("Illegal String parameter: Resolved value is not a boolean.");
181-
Boolean boolValue = Boolean.valueOf(value);
181+
Boolean boolValue = Boolean.valueOf(resultValue);
182182
return (Optional<T>) Optional.of(boolValue);
183183
}
184184
throw new IllegalArgumentException("No type convertion available for " + type);

geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheEnvironmentTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import static org.easymock.EasyMock.createMock;
44
import static org.easymock.EasyMock.expect;
55
import static org.easymock.EasyMock.replay;
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assert.assertThrows;
8+
import static org.junit.Assert.assertTrue;
69

710
import java.util.HashMap;
811
import java.util.List;
912
import java.util.Map;
13+
import java.util.Optional;
1014
import java.util.Properties;
1115
import org.junit.After;
1216
import org.junit.Assert;
@@ -75,4 +79,25 @@ public void testSystemProperty() {
7579
Assert.assertEquals("ABC", genv.resolveValue("${TEST_SYS_PROPERTY}"));
7680
Assert.assertEquals("WWW", genv.resolveValue("${TEST_PROPERTY}"));
7781
}
82+
83+
@Test
84+
public void testResolveValueIfEnabled() {
85+
GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment();
86+
assertTrue(genv.isAllowEnvParametrization());
87+
88+
assertEquals(Optional.of("${ENV_NOT_SET}"), genv.resolveValueIfEnabled("${ENV_NOT_SET}", String.class));
89+
assertEquals(Optional.of("ABC"), genv.resolveValueIfEnabled("${TEST_SYS_PROPERTY}", String.class));
90+
91+
System.setProperty("TEST_BOOL_PROPERTY", "true");
92+
try {
93+
assertEquals(Optional.of(true), genv.resolveValueIfEnabled("${TEST_BOOL_PROPERTY}", Boolean.class));
94+
assertEquals(Optional.of("true"), genv.resolveValueIfEnabled("${TEST_BOOL_PROPERTY}", String.class));
95+
96+
assertThrows(
97+
IllegalArgumentException.class,
98+
() -> genv.resolveValueIfEnabled("${TEST_BOOL_PROPERTY}", Integer.class));
99+
} finally {
100+
System.clearProperty("TEST_BOOL_PROPERTY");
101+
}
102+
}
78103
}

0 commit comments

Comments
 (0)