This is an automated email from the ASF dual-hosted git repository.
anatole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git
The following commit(s) were added to refs/heads/master by this push:
new 873e6a3 Improved test coverage. Fixed PropertyChangeSupport.
873e6a3 is described below
commit 873e6a3add11731315bd47f5139af5b50d122027
Author: Anatole Tresch <[email protected]>
AuthorDate: Tue Jan 15 14:35:27 2019 +0100
Improved test coverage.
Fixed PropertyChangeSupport.
---
.../apache/tamaya/ConfigurationSnapshotTest.java | 155 ++++++++++++++++++
.../tamaya/core/internal/BannerManagerTest.java | 33 ++++
.../propertysource/BasePropertySourceTest.java | 152 +++++++++++++++++
.../tamaya/spisupport/ConfigValueEvaluator.java | 6 +-
.../spisupport/DefaultConfigValueEvaluator.java | 14 +-
.../tamaya/spisupport/DefaultConfiguration.java | 8 +-
.../spisupport/PropertySourceChangeSupport.java | 56 ++++---
.../PropertiesResourcePropertySource.java | 4 +-
.../propertysource/SystemPropertySource.java | 9 +-
.../BuildablePropertySourceProviderTest.java | 6 +
.../spisupport/BuildablePropertySourceTest.java | 16 ++
.../spisupport/ConfigValueEvaluatorTest.java | 69 ++++++++
.../DefaultConfigValueEvaluatorTest.java | 11 +-
.../DefaultConfigurationSnapshotTest.java | 179 ++++++++++++++++++++-
.../spisupport/DefaultConfigurationTest.java | 2 +-
.../PropertySourceChangeSupportTest.java | 169 +++++++++++++++++++
.../propertysource/SimplePropertySourceTest.java | 55 ++++++-
.../propertysource/SystemPropertySourceTest.java | 12 ++
.../META-INF/javaconfiguration.properties | 1 -
19 files changed, 896 insertions(+), 61 deletions(-)
diff --git
a/code/api/src/test/java/org/apache/tamaya/ConfigurationSnapshotTest.java
b/code/api/src/test/java/org/apache/tamaya/ConfigurationSnapshotTest.java
new file mode 100644
index 0000000..475dc2b
--- /dev/null
+++ b/code/api/src/test/java/org/apache/tamaya/ConfigurationSnapshotTest.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+public class ConfigurationSnapshotTest {
+
+ public void testEMPTY(){
+ assertNotNull(ConfigurationSnapshot.EMPTY);
+ }
+
+ @Test
+ public void testEMPTY_timestamp(){
+ assertTrue(ConfigurationSnapshot.EMPTY.getTimestamp()==0);
+ }
+
+ @Test
+ public void testEMPTY_get(){
+ assertNull(ConfigurationSnapshot.EMPTY.get("foo"));
+ }
+
+ @Test
+ public void testEMPTY_getOptional(){
+ assertNotNull(ConfigurationSnapshot.EMPTY.getOptional("foo"));
+
assertFalse(ConfigurationSnapshot.EMPTY.getOptional("foo").isPresent());
+ }
+
+ @Test
+ public void testEMPTY_getOrDefault_noValue(){
+ assertNull(ConfigurationSnapshot.EMPTY.getOrDefault("foo", null));
+ }
+
+ @Test
+ public void testEMPTY_getOrDefault_withValue(){
+ assertEquals("foo", ConfigurationSnapshot.EMPTY.getOrDefault("foo",
"foo"));
+ }
+
+ @Test
+ public void testEMPTY_getOptional_Iterable(){
+
assertNotNull(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo")));
+
assertFalse(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo")).isPresent());
+ }
+
+ @Test
+ public void testEMPTY_getOptional_Class_Iterable(){
+
assertNotNull(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo"),
String.class));
+
assertFalse(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo"),
String.class).isPresent());
+ }
+
+ @Test
+ public void testEMPTY_getOptional_Typeliteral_Iterable(){
+
assertNotNull(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo"),
TypeLiteral.of(String.class)));
+
assertFalse(ConfigurationSnapshot.EMPTY.getOptional(Collections.singleton("foo"),
TypeLiteral.of(String.class)).isPresent());
+ }
+
+ @Test
+ public void testEMPTY_get_Iterable(){
+
assertNull(ConfigurationSnapshot.EMPTY.get(Collections.singleton("foo")));
+ }
+
+ @Test
+ public void testEMPTY_get_Iterable_Class(){
+
assertNull(ConfigurationSnapshot.EMPTY.get(Collections.singleton("foo"),
String.class));
+ }
+
+ @Test
+ public void testEMPTY_getOrDefault_Class_withValue(){
+ assertEquals("foo", ConfigurationSnapshot.EMPTY.getOrDefault("foo",
String.class, "foo"));
+ }
+
+ @Test
+ public void testEMPTY_getOrDefault_TypeLiteral_withValue(){
+ assertEquals("foo", ConfigurationSnapshot.EMPTY.getOrDefault("foo",
TypeLiteral.of(String.class), "foo"));
+ }
+
+ @Test
+ public void testEMPTY_get_Iterable_TypeLiteral(){
+
assertNull(ConfigurationSnapshot.EMPTY.get(Collections.singleton("foo"),
TypeLiteral.of(String.class)));
+ }
+
+ @Test
+ public void testEMPTY_get_Classl(){
+ assertNull(ConfigurationSnapshot.EMPTY.get("foo",
TypeLiteral.of(String.class)));
+ }
+
+ @Test
+ public void testEMPTY_get_TypeLiteral(){
+ assertNull(ConfigurationSnapshot.EMPTY.get("foo",
TypeLiteral.of(String.class)));
+ }
+
+ @Test
+ public void testEMPTY_getKeys(){
+ assertNotNull(ConfigurationSnapshot.EMPTY.getKeys());
+ assertTrue(ConfigurationSnapshot.EMPTY.getKeys().isEmpty());
+ }
+
+ @Test
+ public void testEMPTY_getContext(){
+ assertEquals(ConfigurationContext.EMPTY,
ConfigurationSnapshot.EMPTY.getContext());
+ }
+
+ @Test
+ public void testEMPTY_getPropertiest(){
+ assertNotNull(ConfigurationSnapshot.EMPTY.getProperties());
+ assertTrue(ConfigurationSnapshot.EMPTY.getProperties().isEmpty());
+ }
+
+ @Test
+ public void testEMPTY_toBuildert(){
+ assertNotNull(ConfigurationSnapshot.EMPTY.toBuilder());
+ }
+
+ @Test
+ public void testEMPTY_toStringt(){
+ assertNotNull(ConfigurationSnapshot.EMPTY.toString());
+ }
+
+ @Test
+ public void testEMPTY_getSnapshot(){
+ assertEquals(ConfigurationSnapshot.EMPTY,
ConfigurationSnapshot.EMPTY.getSnapshot());
+ }
+
+ @Test
+ public void testEMPTY_getSnapshot_Keys(){
+ assertEquals(ConfigurationSnapshot.EMPTY,
ConfigurationSnapshot.EMPTY.getSnapshot("foo"));
+ }
+
+ @Test
+ public void testEMPTY_getSnapshot_Iterable(){
+ assertEquals(ConfigurationSnapshot.EMPTY,
ConfigurationSnapshot.EMPTY.getSnapshot(Collections.singletonList("foo")));
+ }
+
+}
\ No newline at end of file
diff --git
a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
index 9fc4433..663472c 100644
---
a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
+++
b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
@@ -69,6 +69,39 @@ public class BannerManagerTest {
}
@Test
+ public void valueLoggerSendsBannerToSystemOut() {
+
+ SecurityManager sm = new SecurityManager();
+ AccessControlContext con = AccessController.getContext();
+
+ Permission p = new RuntimePermission("setIO");
+
+ /*
+ * Here we check the precondition for this unit test
+ * and the correct setup of the test environment
+ * The JVM must have been started with
+ *
-Djava.security.policy=<path_to_core_module</src/test/resources/java-security.policy
+ */
+ sm.checkPermission(p, con);
+
+ PrintStream standard = System.out;
+ PrintStream printStream = Mockito.mock(PrintStream.class);
+
+ System.setOut(printStream);
+ standard.println("Changed stream for STDOUT successfully");
+
+ try {
+ BannerManager bm = new BannerManager("LOGGER");
+ bm.outputBanner();
+
+ } finally {
+ System.setOut(standard);
+ }
+
+ Mockito.verifyZeroInteractions(printStream);
+ }
+
+ @Test
public void invalidValueAvoidsLoggingToConsonle() {
PrintStream standard = System.out;
diff --git
a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..16c5f17
--- /dev/null
+++
b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
+import org.junit.Test;
+
+import java.util.*;
+
+import static org.assertj.core.api.Assertions.*;
+
+@Deprecated
+public class BasePropertySourceTest {
+
+ @Test
+ public void isAlwaysScanable() {
+ BasePropertySource bs = new EmptyPropertySource();
+
+ assertThat(bs.isScannable()).isTrue();
+ }
+
+ @Test
+ public void givenOrdinalOverwritesGivenDefaulOrdinal() {
+ BasePropertySource bs = new EmptyPropertySource();
+
+ bs.setDefaultOrdinal(10);
+
+ assertThat(bs.getDefaultOrdinal()).isEqualTo(10);
+ assertThat(bs.getOrdinal()).isEqualTo(10);
+
+ bs.setOrdinal(20);
+
+ assertThat(bs.getOrdinal()).isEqualTo(20);
+ }
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource(56) {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+
assertThat(PropertySourceComparator.getOrdinal(defaultPropertySource)).isEqualTo(56);
+ assertThat(new
OverriddenOrdinalPropertySource().getOrdinal()).isEqualTo(1000);
+
+ // propertySource with invalid ordinal
+ assertThat(new
OverriddenInvalidOrdinalPropertySource().getOrdinal()).isEqualTo(1);
+ }
+
+ @Test
+ public void testGet() {
+ assertThat(new
OverriddenOrdinalPropertySource().getOrdinal()).isEqualTo(1000);
+ }
+
+ @Test
+ public void testEqualsAndHashAndToStringValues() {
+ BasePropertySource bs1 = new EmptyPropertySource();
+ bs1.setName("testEqualsName");
+ BasePropertySource bs2 = new EmptyPropertySource();
+ bs2.setName("testEqualsName");
+ BasePropertySource bs3 = new EmptyPropertySource();
+ bs3.setName("testNotEqualsName");
+
+ assertThat(bs1).isEqualTo(bs1);
+ assertThat(bs1).isNotEqualTo(null);
+ assertThat("aString").isNotEqualTo(bs1);
+ assertThat(bs2).isEqualTo(bs1);
+ assertThat(bs1).isNotEqualTo(bs3);
+ assertThat(bs2.hashCode()).isEqualTo(bs1.hashCode());
+ assertThat(bs1.hashCode()).isNotEqualTo(bs3.hashCode());
+
assertThat(bs1.toStringValues().contains("name='testEqualsName'")).isTrue();
+ }
+
+ private class EmptyPropertySource extends BasePropertySource {
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+ }
+
+ private static class OverriddenOrdinalPropertySource extends
BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ super(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ Map<String, PropertyValue> result = new HashMap<>(1);
+ result.put(PropertySource.TAMAYA_ORDINAL,
PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "1000", getName()));
+ return result;
+ }
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends
BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ super(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ Map<String, PropertyValue> result = new HashMap<>(1);
+ result.put(PropertySource.TAMAYA_ORDINAL,
PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "invalid", getName()));
+ return result;
+ }
+ }
+
+}
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
index f63f110..fe8be43 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
@@ -39,8 +39,8 @@ public interface ConfigValueEvaluator {
* @param context the context, not null.
* @return the createValue, or null.
*/
- default PropertyValue evaluteRawValue(String key, ConfigurationContext
context){
- List<PropertyValue> values = evaluteAllValues(key, context);
+ default PropertyValue evaluateRawValue(String key, ConfigurationContext
context){
+ List<PropertyValue> values = evaluateAllValues(key, context);
if(values.isEmpty()){
return null;
}
@@ -53,7 +53,7 @@ public interface ConfigValueEvaluator {
* @param context the context, not null.
* @return the createValue, or null.
*/
- default List<PropertyValue> evaluteAllValues(String key,
ConfigurationContext context){
+ default List<PropertyValue> evaluateAllValues(String key,
ConfigurationContext context){
List<PropertyValue> result = new ArrayList<>();
for(PropertySource ps:context.getPropertySources()){
try{
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
index 22b0dfc..b71bc08 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
@@ -35,7 +35,7 @@ import java.util.Map;
public class DefaultConfigValueEvaluator implements ConfigValueEvaluator{
@Override
- public PropertyValue evaluteRawValue(String key, ConfigurationContext
context) {
+ public PropertyValue evaluateRawValue(String key, ConfigurationContext
context) {
PropertyValue unfilteredValue = null;
for (PropertySource propertySource : context.getPropertySources()) {
PropertyValue val = propertySource.get(key);
@@ -63,18 +63,6 @@ public class DefaultConfigValueEvaluator implements
ConfigValueEvaluator{
return result;
}
- /**
- * Default overriding policy.
- * @param currentValue the
- * @param key
- * @param propertySource
- * @return
- */
- private PropertyValue collect(PropertyValue currentValue, String key,
PropertySource propertySource) {
- PropertyValue value = propertySource.get(key);
- return value!=null?value:currentValue;
- }
-
@Override
public String toString() {
return "DefaultConfigEvaluator{}";
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
index 47a3b4c..8950d17 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
@@ -80,7 +80,7 @@ public class DefaultConfiguration implements Configuration {
public String get(String key) {
Objects.requireNonNull(key, "Key must not be null.");
- PropertyValue value = configEvaluator.evaluteRawValue(key,
configurationContext);
+ PropertyValue value = configEvaluator.evaluateRawValue(key,
configurationContext);
if(value==null || value.getValue()==null){
return null;
}
@@ -99,7 +99,7 @@ public class DefaultConfiguration implements Configuration {
public List<PropertyValue> getValues(String key) {
Objects.requireNonNull(key, "Key must not be null.");
- List<PropertyValue> value = configEvaluator.evaluteAllValues(key,
configurationContext);
+ List<PropertyValue> value = configEvaluator.evaluateAllValues(key,
configurationContext);
if(value==null || value.isEmpty()){
return Collections.emptyList();
}
@@ -115,11 +115,11 @@ public class DefaultConfiguration implements
Configuration {
* Evaluates the raw value.
* @param key the key, not null.
* @return the createValue, before filtering is applied.
- * @deprecated Use {@link ConfigValueEvaluator#evaluteRawValue(String,
ConfigurationContext)}.
+ * @deprecated Use {@link ConfigValueEvaluator#evaluateRawValue(String,
ConfigurationContext)}.
*/
@Deprecated
protected PropertyValue evaluteRawValue(String key) {
- return configEvaluator.evaluteRawValue(key, configurationContext);
+ return configEvaluator.evaluateRawValue(key, configurationContext);
}
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceChangeSupport.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceChangeSupport.java
index b587f91..d41b982 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceChangeSupport.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceChangeSupport.java
@@ -29,7 +29,6 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
-import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -55,9 +54,10 @@ public final class PropertySourceChangeSupport {
/**
* Create a new property change support instance.
* @param changeSupport the support type, not null.
- * @param propertySource the propertySource, not null.
+ * @param propertySource the property source to pass to listeners, not
null.
*/
- public PropertySourceChangeSupport(ChangeSupport changeSupport,
PropertySource propertySource){
+ public PropertySourceChangeSupport(ChangeSupport changeSupport,
+ PropertySource propertySource){
this.changeSupport = Objects.requireNonNull(changeSupport);
this.propertySource = Objects.requireNonNull(propertySource);
}
@@ -85,20 +85,32 @@ public final class PropertySourceChangeSupport {
}
public void removeChangeListener(BiConsumer<Set<String>, PropertySource>
l){
- listeners.remove(l);
+ if(changeSupport==ChangeSupport.SUPPORTED) {
+ listeners.remove(l);
+ }
}
public void removeAllChangeListeners(){
- listeners.clear();
+ if(changeSupport==ChangeSupport.SUPPORTED) {
+ listeners.clear();
+ }
}
- public long update(Map<String, PropertyValue> props){
- Set<String> changedKeys = calculateChangedKeys(this.valueMap, props);
- if(!changedKeys.isEmpty()) {
- this.valueMap = props;
- long newVersion = version.incrementAndGet();
- fireListeners(changedKeys);
- return newVersion;
+ public long load(Map<String, PropertyValue> properties){
+ Objects.requireNonNull(properties);
+ if(changeSupport==ChangeSupport.SUPPORTED) {
+ Set<String> changedKeys = calculateChangedKeys(this.valueMap,
properties);
+ if(!changedKeys.isEmpty()) {
+ this.valueMap = properties;
+ version.incrementAndGet();
+ fireListeners(changedKeys);
+ }
+ }
+ else{
+ if(!properties.equals(this.valueMap)){
+ this.valueMap = properties;
+ version.incrementAndGet();
+ }
}
return version.get();
}
@@ -131,13 +143,16 @@ public final class PropertySourceChangeSupport {
try{
l.accept(changedKeys, propertySource);
}catch(Exception e){
- LOG.log(Level.WARNING, "Failed to update listener on property
source change: " + l, e);
+ LOG.log(Level.WARNING, "Failed to load listener on property
source change: " + l, e);
}
}
}
public PropertyValue getValue(String key){
- return valueMap.get(key);
+ if(valueMap==null){
+ return null;
+ }
+ return valueMap.get(key);
}
public Map<String, PropertyValue> getProperties(){
@@ -147,14 +162,17 @@ public final class PropertySourceChangeSupport {
return Collections.unmodifiableMap(valueMap);
}
- public void scheduleChangeMonitor(Supplier<Map<String, PropertyValue>>
propsSupplier, long duration, TimeUnit timeUnit){
- scheduleTask = executorService.schedule(() -> {
- update(propsSupplier.get());
- }, duration, timeUnit);
+ public void scheduleChangeMonitor(Supplier<Map<String, PropertyValue>>
propertySupplier, long duration, TimeUnit timeUnit){
+ if(changeSupport==ChangeSupport.SUPPORTED) {
+ Objects.requireNonNull(propertySupplier);
+ scheduleTask = executorService.schedule(() -> {
+ load(propertySupplier.get());
+ }, duration, timeUnit);
+ }
}
public void cancelSchedule(){
- if(scheduleTask!=null){
+ if(changeSupport==ChangeSupport.SUPPORTED && scheduleTask!=null){
scheduleTask.cancel(false);
}
}
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
index f9704d7..3ddc74f 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
@@ -58,7 +58,7 @@ public class PropertiesResourcePropertySource extends
BasePropertySource {
public PropertiesResourcePropertySource(URL url, String prefix){
super(url.toExternalForm());
setPrefix(prefix);
- this.cachedProperties.update(loadProps(url));
+ this.cachedProperties.load(loadProps(url));
this.cachedProperties.scheduleChangeMonitor(() -> loadProps(url),
120, TimeUnit.SECONDS);
}
@@ -81,7 +81,7 @@ public class PropertiesResourcePropertySource extends
BasePropertySource {
public PropertiesResourcePropertySource(String path, String prefix,
ClassLoader cl){
super(path);
setPrefix(prefix);
- this.cachedProperties.update(loadProps(path, cl));
+ this.cachedProperties.load(loadProps(path, cl));
this.cachedProperties.scheduleChangeMonitor(() -> loadProps(path, cl),
120, TimeUnit.SECONDS);
}
diff --git
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
index 57c18b2..72c8af9 100644
---
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
+++
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
@@ -23,10 +23,7 @@ import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceChangeSupport;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -40,10 +37,10 @@ public class SystemPropertySource extends
BasePropertySource {
*/
public static final int DEFAULT_ORDINAL = 1000;
- private volatile PropertySourceChangeSupport cachedProperties = new
PropertySourceChangeSupport(
- ChangeSupport.SUPPORTED, this);
private AtomicInteger savedHashcode = new AtomicInteger();
+ private volatile PropertySourceChangeSupport cachedProperties = new
PropertySourceChangeSupport(
+ ChangeSupport.SUPPORTED, this);
/**
* Creates a new instance. Also initializes the {@code prefix} and {@code
disabled} properties
@@ -135,7 +132,7 @@ public class SystemPropertySource extends
BasePropertySource {
int hashCode = System.getProperties().hashCode();
if(hashCode!=this.savedHashcode.get()) {
this.savedHashcode.set(hashCode);
- this.cachedProperties.update(loadProperties());
+ this.cachedProperties.load(loadProperties());
}
}
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
index e3d8900..b69e936 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
@@ -25,6 +25,7 @@ import
org.apache.tamaya.spisupport.propertysource.BuildablePropertySourceProvid
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.assertNotNull;
public class BuildablePropertySourceProviderTest {
@@ -87,4 +88,9 @@ public class BuildablePropertySourceProviderTest {
assertThat(BuildablePropertySource.builder()).isNotEqualTo(BuildablePropertySource.builder());
}
+ @Test
+ public void testToString(){
+ assertNotNull(BuildablePropertySourceProvider.builder().toString());
+
assertNotNull(BuildablePropertySourceProvider.builder().build().toString());
+ }
}
\ No newline at end of file
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
index 773c8ca..23ddf8d 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
@@ -20,11 +20,15 @@ package org.apache.tamaya.spisupport;
import java.util.HashMap;
import java.util.Map;
+
+import org.apache.tamaya.spi.ChangeSupport;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class BuildablePropertySourceTest {
@Test
@@ -147,4 +151,16 @@ public class BuildablePropertySourceTest {
assertThat(BuildablePropertySource.builder()).isNotEqualTo(BuildablePropertySource.builder());
}
+ @Test
+ public void testToString(){
+ assertNotNull(BuildablePropertySource.builder().toString());
+ assertNotNull(BuildablePropertySource.builder().build().toString());
+ }
+
+ @Test
+ public void testGetChangeSupport(){
+ assertEquals(ChangeSupport.IMMUTABLE,
BuildablePropertySource.builder().build().getChangeSupport());
+ }
+
+
}
\ No newline at end of file
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/ConfigValueEvaluatorTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/ConfigValueEvaluatorTest.java
new file mode 100644
index 0000000..4b3b7d2
--- /dev/null
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/ConfigValueEvaluatorTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ConfigValueEvaluatorTest {
+
+ private ConfigValueEvaluator evaluator = new ConfigValueEvaluator(){};
+ private ConfigurationContext context = mock(ConfigurationContext.class);
+
+ @Before
+ public void initMock(){
+ PropertySource ps = BuildablePropertySource.builder()
+ .withName("MySource")
+ .withSimpleProperty("foo", "bar")
+ .build();
+
when(context.getPropertySources()).thenReturn(Collections.singletonList(ps));
+ }
+
+ @Test
+ public void evaluteRawValue() {
+ PropertyValue value = evaluator.evaluateRawValue("foo",
ConfigurationContext.EMPTY);
+ assertNull(value);
+ }
+
+ @Test
+ public void evaluteAllValues() {
+ List<PropertyValue> values = evaluator.evaluateAllValues("foo",
ConfigurationContext.EMPTY);
+ assertNotNull(values);
+ assertTrue(values.isEmpty());
+ }
+
+ @Test
+ public void evaluateRawValues() {
+ Map<String, PropertyValue> map =
evaluator.evaluateRawValues(ConfigurationContext.EMPTY);
+ assertNotNull(map);
+ assertTrue(map.isEmpty());
+ }
+}
\ No newline at end of file
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluatorTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluatorTest.java
index 8f13586..b2c0ed2 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluatorTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluatorTest.java
@@ -23,6 +23,7 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.assertNotNull;
/**
*
@@ -32,15 +33,15 @@ public class DefaultConfigValueEvaluatorTest {
/**
- * Test of evaluteRawValue method, of class DefaultConfigValueEvaluator.
+ * Test of evaluateRawValue method, of class DefaultConfigValueEvaluator.
*/
@Test
public void testEvaluteRawValue() {
Configuration config = Configuration.current();
DefaultConfigValueEvaluator instance = new
DefaultConfigValueEvaluator();
- PropertyValue result = instance.evaluteRawValue("confkey1",
config.getContext());
+ PropertyValue result = instance.evaluateRawValue("confkey1",
config.getContext());
assertThat(result.getValue()).isEqualTo("javaconf-value1");
- result = instance.evaluteRawValue("missing", config.getContext());
+ result = instance.evaluateRawValue("missing", config.getContext());
assertThat(result).isNull();
}
@@ -56,5 +57,9 @@ public class DefaultConfigValueEvaluatorTest {
assertThat(result.get("confkey1").getValue()).isEqualTo("javaconf-value1");
}
+ @Test
+ public void testToString(){
+ assertNotNull(new DefaultConfigValueEvaluator().toString());
+ }
}
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationSnapshotTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationSnapshotTest.java
index b351c91..2e20ad1 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationSnapshotTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationSnapshotTest.java
@@ -20,26 +20,36 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationSnapshot;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
public class DefaultConfigurationSnapshotTest {
+// confkey1=javaconf-value1
+// confkey2=javaconf-value2
+// confkey3=javaconf-value3
+
+ @Test
+ public void testCreationForKeys() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ }
+
@Test
public void getFrozenAtReturnsTheCorrectTimestamp() throws
InterruptedException {
- Configuration source = Mockito.mock(Configuration.class);
+ Configuration source = mock(Configuration.class);
Mockito.when(source.getContext()).thenReturn(ConfigurationContext.EMPTY);
Mockito.when(source.getSnapshot(Mockito.anyCollection())).thenReturn(ConfigurationSnapshot.EMPTY);
Mockito.when(source.getSnapshot()).thenReturn(ConfigurationSnapshot.EMPTY);
@@ -59,7 +69,7 @@ public class DefaultConfigurationSnapshotTest {
@Test
public void idMustBeNotNull() {
- Configuration source = Mockito.mock(Configuration.class);
+ Configuration source = mock(Configuration.class);
Mockito.when(source.getContext()).thenReturn(ConfigurationContext.EMPTY);
Mockito.when(source.getProperties()).thenReturn(Collections.emptyMap());
@@ -77,7 +87,7 @@ public class DefaultConfigurationSnapshotTest {
Map<String, String> properties = new HashMap<>();
properties.put("key", "createValue");
- Configuration configuration = Mockito.mock(Configuration.class);
+ Configuration configuration = mock(Configuration.class);
Mockito.when(configuration.getContext()).thenReturn(ConfigurationContext.EMPTY);
doReturn(properties).when(configuration).getProperties();
@@ -90,4 +100,157 @@ public class DefaultConfigurationSnapshotTest {
/*
* END OF ALL TESTS for equals() and hashCode()
*/
+
+ @Test
+ public void testGetContext() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+
assertEquals(config.getContext().getPropertySources().size(),snapshot.getContext().getPropertySources().size());
+
assertEquals(config.getContext().getPropertyConverters().size(),snapshot.getContext().getPropertyConverters().size());
+
assertEquals(config.getContext().getPropertyFilters().size(),snapshot.getContext().getPropertyFilters().size());
+ }
+
+ @Test
+ public void testGet() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertEquals("javaconf-value1", snapshot.get("confkey1"));
+ assertEquals("javaconf-value2", snapshot.get("confkey2"));
+ assertEquals("javaconf-value3", snapshot.get("confkey3"));
+ assertNull(snapshot.getOrDefault("confkey4", null));
+ assertEquals("javaconf-value1", snapshot.get("confkey1",
String.class));
+ assertEquals("javaconf-value2", snapshot.get("confkey2",
String.class));
+ assertEquals("javaconf-value3", snapshot.get("confkey3",
String.class));
+ assertNull(snapshot.getOrDefault("confkey4", String.class, null));
+ assertEquals("javaconf-value1", snapshot.get("confkey1",
TypeLiteral.of(String.class)));
+ assertEquals("javaconf-value2", snapshot.get("confkey2",
TypeLiteral.of(String.class)));
+ assertEquals("javaconf-value3", snapshot.get("confkey3",
TypeLiteral.of(String.class)));
+ assertNull(snapshot.getOrDefault("confkey4",
TypeLiteral.of(String.class), null));
+ }
+
+ @Test
+ public void testGet_with_Subset() {
+ Configuration config = Configuration.current();
+ ConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ snapshot = snapshot.getSnapshot(Arrays.asList("confkey1"));
+ assertEquals("javaconf-value1", snapshot.get("confkey1"));
+ assertNull(snapshot.getOrDefault("confkey2", null));
+ assertEquals("javaconf-value1", snapshot.get("confkey1",
String.class));
+ assertNull(snapshot.getOrDefault("confkey2", String.class, null));
+ assertEquals("javaconf-value1", snapshot.get("confkey1",
TypeLiteral.of(String.class)));
+ assertNull(snapshot.getOrDefault("confkey2",
TypeLiteral.of(String.class), null));
+ }
+
+ @Test
+ public void testGet_with_MultiKey() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertEquals("javaconf-value1", snapshot.get(Arrays.asList("confkey1",
"foo")));
+ assertEquals("javaconf-value2", snapshot.get(Arrays.asList("foo",
"confkey2")));
+ assertEquals("javaconf-value1", snapshot.get(Arrays.asList("confkey1",
"foo"), String.class));
+ assertEquals("javaconf-value2", snapshot.get(Arrays.asList("foo",
"confkey2"), String.class));
+ }
+
+ @Test
+ public void testGetOrDefault() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertEquals("javaconf-value1", snapshot.getOrDefault("confkey1",
"foo"));
+ assertEquals("javaconf-value2", snapshot.getOrDefault("confkey2",
"foo"));
+ assertEquals("javaconf-value2", snapshot.getOrDefault("confkey2",
String.class,"foo"));
+ assertEquals("javaconf-value3", snapshot.getOrDefault("confkey3",
"foo"));
+ assertEquals("foo", snapshot.getOrDefault("confkey4", "foo"));
+ assertEquals("foo", snapshot.getOrDefault("confkey4",
String.class,"foo"));
+ }
+
+ @Test
+ public void testGetProperties() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3", "missing"));
+ Map<String, String> properties = snapshot.getProperties();
+ assertNotNull(properties);
+ assertEquals(3, properties.size());
+ assertEquals("javaconf-value1", properties.get("confkey1"));
+ assertEquals("javaconf-value2", properties.get("confkey2"));
+ assertEquals("javaconf-value3", properties.get("confkey3"));
+ assertEquals(null, properties.get("confkey4"));
+ }
+
+ @Test
+ public void testGetId() {
+ Configuration config = Configuration.current();
+ ConfigurationSnapshot snapshot1 = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3", "foo"));
+ ConfigurationSnapshot snapshot2 = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3", "foo"));
+ assertNotEquals(snapshot1, snapshot2);
+ assertNotEquals(((DefaultConfigurationSnapshot) snapshot1).getId(),
+ ((DefaultConfigurationSnapshot) snapshot2).getId());
+ }
+
+ @Test
+ public void testGetOrDefault_withSubset() {
+ Configuration config = Configuration.current();
+ ConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ snapshot = snapshot.getSnapshot(Arrays.asList("confkey1"));
+ assertEquals("javaconf-value1", snapshot.getOrDefault("confkey1",
"foo"));
+ assertEquals("foo", snapshot.getOrDefault("confkey2", "foo"));
+ assertEquals("javaconf-value1", snapshot.getOrDefault("confkey1",
String.class,"foo"));
+ assertEquals("foo", snapshot.getOrDefault("confkey2", String.class,
"foo"));
+ }
+
+ @Test
+ public void testGetOrDefault_with_MultiKey() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertEquals("javaconf-value1",
snapshot.getOrDefault(Arrays.asList("confkey1", "foo"), "foo"));
+ assertEquals("foo", snapshot.getOrDefault(Arrays.asList("confkeyNone",
"foo"), "foo"));
+ assertEquals("javaconf-value1",
snapshot.getOrDefault(Arrays.asList("confkey1", "foo"), String.class, "foo"));
+ assertEquals("foo", snapshot.getOrDefault(Arrays.asList("confkeyNone",
"foo"), String.class, "foo"));
+ }
+
+ @Test
+ public void testGetKeys() {
+ Configuration config = Configuration.current();
+ DefaultConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertTrue(snapshot.getKeys().contains("confkey1"));
+ assertTrue(snapshot.getKeys().contains("confkey2"));
+ assertTrue(snapshot.getKeys().contains("confkey3"));
+ assertFalse(snapshot.getKeys().contains("confkey4"));
+ assertFalse(snapshot.getKeys().contains("foo"));
+ }
+
+ @Test
+ public void testGetKeys_Subkeys() {
+ Configuration config = Configuration.current();
+ ConfigurationSnapshot snapshot = new
DefaultConfigurationSnapshot(config,
+ Arrays.asList("confkey1", "confkey2", "confkey3"));
+ assertTrue(snapshot.getKeys().contains("confkey1"));
+ assertTrue(snapshot.getKeys().contains("confkey2"));
+ assertTrue(snapshot.getKeys().contains("confkey3"));
+ assertFalse(snapshot.getKeys().contains("confkey4"));
+ assertFalse(snapshot.getKeys().contains("foo"));
+ snapshot = snapshot.getSnapshot(Arrays.asList("confkey1", "confkey2"));
+ assertTrue(snapshot.getKeys().contains("confkey1"));
+ assertTrue(snapshot.getKeys().contains("confkey2"));
+ assertFalse(snapshot.getKeys().contains("confkey3"));
+ assertFalse(snapshot.getKeys().contains("confkey4"));
+ assertFalse(snapshot.getKeys().contains("foo"));
+ snapshot = snapshot.getSnapshot(Arrays.asList("confkey1", "foo"));
+ assertTrue(snapshot.getKeys().contains("confkey1"));
+ assertFalse(snapshot.getKeys().contains("confkey2"));
+ assertFalse(snapshot.getKeys().contains("confkey3"));
+ assertFalse(snapshot.getKeys().contains("confkey4"));
+ assertTrue(snapshot.getKeys().contains("foo"));
+ }
+
}
\ No newline at end of file
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
index a771041..854d0c2 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
@@ -260,7 +260,7 @@ public class DefaultConfigurationTest {
DefaultConfiguration c = new DefaultConfiguration(new
MockedConfigurationContext());
assertThat("testQ").isEqualTo(c.adapt(config -> "testQ"));
}
-
+
@Test
public void testEqualsAndHashAndToStringValues() {
ConfigurationContext sharedContext = new MockedConfigurationContext();
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertySourceChangeSupportTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertySourceChangeSupportTest.java
new file mode 100644
index 0000000..90e7b9e
--- /dev/null
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertySourceChangeSupportTest.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.spi.ChangeSupport;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+/**
+ * Tests for {@link java.beans.PropertyChangeSupport}.
+ */
+public class PropertySourceChangeSupportTest {
+
+ @Test
+ public void getChangeSupport() {
+ PropertySource ps =
BuildablePropertySource.builder().withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ assertEquals(ChangeSupport.IMMUTABLE, support.getChangeSupport());
+ support = new PropertySourceChangeSupport(ChangeSupport.UNSUPPORTED,
ps);
+ assertEquals(ChangeSupport.UNSUPPORTED, support.getChangeSupport());
+ }
+
+ @Test
+ public void getVersion_Immutable() {
+ PropertySource ps =
BuildablePropertySource.builder().withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ support.load(ps.getProperties());
+ String v0 = support.getVersion();
+ assertNotNull(v0);
+ String v1 = support.getVersion();
+ support.load(Collections.emptyMap());
+ String v2 = support.getVersion();
+ assertEquals(v0, v1);
+ assertEquals(v1, v2);
+ }
+
+ @Test
+ public void getVersion() {
+ PropertySource ps =
BuildablePropertySource.builder().withSimpleProperty("foo",
"bar").withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.SUPPORTED, ps);
+ support.load(ps.getProperties());
+ String v0 = support.getVersion();
+ assertNotNull(v0);
+ String v1 = support.getVersion();
+ support.load(Collections.emptyMap());
+ String v2 = support.getVersion();
+ assertEquals(v0, v1);
+ assertNotEquals(v1, v2);
+ }
+
+ @Test
+ public void addChangeListener() {
+ PropertySource ps = BuildablePropertySource.builder().withName("test").
+ withSimpleProperty("foo", "bar").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.SUPPORTED, ps);
+ support.load(ps.getProperties());
+ BiConsumer<Set<String>, PropertySource> l = mock(BiConsumer.class);
+ support.addChangeListener(l);
+ support.load(Collections.emptyMap());
+ verify(l).accept(any(), any());
+ }
+
+ @Test
+ public void removeChangeListener() {
+ PropertySource ps =
BuildablePropertySource.builder().withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.SUPPORTED, ps);
+ BiConsumer<Set<String>, PropertySource> l = mock(BiConsumer.class);
+ support.addChangeListener(l);
+ support.removeChangeListener(l);
+ support.load(Collections.emptyMap());
+ verifyNoMoreInteractions(l);
+ }
+
+ @Test
+ public void removeAllChangeListeners() {
+ PropertySource ps =
BuildablePropertySource.builder().withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ BiConsumer<Set<String>, PropertySource> l = mock(BiConsumer.class);
+ support.addChangeListener(l);
+ support.removeAllChangeListeners();
+ support.load(Collections.emptyMap());
+ verifyNoMoreInteractions(l);
+ }
+
+ @Test
+ public void update() {
+ PropertySource ps =
BuildablePropertySource.builder().withName("test").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ support.load(Collections.emptyMap());
+ }
+
+ @Test
+ public void getValue() {
+ PropertySource ps =
BuildablePropertySource.builder().withSimpleProperty("foo",
"bar").withName("test")
+ .withSimpleProperty("foo", "bar").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ support.load(ps.getProperties());
+ assertNotNull(support.getValue("foo"));
+ assertNull(support.getValue("bar"));
+ }
+
+ @Test
+ public void getProperties() {
+ PropertySource ps = BuildablePropertySource.builder().withName("test")
+ .withSimpleProperty("foo", "bar").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ Map properties = support.getProperties();
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ support.load(ps.getProperties());
+ properties = support.getProperties();
+ assertNotNull(properties);
+ assertEquals(1, properties.size());
+ }
+
+ @Test
+ public void scheduleChangeMonitor() throws InterruptedException {
+ PropertySource ps = BuildablePropertySource.builder().withName("test")
+ .withSimpleProperty("foo", "bar").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.SUPPORTED, ps);
+ support.load(ps.getProperties());
+ String v1 = support.getVersion();
+ support.scheduleChangeMonitor(() -> Collections.emptyMap(), 500,
TimeUnit.MILLISECONDS);
+ Thread.sleep(600L);
+ String v2 = support.getVersion();
+ assertNotEquals(v1, v2);
+ }
+
+ @Test
+ public void cancelSchedule() throws InterruptedException {
+ PropertySource ps = BuildablePropertySource.builder().withName("test")
+ .withSimpleProperty("foo", "bar").build();
+ PropertySourceChangeSupport support = new
PropertySourceChangeSupport(ChangeSupport.IMMUTABLE, ps);
+ support.load(ps.getProperties());
+ String v1 = support.getVersion();
+ support.scheduleChangeMonitor(() -> Collections.emptyMap(), 1,
TimeUnit.SECONDS);
+ Thread.sleep(500L);
+ support.cancelSchedule();
+ String v2 = support.getVersion();
+ assertEquals(v1, v2);
+ }
+}
\ No newline at end of file
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
index f98ccac..aa34456 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
@@ -20,23 +20,43 @@ package org.apache.tamaya.spisupport.propertysource;
import java.io.File;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ChangeSupport;
import org.apache.tamaya.spi.PropertyValue;
import
org.apache.tamaya.spisupport.propertysource.SimplePropertySource.Builder;
import org.junit.Test;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.assertEquals;
public class SimplePropertySourceTest {
@Test
- public void successfulCreationWithPropertiesFromXMLPropertiesFile() {
+ public void successfulCreationWithPropertiesFromXMLPropertiesFile() throws
URISyntaxException {
URL resource = getClass().getResource("/valid-properties.xml");
+ File resourceFile = new File(resource.toURI());
+ SimplePropertySource source = new SimplePropertySource(resourceFile);
+ assertThat(source).isNotNull();
+ assertThat(source.getProperties()).hasSize(2); // double the
getNumChilds for .source values.
+ assertThat(source.getProperties()).contains(entry("a",
PropertyValue.of("a", "b", resource.toString())));
+ assertThat(source.getProperties()).contains(entry("b",
PropertyValue.of("b", "1", resource.toString())));
+ }
+
+ @Test(expected=ConfigException.class)
+ public void successfulCreationWithPropertiesFromInvalidsFile() throws
URISyntaxException {
+ File resourceFile = new File("fooe.file");
+ new SimplePropertySource(resourceFile);
+ }
+
+ @Test
+ public void successfulCreationWithPropertiesFromURL() throws
URISyntaxException {
+ URL resource = getClass().getResource("/valid-properties.xml");
SimplePropertySource source = new SimplePropertySource(resource);
assertThat(source).isNotNull();
@@ -46,6 +66,39 @@ public class SimplePropertySourceTest {
}
@Test
+ public void successfulCreationWithPropertiesFromXMLPropertiesResource() {
+ URL resource = getClass().getResource("/valid-properties.xml");
+
+ SimplePropertySource source = new SimplePropertySource(resource);
+
+ assertThat(source).isNotNull();
+ assertThat(source.getProperties()).hasSize(2); // double the
getNumChilds for .source values.
+ assertThat(source.getProperties()).contains(entry("a",
PropertyValue.of("a", "b", resource.toString())));
+ assertThat(source.getProperties()).contains(entry("b",
PropertyValue.of("b", "1", resource.toString())));
+ }
+
+ @Test
+ public void successfulCreationWithProperties() {
+ URL resource = getClass().getResource("/valid-properties.xml");
+ Map<String,String> props = new HashMap<>();
+ props.put("a", "b");
+ props.put("b", "1");
+ SimplePropertySource source = new SimplePropertySource("test", props);
+
+ assertThat(source).isNotNull();
+ assertThat(source.getProperties()).hasSize(2); // double the
getNumChilds for .source values.
+ assertThat(source.getProperties()).contains(entry("a",
PropertyValue.of("a", "b", "test")));
+ assertThat(source.getProperties()).contains(entry("b",
PropertyValue.of("b", "1", "test")));
+ }
+
+ @Test
+ public void getChangeSupport(){
+ URL resource = getClass().getResource("/valid-properties.xml");
+ SimplePropertySource source = new SimplePropertySource(resource);
+ assertEquals(ChangeSupport.IMMUTABLE, source.getChangeSupport());
+ }
+
+ @Test
public void failsToCreateFromNonXMLPropertiesXMLFile() {
URL resource = getClass().getResource("/non-xml-properties.xml");
ConfigException catchedException = null;
diff --git
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
index 0139268..271c47c 100644
---
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
+++
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
@@ -28,12 +28,24 @@ import org.junit.Test;
import java.util.Map;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class SystemPropertySourceTest {
private final SystemPropertySource testPropertySource = new
SystemPropertySource();
@Test
+ public void testConstrcutorWithPrefix() throws Exception {
+ SystemPropertySource testPropertySource = new
SystemPropertySource("PRE::");
+ assertNotNull(testPropertySource.getProperties());
+ for(Map.Entry en:System.getProperties().entrySet()){
+ assertEquals(System.getProperty(en.getKey().toString()),
+ testPropertySource.get("PRE::"+en.getKey()).getValue());
+ }
+ }
+
+ @Test
public void testConstructionPropertiesAndDisabledBehavior() throws
IOException {
SystemPropertySource localSystemPropertySource;
StringWriter stringBufferWriter = new StringWriter();
diff --git
a/code/spi-support/src/test/resources/META-INF/javaconfiguration.properties
b/code/spi-support/src/test/resources/META-INF/javaconfiguration.properties
index 33beabb..e907419 100644
--- a/code/spi-support/src/test/resources/META-INF/javaconfiguration.properties
+++ b/code/spi-support/src/test/resources/META-INF/javaconfiguration.properties
@@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
confkey1=javaconf-value1
confkey2=javaconf-value2
confkey3=javaconf-value3