You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/05/21 09:40:19 UTC
[01/15] incubator-tamaya git commit: Fixed bugs in TypeLiteral with
code from OpenWebBeans. Unified test file location in RIs. Added tests for
uncoveraged areas.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master f49c07c26 -> d941df7fc
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
deleted file mode 100644
index 2eba79e..0000000
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.Properties;
-
-public class SystemPropertySourceTest {
-
- private SystemPropertySource testPropertySource = new SystemPropertySource();
-
-
- @Test
- public void testGetOrdinal() throws Exception {
-
- // test the default ordinal
- Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
-
- // set the ordinal to 1000
- System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
- Assert.assertEquals(1000, new SystemPropertySource().getOrdinal());
- // currently its not possible to change ordinal at runtime
-
- // reset it to not destroy other tests!!
- System.clearProperty(PropertySource.TAMAYA_ORDINAL);
- }
-
- @Test
- public void testGetName() throws Exception {
- Assert.assertEquals("system-properties", new SystemPropertySource().getName());
- }
-
- @Test
- public void testGet() throws Exception {
- String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
-
- String property = testPropertySource.get(propertyKeyToCheck);
- Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
- property != null);
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
-
-
- }
-
- @Test
- public void testGetProperties() throws Exception {
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // modify system properties
- System.setProperty("test", "myTestVal");
-
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // cleanup
- System.clearProperty("test");
-
- // no modifaction
- try {
- testPropertySource.getProperties().put("add.new.keys", "must throw exception");
- Assert.fail(UnsupportedOperationException.class.getName() + " expected");
- }
- catch (UnsupportedOperationException e) {
- // expected -> all is fine
- }
- }
-
- private void checkWithSystemProperties(Map<String, String> toCheck) {
- Properties systemEntries = System.getProperties();
-
- Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
- systemEntries.entrySet().size(), toCheck.size());
-
- for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
-
- Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
- systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
deleted file mode 100644
index dfb5ff1..0000000
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.test.provider;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.core.provider.JavaConfigurationProvider;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collection;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-
-public class JavaConfigurationProviderTest {
-
- @Test
- public void testJavaConfigurationProvider() {
-
- Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
-
- assertThat(propertySources, notNullValue());
- assertThat(propertySources, hasSize(1));
-
- PropertySource propertySource = propertySources.iterator().next();
-
- assertThat(propertySource.getProperties().keySet(), hasSize(5));
-
- for (int i = 1; i < 6; i++) {
- String key = "confkey" + i;
- String value = "javaconf-value" + i;
-
- Assert.assertEquals(value, propertySource.get(key));
-
- // check if we had our key in configuration.current
- Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
- Assert.assertEquals(value, ConfigurationProvider.getConfiguration().getOptional(key).get());
- }
-
- }
-
-}
[06/15] incubator-tamaya git commit: Moved PropertySourceBuilder from
resource module to builder module. Minor Javadoc change.
Posted by an...@apache.org.
Moved PropertySourceBuilder from resource module to builder module.
Minor Javadoc change.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/391671af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/391671af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/391671af
Branch: refs/heads/master
Commit: 391671af5bb5d64ce179726d64671b83a18f0b51
Parents: 3013dbd
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:28:44 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:28:44 2015 +0200
----------------------------------------------------------------------
.../tamaya/builder/ConfigurationBuilder.java | 2 +-
.../tamaya/builder/PropertySourceBuilder.java | 118 +++++++++++++
.../tamaya/builder/SimplePropertySource.java | 55 +++++++
modules/events/pom.xml | 5 +
.../tamaya/events/ObservedConfigTest.java | 164 -------------------
.../tamaya/events/TestObservingProvider.java | 40 +++++
.../events/delta/PropertySourceChangeTest.java | 26 +--
.../tamaya/resource/PropertySourceBuilder.java | 81 ---------
sandbox/remote/pom.xml | 5 +
9 files changed, 237 insertions(+), 259 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 799b114..82eb3eb 100644
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -71,7 +71,7 @@ import static java.lang.String.format;
*
* <p><strong>Support for configuration formats</strong></p>
*
- * The configuration builder allows you to add property resources
+ * The configuration builder allows you to put property resources
* via a URL, as shown in the code example above, without implementing
* a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
* instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/modules/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
new file mode 100644
index 0000000..e298939
--- /dev/null
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
+ */
+public final class PropertySourceBuilder {
+ /** The ordinal to be used. */
+ private int ordinal;
+ /** The name to be used. */
+ private String name;
+ /** The properties. */
+ private Map<String,String> properties = new HashMap<>();
+
+ /** private constructor. */
+ private PropertySourceBuilder(String name){
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder of(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder from(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Sets a new property key/value.
+ * @param key the property key, not null.
+ * @param value the property value, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder put(String key, String value){
+ this.properties.put(key, value);
+ return this;
+ }
+
+ /**
+ * Put all the given key, values.
+ * @param values the new key/values, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(Map<String, String> values){
+ this.properties.putAll(values);
+ return this;
+ }
+
+ /**
+ * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
+ * @param ordinal the explicit ordinal to be used.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder withOrdinal(int ordinal){
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * Puts all values from the given property source.
+ * @param propertySource the property source, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(PropertySource propertySource){
+ this.properties.putAll(propertySource.getProperties());
+ return this;
+ }
+
+ /**
+ * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance.
+ * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null.
+ */
+ public PropertySource build(){
+ return new SimplePropertySource(name, properties);
+ }
+
+ @Override
+ public String toString() {
+ return "PropertySourceBuilder{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
new file mode 100644
index 0000000..f343973
--- /dev/null
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+* Simple property source implementation using a map.
+*/
+public class SimplePropertySource implements PropertySource {
+ /** The properties. */
+ private Map<String, String> properties;
+ /** The source's name. */
+ private String name;
+
+ public SimplePropertySource(String name, Map<String, String> properties){
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.properties;
+ }
+
+ @Override
+ public String toString(){
+ return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index e23dd1d..0da9ec9 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -43,6 +43,11 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-builder</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java b/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
index bc3d087..d954ce0 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
@@ -21,19 +21,12 @@ package org.apache.tamaya.events;
import org.apache.commons.io.FileUtils;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.Map;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
@@ -42,68 +35,6 @@ import static org.junit.Assert.assertEquals;
*/
public class ObservedConfigTest {
- private static Path getSourceFile(String name) throws Exception {
- URL url = ObservedConfigTest.class.getResource("/data");
- File testFile = new File(new File(url.toURI()), name);
- return Paths.get(testFile.toURI());
- }
-
- private static Path getTargetFile(String name) {
- File testFile = new File(TestObservingProvider.getTestDirectory(), name);
- return Paths.get(testFile.toURI());
- }
-
- /**
- * Test method that periodically prints out what is happening.
- */
- public static void main() {
- while (true) {
- System.out.println("1: " + ConfigurationProvider.getConfiguration().get("1"));
- System.out.println("2: " + ConfigurationProvider.getConfiguration().get("2"));
- System.out.println("3: " + ConfigurationProvider.getConfiguration().get("3"));
- System.out.println("4: " + ConfigurationProvider.getConfiguration().get("4"));
- System.out.println("5: " + ConfigurationProvider.getConfiguration().get("5"));
- System.out.println("6: " + ConfigurationProvider.getConfiguration().get("6"));
- System.out.println("=======================================================================");
- try {
- Thread.sleep(2000L);
- } catch (Exception e) {
- // stop here...
- }
- }
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- // cleanup directory
- Files.deleteIfExists(getTargetFile("test1.properties"));
- Files.deleteIfExists(getTargetFile("test2.properties"));
- Files.deleteIfExists(getTargetFile("test3.properties"));
- }
-
- @Before
- public void setup() throws IOException {
- // create some temporary config
- Path tempDir = Files.createTempDirectory("observedFolder");
-
- TestObservingProvider.propertyLocation = tempDir;
-
- FileUtils.copyInputStreamToFile(
- getClass().getResourceAsStream("/test.properties"),
- new File(tempDir.toFile(), "test.properties"));
- }
-
- public void testInitialConfig() throws IOException {
- Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
-
- Map<String, String> props = config.getProperties();
-
- assertEquals(props.get("test"), "test2");
- assertEquals(props.get("testValue1"), "value");
- assertNull(props.get("a"));
-
- }
-
@Test
public void testChangingConfig() throws IOException {
Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
@@ -133,99 +64,4 @@ public class ObservedConfigTest {
assertEquals(props.get("testValue2"), "anotherValue");
}
- @Test
- //Y TODO Check tests later
- public void testConfigChanges() throws Exception {
-// // test empty directory
-// testEmpty();
-// // add a file, test for changes
-// Files.copy(getSourceFile("test1.properties"), getTargetFile("test1.properties"));
-// try {
-// Thread.sleep(2000L);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// testProperties1();
-// Files.copy(getSourceFile("test2.properties"), getTargetFile("test2.properties"));
-// Files.copy(getSourceFile("test3.properties"), getTargetFile("test3.properties"));
-// try {
-// Thread.sleep(2000L);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// testAllFiles();
-// // change a file, test for changes
-// Files.copy(getSourceFile("test1b.properties"), getTargetFile("test1.properties"));
-// try {
-// Thread.sleep(2000L);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// testProperties2();
-// // remove a file, test for changes
-// Files.delete(getTargetFile("test2.properties"));
-// try {
-// Thread.sleep(2000L);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// testProperties3();
-// // cleanup directory
-// Files.deleteIfExists(getTargetFile("test1.properties"));
-// Files.deleteIfExists(getTargetFile("test2.properties"));
-// Files.deleteIfExists(getTargetFile("test3.properties"));
-// try {
-// Thread.sleep(2000L);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// testEmpty();
- }
-
- private void testEmpty() {
- assertNull(ConfigurationProvider.getConfiguration().get("1"));
- assertNull(ConfigurationProvider.getConfiguration().get("2"));
- assertNull(ConfigurationProvider.getConfiguration().get("3"));
- assertNull(ConfigurationProvider.getConfiguration().get("4"));
- assertNull(ConfigurationProvider.getConfiguration().get("5"));
- assertNull(ConfigurationProvider.getConfiguration().get("6"));
- }
-
- private void testAllFiles() {
- assertNotNull(ConfigurationProvider.getConfiguration().get("1"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("2"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("3"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("4"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("5"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("6"));
- }
-
- private void testProperties1() {
- assertNotNull(ConfigurationProvider.getConfiguration().get("1"));
- assertNull(ConfigurationProvider.getConfiguration().get("2"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("3"));
- assertNull(ConfigurationProvider.getConfiguration().get("4"));
- assertNull(ConfigurationProvider.getConfiguration().get("5"));
- assertNull(ConfigurationProvider.getConfiguration().get("6"));
- }
-
- private void testProperties2() {
- assertNotNull(ConfigurationProvider.getConfiguration().get("1"));
- assertNull(ConfigurationProvider.getConfiguration().get("2"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("3"));
- assertNull(ConfigurationProvider.getConfiguration().get("4"));
- assertNull(ConfigurationProvider.getConfiguration().get("5"));
- assertNull(ConfigurationProvider.getConfiguration().get("6"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("7"));
- }
-
- private void testProperties3() {
- assertNotNull(ConfigurationProvider.getConfiguration().get("1"));
- assertNull(ConfigurationProvider.getConfiguration().get("2"));
- assertNotNull(ConfigurationProvider.getConfiguration().get("3"));
- assertNull(ConfigurationProvider.getConfiguration().get("4"));
- assertNull(ConfigurationProvider.getConfiguration().get("5"));
- assertNull(ConfigurationProvider.getConfiguration().get("6"));
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
index 775de58..160c117 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.events;
+import org.apache.commons.io.FileUtils;
import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
import org.apache.tamaya.format.formats.PropertiesFormat;
@@ -26,6 +27,7 @@ import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.FileSystem;
+import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -33,6 +35,7 @@ import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.Iterator;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -42,6 +45,43 @@ public class TestObservingProvider extends ObservingPropertySourceProvider{
public static Path propertyLocation;
+ static{
+ try {
+ // create some temporary config
+ Path tempDir = Files.createTempDirectory("observedFolder");
+
+ TestObservingProvider.propertyLocation = tempDir;
+
+ FileUtils.copyInputStreamToFile(
+ TestObservingProvider.class.getResourceAsStream("/test.properties"),
+ new File(tempDir.toFile(), "test.properties"));
+
+ Runtime.getRuntime().addShutdownHook(new Thread(){
+ @Override
+ public void run(){
+ try{
+ // cleanup directory
+ Files.deleteIfExists(getTargetFile("test1.properties"));
+ Files.deleteIfExists(getTargetFile("test2.properties"));
+ Files.deleteIfExists(getTargetFile("test3.properties"));
+ }
+ catch(Exception e){
+ Logger.getLogger("TestObservingProvider").log(Level.WARNING,
+ "Failed to cleanup config test dir", e);
+ }
+ }
+ });
+ }
+ catch(Exception e){
+ Logger.getLogger("TestObservingProvider").log(Level.WARNING, "Failed to init config test dir", e);
+ }
+ }
+
+ private static Path getTargetFile(String name) {
+ File testFile = new File(TestObservingProvider.getTestDirectory(), name);
+ return Paths.get(testFile.toURI());
+ }
+
public TestObservingProvider(){
super(propertyLocation,
new PropertiesFormat());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
index b3b6145..770bd5d 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.events.delta;
+import org.apache.tamaya.builder.PropertySourceBuilder;
import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.resource.PropertySourceBuilder;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
@@ -99,10 +99,10 @@ public class PropertySourceChangeTest {
@Test
public void testIsRemoved() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
- .add("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
- .add("key3", "value3").build();
+ PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
+ .put("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
+ .put("key3", "value3").build();
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
@@ -114,10 +114,10 @@ public class PropertySourceChangeTest {
@Test
public void testIsAdded() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
- .add("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
- .add("key3", "value3").build();
+ PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
+ .put("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
+ .put("key3", "value3").build();
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
@@ -129,10 +129,10 @@ public class PropertySourceChangeTest {
@Test
public void testIsUpdated() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
- .add("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
- .add("key3", "value3").build();
+ PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
+ .put("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
+ .put("key3", "value3").build();
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/modules/resources/src/main/java/org/apache/tamaya/resource/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/PropertySourceBuilder.java b/modules/resources/src/main/java/org/apache/tamaya/resource/PropertySourceBuilder.java
deleted file mode 100644
index 5a387ee..0000000
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/PropertySourceBuilder.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.resource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
- */
-public final class PropertySourceBuilder {
- private int ordinal;
- private String name;
- private Map<String,String> properties = new HashMap<>();
-
- /** private constructor. */
- private PropertySourceBuilder(String name){
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Gets a new instance of a builder.
- * @param name The name of the property source, not null.
- * @return a new instance.
- */
- public static PropertySourceBuilder of(String name){
- return new PropertySourceBuilder(name);
- }
-
- /**
- * Gets a new instance of a builder.
- * @param name The name of the property source, not null.
- * @return a new instance.
- */
- public static PropertySourceBuilder from(String name){
- return new PropertySourceBuilder(name);
- }
-
- public PropertySourceBuilder add(String key, String value){
- this.properties.put(key, value);
- return this;
- }
-
- public PropertySourceBuilder addAll(Map<String,String> values){
- this.properties.putAll(values);
- return this;
- }
-
- public PropertySourceBuilder withOrdinal(int ordinal){
- this.ordinal = ordinal;
- return this;
- }
-
- public PropertySourceBuilder addValues(PropertySource propertySource){
- this.properties.putAll(propertySource.getProperties());
- return this;
- }
-
- public PropertySource build(){
- throw new UnsupportedOperationException("Not yet implemented.");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/391671af/sandbox/remote/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/remote/pom.xml b/sandbox/remote/pom.xml
index f4b7100..26c1bbd 100644
--- a/sandbox/remote/pom.xml
+++ b/sandbox/remote/pom.xml
@@ -51,5 +51,10 @@ under the License.
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <!-- dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency -->
</dependencies>
</project>
[08/15] incubator-tamaya git commit: Minor change on logging output.
Posted by an...@apache.org.
Minor change on logging output.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/88a862d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/88a862d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/88a862d0
Branch: refs/heads/master
Commit: 88a862d00bd4d26f1dd14814e1465d668424ae4a
Parents: 216af2a
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:33:11 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:33:11 2015 +0200
----------------------------------------------------------------------
.../BaseFormatPropertySourceProvider.java | 2 +-
.../tamaya/format/ConfigurationDataBuilder.java | 2 +-
.../environment/BuildableRuntimeContext.java | 30 ++++++++++++++--
.../tamaya/environment/RuntimeContext.java | 4 +--
.../environment/RuntimeContextBuilder.java | 33 ++++++++++++++---
.../environment/RuntimeContextProvider.java | 7 ++--
...DependentApplicationEnvironmentProvider.java | 11 +++---
...ssLoaderDependentEarEnvironmentProvider.java | 11 +++---
.../SystemClassLoaderEnvironmentProvider.java | 11 +++---
.../environment/spi/ContextDataProvider.java | 37 +++++++++++++++++++-
10 files changed, 114 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
index 3c2789d..55f8a8d 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
@@ -150,7 +150,7 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
propertySources.addAll(getPropertySources(data));
}
} catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to add resource based config: " + res, e);
+ LOG.log(Level.WARNING, "Failed to put resource based config: " + res, e);
}
});
return propertySources;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
index 58c1691..d0c3675 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
@@ -66,7 +66,7 @@ public final class ConfigurationDataBuilder {
/**
* Adds (empty) sections,if they are not yet existing. Already existing sections will not be touched.
- * @param sections the new sections to add.
+ * @param sections the new sections to put.
* @return the builder for chaining.
*/
public ConfigurationDataBuilder addSections(String... sections){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
index 009b5e2..94d0125 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment;
+package org.apache.tamaya.environment;
import java.util.Map;
import java.util.Objects;
@@ -26,6 +26,10 @@ import java.util.TreeMap;
* Environment class that is used by the {@link org.apache.tamaya.environment.RuntimeContextBuilder}.
*/
class BuildableRuntimeContext implements RuntimeContext {
+ /** The context id, never null or empty. */
+ private String contextId;
+ /** The parent context. */
+ private RuntimeContext parentContext;
/**
* The environment data.
@@ -37,8 +41,10 @@ class BuildableRuntimeContext implements RuntimeContext {
*
* @param builder the builder, not null.
*/
- BuildableRuntimeContext(EnvironmentBuilder builder) {
+ BuildableRuntimeContext(RuntimeContextBuilder builder) {
Objects.requireNonNull(builder);
+ this.contextId = builder.contextId;
+ this.parentContext = builder.parentContext;
context.putAll(builder.contextData);
}
@@ -48,6 +54,24 @@ class BuildableRuntimeContext implements RuntimeContext {
}
@Override
+ public String getContextId() {
+ return contextId;
+ }
+
+ @Override
+ public String getQualifiedContextId() {
+ if(parentContext!=null){
+ return parentContext.getQualifiedContextId()+"/"+contextId;
+ }
+ return contextId;
+ }
+
+ @Override
+ public RuntimeContext getParentContext() {
+ return parentContext;
+ }
+
+ @Override
public String get(String key) {
return context.get(key);
}
@@ -62,7 +86,7 @@ class BuildableRuntimeContext implements RuntimeContext {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- BuildableEnvironment that = (BuildableEnvironment) o;
+ BuildableRuntimeContext that = (BuildableRuntimeContext) o;
return context.equals(that.context);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
index 48b0691..b782667 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
@@ -16,9 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment;
-
-import org.apache.tamaya.spi.ServiceContext;
+package org.apache.tamaya.environment;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
index 1aba76a..e5ceb29 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment;
+package org.apache.tamaya.environment;
import java.util.HashMap;
import java.util.Map;
@@ -27,21 +27,46 @@ import java.util.Objects;
*/
public final class RuntimeContextBuilder {
+ /** The context id, never null or empty. */
+ String contextId;
+ /** The parent context. */
+ RuntimeContext parentContext;
+
/** THe environment data. */
Map<String,String> contextData = new HashMap<>();
/**
* Constructor.
*/
- private RuntimeContextBuilder() {
+ private RuntimeContextBuilder(String contextId, RuntimeContext parentContext) {
+ this.contextId = Objects.requireNonNull(contextId);
+ this.parentContext = parentContext;
+ }
+
+ /**
+ * Creates a new buildr instance.
+ * @return the new builder instance.
+ */
+ public static RuntimeContextBuilder of(String contextId) {
+ return new RuntimeContextBuilder(contextId, null);
}
/**
* Creates a new buildr instance.
* @return the new builder instance.
*/
- public static final RuntimeContextBuilder of() {
- return new RuntimeContextBuilder();
+ public static RuntimeContextBuilder of(String contextId, RuntimeContext parentContext) {
+ return new RuntimeContextBuilder(contextId, parentContext);
+ }
+
+ /**
+ * Sets a new parent context.
+ * @param parentContext the parent context (can be null).
+ * @return the builder for chaining
+ */
+ public RuntimeContextBuilder withParentContext(RuntimeContext parentContext){
+ this.parentContext = parentContext;
+ return this;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
index dcd6cf2..9b37467 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
@@ -18,19 +18,18 @@
*/
package org.apache.tamaya.environment;
+import org.apache.tamaya.environment.spi.ContextSpi;
import org.apache.tamaya.spi.ServiceContext;
-import java.util.Map;
-
/**
- * Singleton accessor to the current {@link org.apache.tamaya.metamodel.environment.RuntimeContext}.
+ * Singleton accessor to the current {@link org.apache.tamaya.environment.RuntimeContext}.
*/
public final class RuntimeContextProvider {
private static final ContextSpi contextSpi = loadSpi();
private static ContextSpi loadSpi(){
- return ServiceContext.getInstance().getSingleton(org.apache.tamaya.environment.spi.ContextSpi.class);
+ return ServiceContext.getInstance().getService(ContextSpi.class);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
index cc9034e..e130644 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
@@ -16,8 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.environment.internal;
+import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -60,7 +61,7 @@ public class ClassLoaderDependentApplicationEnvironmentProvider implements Conte
if(available!=null && !available){
return false;
}
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ List<URL> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
"classpath:META-INF/context/application.properties", "classpath:META-INF/context/application.xml", "classpath:META-INF/context/application.ini");
available = !propertyUris.isEmpty();
this.contextsAvailable.put(cl, available);
@@ -77,11 +78,11 @@ public class ClassLoaderDependentApplicationEnvironmentProvider implements Conte
if(data!=null){
return data;
}
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ List<URL> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
"classpath:META-INF/context/application.properties", "classpath:META-INF/context/application.xml", "classpath:META-INF/context/application.ini");
data = new HashMap<>();
- for(Resource resource:propertyUris){
+ for(URL resource:propertyUris){
try{
ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
data.putAll(format.readConfiguration(resource));
@@ -92,7 +93,7 @@ public class ClassLoaderDependentApplicationEnvironmentProvider implements Conte
}
data.put("classloader.type", cl.getClass().getName());
data.put("classloader.info", cl.toString());
- Set<Resource> uris = new HashSet<>();
+ Set<URL> uris = new HashSet<>();
uris.addAll(propertyUris);
data.put("context.sources", uris.toString());
data = Collections.unmodifiableMap(data);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
index 6b999cc..b4160e2 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.environment.internal;
import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
@@ -27,6 +27,7 @@ import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
+import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
@@ -60,7 +61,7 @@ public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentPr
if(available!=null && !available){
return false;
}
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ List<URL> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
"classpath:META-INF/context/ear.properties", "classpath:META-INF/context/ear.xml", "classpath:META-INF/context/ear.ini");
available = !propertyUris.isEmpty();
this.contextsAvailable.put(cl, available);
@@ -77,10 +78,10 @@ public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentPr
if(data!=null){
return data;
}
- List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ List<URL> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
"classpath:META-INF/context/ear.properties", "classpath:META-INF/context/ear.xml", "classpath:META-INF/context/ear.ini");
data = new HashMap<>();
- for(Resource resource:resources){
+ for(URL resource:resources){
try{
ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
Map<String,String> read = format.readConfiguration(resource);
@@ -97,7 +98,7 @@ public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentPr
}
data.put("classloader.type", cl.getClass().getName());
data.put("classloader.info", cl.toString());
- Set<Resource> resourceSet = new HashSet<>();
+ Set<URL> resourceSet = new HashSet<>();
resourceSet.addAll(resources);
data.put("context.sources", resourceSet.toString());
data = Collections.unmodifiableMap(data);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
index 12019a0..f692b95 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
@@ -27,6 +27,7 @@ import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
+import java.net.URL;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -43,9 +44,9 @@ public class SystemClassLoaderEnvironmentProvider implements ContextDataProvider
public SystemClassLoaderEnvironmentProvider(){
- List<Resource> propertyResources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(ClassLoader.getSystemClassLoader(),
+ List<URL> propertyResources = Resource.getResources(ClassLoader.getSystemClassLoader(),
"classpath:META-INF/env/system.properties", "classpath:META-INF/env/system.xml", "classpath:META-INF/env/system.ini");
- for(Resource resource:propertyResources){
+ for(URL resource:propertyResources){
try{
ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
Map<String,String> data = format.readConfiguration(resource);
@@ -57,15 +58,11 @@ public class SystemClassLoaderEnvironmentProvider implements ContextDataProvider
}
data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
data.put("classloader.info", ClassLoader.getSystemClassLoader().toString());
- Set<Resource> resourceSet = new HashSet<>();
+ Set<URL> resourceSet = new HashSet<>();
resourceSet.addAll(propertyResources);
data.put("environment.system.sources", resourceSet.toString());
this.data = Collections.unmodifiableMap(data);
}
- @Override
- public boolean isActive() {
- return true;
- }
@Override
public Map<String,String> getContextData() {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/88a862d0/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
index 0c6c138..99e2c03 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
@@ -1,7 +1,42 @@
+/*
+ * 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.environment.spi;
+
+import org.apache.tamaya.environment.RuntimeContext;
+
+
/**
- * Created by Anatole on 04.05.2015.
+ * SPI component for evaluating the current runtime context. All registered providers hereby are
+ * organized by default depending on their (optional) {@code @Priority} annotation's value. (the
+ * effective ordering depends on the current {@link org.apache.tamaya.spi.ServiceContext} implementation
+ * active).
*/
public interface ContextDataProvider {
+
+ /**
+ * If a data providers identifies a new runtime context level, it should build a new
+ * {@link org.apache.tamaya.environment.RuntimeContext} with all the related data to be added to this
+ * context, otherwise it should simply return null.
+ *
+ * @param currentContext the current context, or null for the root context.
+ * @return the new current context for the current runtime state, or null.
+ */
+ public RuntimeContext getContext(RuntimeContext currentContext);
}
[02/15] incubator-tamaya git commit: Fixed bugs in TypeLiteral with
code from OpenWebBeans. Unified test file location in RIs. Added tests for
uncoveraged areas.
Posted by an...@apache.org.
Fixed bugs in TypeLiteral with code from OpenWebBeans.
Unified test file location in RIs.
Added tests for uncoveraged areas.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/58bda32a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/58bda32a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/58bda32a
Branch: refs/heads/master
Commit: 58bda32ab247e71e8b3cd791486f06283d1cfb53
Parents: 0bf0eec
Author: anatole <an...@apache.org>
Authored: Fri May 15 14:09:23 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri May 15 14:09:23 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/TypeLiteral.java | 167 +++++++++-------
.../org/apache/tamaya/ConfigExceptionTest.java | 45 +++++
.../java/org/apache/tamaya/TypeLiteralTest.java | 61 ++++++
.../core/internal/PropertyConverterManager.java | 2 +-
.../propertysource/BasePropertySourceTest.java | 104 ++++++++++
.../EnvironmentPropertySourceTest.java | 41 ++++
.../PropertiesFilePropertySourceTest.java | 58 ++++++
.../SystemPropertySourceTest.java | 99 ++++++++++
.../provider/JavaConfigurationProviderTest.java | 60 ++++++
.../propertysource/BasePropertySourceTest.java | 104 ----------
.../PropertiesFilePropertySourceTest.java | 58 ------
.../SystemPropertySourceTest.java | 99 ----------
.../provider/JavaConfigurationProviderTest.java | 60 ------
.../java/org/apache/tamaya/TypeLiteral.java | 191 +++++++++++--------
.../java/org/apache/tamaya/TypeLiteralTest.java | 62 ++++++
.../core/internal/PropertyConverterManager.java | 2 +-
.../propertysource/BasePropertySourceTest.java | 104 ++++++++++
.../EnvironmentPropertySourceTest.java | 41 ++++
.../PropertiesFilePropertySourceTest.java | 64 +++++++
.../SystemPropertySourceTest.java | 101 ++++++++++
.../provider/JavaConfigurationProviderTest.java | 60 ++++++
.../propertysource/BasePropertySourceTest.java | 104 ----------
.../PropertiesFilePropertySourceTest.java | 64 -------
.../SystemPropertySourceTest.java | 101 ----------
.../provider/JavaConfigurationProviderTest.java | 60 ------
25 files changed, 1114 insertions(+), 798 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index a3abdf5..b29a699 100644
--- a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -38,29 +38,39 @@ import java.lang.reflect.Type;
public class TypeLiteral<T> implements Serializable {
private static final long serialVersionUID = 1L;
- private Type type;
+ private static final Type[] EMPTY_TYPE_ARRAY = new Type[0];
+ /** The current defined type. */
+ private Type definedType;
- protected TypeLiteral(Type type) {
- this.type = type;
+ /**
+ * Constructor.
+ * @param definedType the defined type.
+ */
+ protected TypeLiteral(Type definedType) {
+ this.definedType = definedType;
}
/**
* Constructor only for directly implemeting a TypeLiteral hereby dynamically implementing a generic interface.
*/
- protected TypeLiteral() { }
+ protected TypeLiteral() {
+ this.definedType = getDefinedType(this.getClass());
+ }
/**
* Creates a new TypeLiteral based on a given type.
+ *
* @param type the type , not null.
- * @param <R> the literal generic type.
+ * @param <R> the literal generic type.
* @return the corresponding TypeLiteral, never null.
*/
- public static <R> TypeLiteral<R> of(Type type){
+ public static <R> TypeLiteral<R> of(Type type) {
return new TypeLiteral<>(type);
}
/**
* Evaluates the subclass of a TypeLiteral instance.
+ *
* @param clazz the typeliteral class (could be an anonymous class).
* @return the subclass implemented by the TypeLiteral.
*/
@@ -77,107 +87,130 @@ public class TypeLiteral<T> implements Serializable {
/**
* Checks the current implemented generic interfaces and evaluates the given single type parameter.
- * @param clazz the class to check, not null.
+ *
+ * @param clazz the class to check, not null.
* @param interfaceType the interface type to be checked, not null.
* @return the generic type parameter, or null, if it cannot be evaluated.
*/
- public static Type getGenericInterfaceTypeParameter(Class<?> clazz, Class<?> interfaceType) {
- for(Type type: clazz.getGenericInterfaces()){
- if(interfaceType!=null && !interfaceType.equals(type)){
- continue;
- }
+ public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) {
+ for (Type type : clazz.getGenericInterfaces()) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
- if (parameterizedType.getActualTypeArguments().length == 1) {
- return parameterizedType.getActualTypeArguments()[0];
+ if(parameterizedType.getRawType().equals(interfaceType)){
+ return parameterizedType.getActualTypeArguments();
}
}
}
- return null;
+ return EMPTY_TYPE_ARRAY;
}
/**
* Method that checks the class's type for a generic interface implementation type.
- * @param clazz the type class, not null.
- * @param interfaceType the generic interface to check (there could be multiple ones implemented by a class).
+ *
+ * @param type the type, not null.
* @return the generic type parameter of the given single type generic interfaceType, or null.
*/
- public static Type getTypeParameter(Class<?> clazz, Class<?> interfaceType) {
- Type[] types = clazz.getGenericInterfaces();
- for(Type type:types) {
- if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType) type;
- if(interfaceType==null || parameterizedType.getRawType().equals(interfaceType)){
- if (parameterizedType.getActualTypeArguments().length == 1) {
- return parameterizedType.getActualTypeArguments()[0];
- }
- }
- }
+ public static Type[] getTypeParameters(Type type) {
+ if (type instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ return parameterizedType.getActualTypeArguments();
}
- return null;
+ return EMPTY_TYPE_ARRAY;
}
- /**
- * Returns basic Java type.
- * @return the actual type represented by this object
- */
public final Type getType() {
- if (type == null) {
- Class<?> typeLiteralSubclass = getTypeLiteralSubclass(this.getClass());
- if (typeLiteralSubclass == null) {
- throw new RuntimeException(getClass() + " is not a subclass of TypeLiteral");
- }
- type = getTypeParameter(typeLiteralSubclass, null);
- if (type == null) {
- throw new RuntimeException(getClass() + " does not specify the type parameter T of TypeLiteral<T>");
- }
- }
- return type;
+ return definedType;
}
/**
- * Get the raw type of the current type.
- * @return the raw type represented by this object
- */
- @SuppressWarnings("unchecked")
+ * Returns basic raw Java type.
+ *
+ * @return the actual type represented by this object
+ */
public final Class<T> getRawType() {
- Type type = getType();
- if (type instanceof Class) {
- return (Class<T>) type;
- } else if (type instanceof ParameterizedType) {
- return (Class<T>) ((ParameterizedType) type).getRawType();
- } else if (type instanceof GenericArrayType) {
- return (Class<T>) Object[].class;
+ Class<T> rawType = null;
+
+ if (this.definedType instanceof Class) {
+ rawType = (Class<T>) this.definedType;
+ } else if (this.definedType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) this.definedType;
+ rawType = (Class<T>) pt.getRawType();
+
+ } else if (this.definedType instanceof GenericArrayType) {
+ rawType = (Class<T>) Object[].class;
+ } else {
+ throw new RuntimeException("Illegal type for the Type Literal Class");
+ }
+
+ return rawType;
+ }
+
+
+ protected Type getDefinedType(Class<?> clazz) {
+ Type type = null;
+
+ if (clazz == null) {
+ throw new RuntimeException("Class parameter clazz can not be null");
+ }
+
+ Type superClazz = clazz.getGenericSuperclass();
+
+ if (superClazz.equals(Object.class)) {
+ throw new RuntimeException("Super class must be parametrized type");
+ } else if (superClazz instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) superClazz;
+ Type[] actualArgs = pt.getActualTypeArguments();
+
+ if (actualArgs.length == 1) {
+ type = actualArgs[0];
+
+ } else {
+ throw new RuntimeException("More than one parametric type");
+ }
+
} else {
- throw new RuntimeException("Illegal type");
+ type = getDefinedType((Class<?>) superClazz);
}
+
+ return type;
}
+
@Override
- public boolean equals(Object o) {
- if (this == o){
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((definedType == null) ? 0 : definedType.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
}
- if (!(o instanceof TypeLiteral)){
+ if (obj == null) {
return false;
}
- TypeLiteral that = (TypeLiteral) o;
- if (type != null ? !type.equals(that.type) : that.type != null){
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TypeLiteral other = (TypeLiteral) obj;
+ if (definedType == null) {
+ if (other.definedType != null) {
+ return false;
+ }
+ } else if (!definedType.equals(other.definedType)) {
return false;
}
return true;
}
- @Override
- public int hashCode() {
- int result = type != null ? type.hashCode() : 0;
- return result;
- }
@Override
public String toString() {
return "TypeLiteral{" +
- "type=" + type +
+ "type=" + definedType +
'}';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java b/java7/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
new file mode 100644
index 0000000..fa7da0a
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests instantiating {@link ConfigException}.
+ */
+public class ConfigExceptionTest {
+
+ @Test
+ public void testCreationMessage(){
+ ConfigException ex = new ConfigException("test");
+ assertNull(ex.getCause());
+ assertEquals(ex.getMessage(), "test");
+ }
+
+ @Test
+ public void testCreationMessageThrowable(){
+ Exception e = new IllegalStateException("blabla");
+ ConfigException ex = new ConfigException("test", e);
+ assertTrue(ex.getCause() == e);
+ assertEquals("test", ex.getMessage());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java b/java7/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
new file mode 100644
index 0000000..51edae9
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for the {@link TypeLiteral} class.
+ */
+public class TypeLiteralTest {
+
+ @Test
+ public void test_constrcutor(){
+ TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
+ assertEquals(List.class, listTypeLiteral.getRawType());
+ assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
+ }
+
+ @Test
+ public void test_of(){
+ class MyListClass extends ArrayList<String>{};
+ TypeLiteral<MyListClass> listTypeLiteral = TypeLiteral.of(MyListClass.class);
+ assertEquals(MyListClass.class, listTypeLiteral.getRawType());
+ assertEquals(MyListClass.class, listTypeLiteral.getType());
+ }
+
+ @Test
+ public void test_getTypeParameter(){
+ TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
+ assertEquals(List.class, listTypeLiteral.getRawType());
+ assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
+ }
+
+ @Test
+ public void test_getGenericInterfaceTypeParameter(){
+ class MyListClass extends ArrayList<String> implements List<String>{};
+ assertEquals(String.class, TypeLiteral.getGenericInterfaceTypeParameters(MyListClass.class, List.class)[0]);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index 7da86f9..31a05b2 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -69,7 +69,7 @@ public class PropertyConverterManager {
*/
protected void initConverters() {
for(PropertyConverter conv: ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)){
- Type type = TypeLiteral.getTypeParameter(conv.getClass(), PropertyConverter.class);
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
register(TypeLiteral.of(type), conv);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..8d3f086
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource(56) {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(56, defaultPropertySource.getOrdinal());
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
+
+ // propertySource with invalid ordinal
+ Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ super(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "1000");
+ return map;
+ }
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ super(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
+ return map;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..995c7ad
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -0,0 +1,41 @@
+package org.apache.tamaya.core.propertysource;
+
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class EnvironmentPropertySourceTest {
+
+ private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ assertEquals("environment-properties", envPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
+ assertEquals(envPropertySource.get(envEntry.getKey()), envEntry.getValue());
+ }
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Map<String, String> props = envPropertySource.getProperties();
+ assertEquals(System.getenv(), props);
+ }
+
+ @Test
+ public void testIsScannable() throws Exception {
+ assertTrue(envPropertySource.isScannable());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..36b0f5d
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.core.propertysource.SimplePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PropertiesFilePropertySourceTest {
+
+ private SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
+ .getContextClassLoader().getResource("testfile.properties"));
+ private SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
+ Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(0, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Assert.assertEquals(5, testfilePropertySource.getProperties().size());
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..c627972
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1000
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
+ Assert.assertEquals(1000, new SystemPropertySource().getOrdinal());
+ // currently its not possible to change ordinal at runtime
+
+ // reset it to not destroy other tests!!
+ System.clearProperty(PropertySource.TAMAYA_ORDINAL);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ Assert.assertEquals("system-properties", testPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ String property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
+ SystemPropertySource.class.getSimpleName(), property);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // cleanup
+ System.clearProperty("test");
+
+ // no modifaction
+ try {
+ testPropertySource.getProperties().put("add.new.keys", "must throw exception");
+ Assert.fail(UnsupportedOperationException.class.getName() + " expected");
+ }
+ catch (UnsupportedOperationException e) {
+ // expected -> all is fine
+ }
+ }
+
+ private void checkWithSystemProperties(Map<String, String> toCheck) {
+ Properties systemEntries = System.getProperties();
+
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.entrySet().size(), toCheck.size());
+
+ for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..f099da4
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.provider;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.provider.JavaConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+
+public class JavaConfigurationProviderTest {
+
+ @Test
+ public void testJavaConfigurationProvider() {
+
+ Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+ assertThat(propertySources, notNullValue());
+ assertThat(propertySources, hasSize(1));
+
+ PropertySource propertySource = propertySources.iterator().next();
+
+ assertThat(propertySource.getProperties().keySet(), hasSize(5));
+
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ Assert.assertEquals(value, propertySource.get(key));
+
+ // check if we had our key in configuration.current
+ Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
+ Assert.assertEquals(value, ConfigurationProvider.getConfiguration().get(key));
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
deleted file mode 100644
index a8325c6..0000000
--- a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class BasePropertySourceTest {
-
- @Test
- public void testGetOrdinal() {
-
- PropertySource defaultPropertySource = new BasePropertySource(56) {
-
- @Override
- public String getName() {
- return "testWithDefault";
- }
-
- @Override
- public String get(String key) {
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.emptyMap();
- }
- };
-
- Assert.assertEquals(56, defaultPropertySource.getOrdinal());
- Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
-
- // propertySource with invalid ordinal
- Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
- }
-
- @Test
- public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
- }
-
- private static class OverriddenOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenOrdinalPropertySource() {
- super(250);
- }
-
- @Override
- public String getName() {
- return "overriddenOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "1000");
- return map;
- }
- }
-
- private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenInvalidOrdinalPropertySource() {
- super(1);
- }
-
- @Override
- public String getName() {
- return "overriddenInvalidOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
- return map;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
deleted file mode 100644
index 8527881..0000000
--- a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PropertiesFilePropertySourceTest {
-
- private SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
- .getContextClassLoader().getResource("testfile.properties"));
- private SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
- Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
-
-
- @Test
- public void testGetOrdinal() {
- Assert.assertEquals(0, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
- }
-
-
- @Test
- public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3"));
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
- Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
- }
-
-
- @Test
- public void testGetProperties() throws Exception {
- Assert.assertEquals(5, testfilePropertySource.getProperties().size());
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
deleted file mode 100644
index 0b26ff4..0000000
--- a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.Properties;
-
-public class SystemPropertySourceTest {
-
- private SystemPropertySource testPropertySource = new SystemPropertySource();
-
-
- @Test
- public void testGetOrdinal() throws Exception {
-
- // test the default ordinal
- Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
-
- // set the ordinal to 1000
- System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
- Assert.assertEquals(1000, new SystemPropertySource().getOrdinal());
- // currently its not possible to change ordinal at runtime
-
- // reset it to not destroy other tests!!
- System.clearProperty(PropertySource.TAMAYA_ORDINAL);
- }
-
- @Test
- public void testGetName() throws Exception {
- Assert.assertEquals("system-properties", testPropertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
-
- String property = testPropertySource.get(propertyKeyToCheck);
- Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
- SystemPropertySource.class.getSimpleName(), property);
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
- }
-
- @Test
- public void testGetProperties() throws Exception {
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // modify system properties
- System.setProperty("test", "myTestVal");
-
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // cleanup
- System.clearProperty("test");
-
- // no modifaction
- try {
- testPropertySource.getProperties().put("add.new.keys", "must throw exception");
- Assert.fail(UnsupportedOperationException.class.getName() + " expected");
- }
- catch (UnsupportedOperationException e) {
- // expected -> all is fine
- }
- }
-
- private void checkWithSystemProperties(Map<String, String> toCheck) {
- Properties systemEntries = System.getProperties();
-
- Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
- systemEntries.entrySet().size(), toCheck.size());
-
- for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
-
- Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
- systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
deleted file mode 100644
index 6e558d7..0000000
--- a/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.test.provider;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.core.provider.JavaConfigurationProvider;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collection;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-
-public class JavaConfigurationProviderTest {
-
- @Test
- public void testJavaConfigurationProvider() {
-
- Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
-
- assertThat(propertySources, notNullValue());
- assertThat(propertySources, hasSize(1));
-
- PropertySource propertySource = propertySources.iterator().next();
-
- assertThat(propertySource.getProperties().keySet(), hasSize(5));
-
- for (int i = 1; i < 6; i++) {
- String key = "confkey" + i;
- String value = "javaconf-value" + i;
-
- Assert.assertEquals(value, propertySource.get(key));
-
- // check if we had our key in configuration.current
- Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
- Assert.assertEquals(value, ConfigurationProvider.getConfiguration().get(key));
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index c77cadb..b29a699 100644
--- a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -23,44 +23,54 @@ import java.lang.reflect.Type;
/**
-* <p>Class for instantiation of objects that represent parameterized types
-* with current parameters.</p>
-* <p>
-* <p>An object that represents a parameterized type may be obtained by
-* subclassing <tt>TypeLiteral</tt>.</p>
-* <p>
-* <pre>
-* TypeLiteral<List<Integer>> stringListType = new TypeLiteral<List<Integer>>() {};
-* </pre>
-*
-* @param <T> the type, including all type parameters
-*/
+ * <p>Class for instantiation of objects that represent parameterized types
+ * with current parameters.</p>
+ * <p>
+ * <p>An object that represents a parameterized type may be obtained by
+ * subclassing <tt>TypeLiteral</tt>.</p>
+ * <p>
+ * <pre>
+ * TypeLiteral<List<Integer>> stringListType = new TypeLiteral<List<Integer>>() {};
+ * </pre>
+ *
+ * @param <T> the type, including all type parameters
+ */
public class TypeLiteral<T> implements Serializable {
private static final long serialVersionUID = 1L;
- private Type type;
+ private static final Type[] EMPTY_TYPE_ARRAY = new Type[0];
+ /** The current defined type. */
+ private Type definedType;
- protected TypeLiteral(Type type) {
- this.type = type;
+ /**
+ * Constructor.
+ * @param definedType the defined type.
+ */
+ protected TypeLiteral(Type definedType) {
+ this.definedType = definedType;
}
/**
* Constructor only for directly implemeting a TypeLiteral hereby dynamically implementing a generic interface.
*/
- protected TypeLiteral() { }
+ protected TypeLiteral() {
+ this.definedType = getDefinedType(this.getClass());
+ }
/**
* Creates a new TypeLiteral based on a given type.
+ *
* @param type the type , not null.
- * @param <R> the literal generic type.
+ * @param <R> the literal generic type.
* @return the corresponding TypeLiteral, never null.
*/
- public static <R> TypeLiteral<R> of(Type type){
+ public static <R> TypeLiteral<R> of(Type type) {
return new TypeLiteral<>(type);
}
/**
* Evaluates the subclass of a TypeLiteral instance.
+ *
* @param clazz the typeliteral class (could be an anonymous class).
* @return the subclass implemented by the TypeLiteral.
*/
@@ -77,107 +87,130 @@ public class TypeLiteral<T> implements Serializable {
/**
* Checks the current implemented generic interfaces and evaluates the given single type parameter.
- * @param clazz the class to check, not null.
+ *
+ * @param clazz the class to check, not null.
* @param interfaceType the interface type to be checked, not null.
* @return the generic type parameter, or null, if it cannot be evaluated.
*/
- public static Type getGenericInterfaceTypeParameter(Class<?> clazz, Class<?> interfaceType) {
- for(Type type: clazz.getGenericInterfaces()){
- if(interfaceType!=null && !interfaceType.equals(type)){
- continue;
- }
+ public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) {
+ for (Type type : clazz.getGenericInterfaces()) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
- if (parameterizedType.getActualTypeArguments().length == 1) {
- return parameterizedType.getActualTypeArguments()[0];
+ if(parameterizedType.getRawType().equals(interfaceType)){
+ return parameterizedType.getActualTypeArguments();
}
}
}
- return null;
+ return EMPTY_TYPE_ARRAY;
}
/**
* Method that checks the class's type for a generic interface implementation type.
- * @param clazz the type class, not null.
- * @param interfaceType the generic interface to check (there could be multiple ones implemented by a class).
+ *
+ * @param type the type, not null.
* @return the generic type parameter of the given single type generic interfaceType, or null.
*/
- public static Type getTypeParameter(Class<?> clazz, Class<?> interfaceType) {
- Type[] types = clazz.getGenericInterfaces();
- for(Type type:types) {
- if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType) type;
- if(interfaceType==null || parameterizedType.getRawType().equals(interfaceType)){
- if (parameterizedType.getActualTypeArguments().length == 1) {
- return parameterizedType.getActualTypeArguments()[0];
- }
- }
- }
+ public static Type[] getTypeParameters(Type type) {
+ if (type instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ return parameterizedType.getActualTypeArguments();
}
- return null;
+ return EMPTY_TYPE_ARRAY;
}
- /**
- * Returns basic Java type.
- * @return the actual type represented by this object
- */
public final Type getType() {
- if (type == null) {
- Class<?> typeLiteralSubclass = getTypeLiteralSubclass(this.getClass());
- if (typeLiteralSubclass == null) {
- throw new RuntimeException(getClass() + " is not a subclass of TypeLiteral");
- }
- type = getTypeParameter(typeLiteralSubclass, null);
- if (type == null) {
- throw new RuntimeException(getClass() + " does not specify the type parameter T of TypeLiteral<T>");
- }
- }
- return type;
+ return definedType;
}
/**
- * Get the raw type of the current type.
- * @return the raw type represented by this object
- */
- @SuppressWarnings("unchecked")
+ * Returns basic raw Java type.
+ *
+ * @return the actual type represented by this object
+ */
public final Class<T> getRawType() {
- Type type = getType();
- if (type instanceof Class) {
- return (Class<T>) type;
- } else if (type instanceof ParameterizedType) {
- return (Class<T>) ((ParameterizedType) type).getRawType();
- } else if (type instanceof GenericArrayType) {
- return (Class<T>) Object[].class;
+ Class<T> rawType = null;
+
+ if (this.definedType instanceof Class) {
+ rawType = (Class<T>) this.definedType;
+ } else if (this.definedType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) this.definedType;
+ rawType = (Class<T>) pt.getRawType();
+
+ } else if (this.definedType instanceof GenericArrayType) {
+ rawType = (Class<T>) Object[].class;
+ } else {
+ throw new RuntimeException("Illegal type for the Type Literal Class");
+ }
+
+ return rawType;
+ }
+
+
+ protected Type getDefinedType(Class<?> clazz) {
+ Type type = null;
+
+ if (clazz == null) {
+ throw new RuntimeException("Class parameter clazz can not be null");
+ }
+
+ Type superClazz = clazz.getGenericSuperclass();
+
+ if (superClazz.equals(Object.class)) {
+ throw new RuntimeException("Super class must be parametrized type");
+ } else if (superClazz instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) superClazz;
+ Type[] actualArgs = pt.getActualTypeArguments();
+
+ if (actualArgs.length == 1) {
+ type = actualArgs[0];
+
+ } else {
+ throw new RuntimeException("More than one parametric type");
+ }
+
} else {
- throw new RuntimeException("Illegal type");
+ type = getDefinedType((Class<?>) superClazz);
}
+
+ return type;
+ }
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((definedType == null) ? 0 : definedType.hashCode());
+ return result;
}
@Override
- public boolean equals(Object o) {
- if (this == o){
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
}
- if (!(o instanceof TypeLiteral)){
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
return false;
}
- TypeLiteral that = (TypeLiteral) o;
- if (type != null ? !type.equals(that.type) : that.type != null){
+ TypeLiteral other = (TypeLiteral) obj;
+ if (definedType == null) {
+ if (other.definedType != null) {
+ return false;
+ }
+ } else if (!definedType.equals(other.definedType)) {
return false;
}
return true;
}
- @Override
- public int hashCode() {
- int result = type != null ? type.hashCode() : 0;
- return result;
- }
@Override
public String toString() {
return "TypeLiteral{" +
- "type=" + type +
+ "type=" + definedType +
'}';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java b/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
new file mode 100644
index 0000000..783d6bf
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for the {@link org.apache.tamaya.TypeLiteral} class.
+ */
+public class TypeLiteralTest {
+
+ @Test
+ public void test_constrcutor(){
+ TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
+ assertEquals(List.class, listTypeLiteral.getRawType());
+ assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
+ }
+
+ @Test
+ public void test_of(){
+ class MyListClass extends ArrayList<String>{};
+ TypeLiteral<MyListClass> listTypeLiteral = TypeLiteral.of(MyListClass.class);
+ assertEquals(MyListClass.class, listTypeLiteral.getRawType());
+ assertEquals(MyListClass.class, listTypeLiteral.getType());
+ }
+
+ @Test
+ public void test_getTypeParameter(){
+ TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
+ assertEquals(List.class, listTypeLiteral.getRawType());
+ assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
+ }
+
+ @Test
+ public void test_getGenericInterfaceTypeParameter(){
+ class MyListClass extends ArrayList<String> implements List<String>{};
+ assertEquals(String.class, TypeLiteral.getGenericInterfaceTypeParameters(MyListClass.class, List.class)[0]);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index b4d1e75..333572e 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -68,7 +68,7 @@ public class PropertyConverterManager {
*/
protected void initConverters() {
for(PropertyConverter conv: ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)){
- Type type = TypeLiteral.getTypeParameter(conv.getClass(), PropertyConverter.class);
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
register(TypeLiteral.of(type), conv);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..8d3f086
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource(56) {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(56, defaultPropertySource.getOrdinal());
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
+
+ // propertySource with invalid ordinal
+ Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ super(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "1000");
+ return map;
+ }
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ super(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
+ return map;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..995c7ad
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -0,0 +1,41 @@
+package org.apache.tamaya.core.propertysource;
+
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class EnvironmentPropertySourceTest {
+
+ private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ assertEquals("environment-properties", envPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
+ assertEquals(envPropertySource.get(envEntry.getKey()), envEntry.getValue());
+ }
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Map<String, String> props = envPropertySource.getProperties();
+ assertEquals(System.getenv(), props);
+ }
+
+ @Test
+ public void testIsScannable() throws Exception {
+ assertTrue(envPropertySource.isScannable());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..d4ef659
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.core.propertysource.SimplePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PropertiesFilePropertySourceTest {
+
+ private SimplePropertySource testfilePropertySource;
+ private SimplePropertySource overrideOrdinalPropertySource;
+
+
+ @Before
+ public void initTest() {
+ testfilePropertySource = new SimplePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+ overrideOrdinalPropertySource = new SimplePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+ }
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(0, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Assert.assertEquals(5, testfilePropertySource.getProperties().size());
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..14b136b
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1000
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
+ Assert.assertEquals(1000, new SystemPropertySource().getOrdinal());
+ // currently its not possible to change ordinal at runtime
+
+ // reset it to not destroy other tests!!
+ System.clearProperty(PropertySource.TAMAYA_ORDINAL);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ Assert.assertEquals("system-properties", new SystemPropertySource().getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ String property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
+ property != null);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
+
+
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // cleanup
+ System.clearProperty("test");
+
+ // no modifaction
+ try {
+ testPropertySource.getProperties().put("add.new.keys", "must throw exception");
+ Assert.fail(UnsupportedOperationException.class.getName() + " expected");
+ }
+ catch (UnsupportedOperationException e) {
+ // expected -> all is fine
+ }
+ }
+
+ private void checkWithSystemProperties(Map<String, String> toCheck) {
+ Properties systemEntries = System.getProperties();
+
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.entrySet().size(), toCheck.size());
+
+ for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..6d16707
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.provider;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.provider.JavaConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+
+public class JavaConfigurationProviderTest {
+
+ @Test
+ public void testJavaConfigurationProvider() {
+
+ Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+ assertThat(propertySources, notNullValue());
+ assertThat(propertySources, hasSize(1));
+
+ PropertySource propertySource = propertySources.iterator().next();
+
+ assertThat(propertySource.getProperties().keySet(), hasSize(5));
+
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ Assert.assertEquals(value, propertySource.get(key));
+
+ // check if we had our key in configuration.current
+ Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
+ Assert.assertEquals(value, ConfigurationProvider.getConfiguration().getOptional(key).get());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
deleted file mode 100644
index a8325c6..0000000
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class BasePropertySourceTest {
-
- @Test
- public void testGetOrdinal() {
-
- PropertySource defaultPropertySource = new BasePropertySource(56) {
-
- @Override
- public String getName() {
- return "testWithDefault";
- }
-
- @Override
- public String get(String key) {
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.emptyMap();
- }
- };
-
- Assert.assertEquals(56, defaultPropertySource.getOrdinal());
- Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
-
- // propertySource with invalid ordinal
- Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
- }
-
- @Test
- public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
- }
-
- private static class OverriddenOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenOrdinalPropertySource() {
- super(250);
- }
-
- @Override
- public String getName() {
- return "overriddenOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "1000");
- return map;
- }
- }
-
- private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenInvalidOrdinalPropertySource() {
- super(1);
- }
-
- @Override
- public String getName() {
- return "overriddenInvalidOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
- return map;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/58bda32a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
deleted file mode 100644
index 9fef3be..0000000
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class PropertiesFilePropertySourceTest {
-
- private SimplePropertySource testfilePropertySource;
- private SimplePropertySource overrideOrdinalPropertySource;
-
-
- @Before
- public void initTest() {
- testfilePropertySource = new SimplePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
- overrideOrdinalPropertySource = new SimplePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
- }
-
-
- @Test
- public void testGetOrdinal() {
- Assert.assertEquals(0, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
- }
-
-
- @Test
- public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3"));
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
- Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
- }
-
-
- @Test
- public void testGetProperties() throws Exception {
- Assert.assertEquals(5, testfilePropertySource.getProperties().size());
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
- }
-}
[05/15] incubator-tamaya git commit: TAMAYA-79: added non local tests
for events. Added additional testing for module and related fixes.
Posted by an...@apache.org.
TAMAYA-79: added non local tests for events.
Added additional testing for module and related fixes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3013dbd5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3013dbd5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3013dbd5
Branch: refs/heads/master
Commit: 3013dbd5b5c3a15bbd3a4b1c48abb92f71e49c72
Parents: 4048625
Author: anatole <an...@apache.org>
Authored: Wed May 20 17:49:03 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Wed May 20 17:49:03 2015 +0200
----------------------------------------------------------------------
.../examples/fileobserver/TestConfigView.java | 90 ---------
modules/events/pom.xml | 6 +
.../tamaya/events/FrozenPropertySource.java | 3 +-
.../events/delta/ConfigurationChange.java | 3 +-
.../delta/PropertySourceChangeBuilder.java | 4 +-
.../tamaya/events/ConfigEventSupportTest.java | 63 ++++++
.../tamaya/events/FrozenPropertySourceTest.java | 94 +++++++++
.../tamaya/events/ObservedConfigTest.java | 138 ++++++++++----
.../apache/tamaya/events/TestConfigView.java | 90 +++++++++
.../tamaya/events/TestObservingProvider.java | 4 +-
.../delta/ConfigurationContextChangeTest.java | 133 +++++++++++++
.../events/delta/PropertySourceChangeTest.java | 191 +++++++++++++++++++
.../internal/DefaultEventSupportSpiTest.java | 65 +++++++
.../events/src/test/resources/test.properties | 21 ++
14 files changed, 770 insertions(+), 135 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestConfigView.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestConfigView.java b/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestConfigView.java
deleted file mode 100644
index 386ca8d..0000000
--- a/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestConfigView.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.examples.fileobserver;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-/**
- * Created by Anatole on 24.03.2015.
- */
-public class TestConfigView implements ConfigOperator{
-
- private static final TestConfigView INSTANCE = new TestConfigView();
-
- private TestConfigView(){}
-
- public static ConfigOperator of(){
- return INSTANCE;
- }
-
- @Override
- public Configuration operate(Configuration config) {
- return new Configuration() {
- @Override
- public Map<String, String> getProperties() {
- return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
- Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
- }
- /**
- * Accesses the current String value for the given key and tries to convert it
- * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
- * {@link org.apache.tamaya.spi.ConfigurationContext}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @param type The target type required, not null.
- * @param <T> the value type
- * @return the converted value, never null.
- */
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- String value = get(key);
- if (value != null) {
- List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext()
- .getPropertyConverters(type);
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value);
- if (t != null) {
- return t;
- }
- } catch (Exception e) {
- Logger.getLogger(getClass().getName())
- .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: "
- + value, e);
- }
- }
- throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key);
- }
- return null;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index 8c157fa..e23dd1d 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -52,6 +52,12 @@ under the License.
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
index 0b9dc69..2c6eddb 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
@@ -112,8 +112,9 @@ public final class FrozenPropertySource implements PropertySource, Serializable
@Override
public String toString() {
return "FrozenPropertySource{" +
- "properties=" + properties +
+ "name=" + name +
", ordinal=" + ordinal +
+ ", properties=" + properties +
'}';
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
index fcc10d5..dffb835 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
@@ -118,7 +118,8 @@ public final class ConfigurationChange implements Serializable{
* @return the number current added entries.
*/
public int getAddedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
+ return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null &&
+ e.getNewValue() != null).count();
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
index 3aa0c18..b03e570 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
@@ -103,9 +103,9 @@ public final class PropertySourceChangeBuilder {
for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
String val = map1.get(en.getKey());
if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null));
} else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val));
}
}
return changes;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventSupportTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventSupportTest.java b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventSupportTest.java
new file mode 100644
index 0000000..f56659e
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventSupportTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.events;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link org.apache.tamaya.events.ConfigEventSupport}.
+ */
+public class ConfigEventSupportTest {
+
+ private String testAddListenerValue;
+
+ @Test
+ public void testAddRemoveListener() throws Exception {
+ Listener<String> testListener = new Listener<String>() {
+ @Override
+ public void onEvent(String event) {
+ testAddListenerValue = event;
+ }
+ };
+ ConfigEventSupport.addListener(testListener);
+ ConfigEventSupport.fireEvent("Event1", String.class);
+ assertEquals(testAddListenerValue, "Event1");
+ ConfigEventSupport.removeListener(testListener);
+ ConfigEventSupport.fireEvent("Event2", String.class);
+ assertEquals(testAddListenerValue, "Event1");
+ }
+
+ @Test
+ public void testFireEvent() throws Exception {
+ Listener<String> testListener = new Listener<String>() {
+ @Override
+ public void onEvent(String event) {
+ testAddListenerValue = event;
+ }
+ };
+ ConfigEventSupport.addListener(testListener);
+ ConfigEventSupport.fireEvent("Event1");
+ assertEquals(testAddListenerValue, "Event1");
+ ConfigEventSupport.removeListener(testListener);
+ ConfigEventSupport.fireEvent("Event2");
+ assertEquals(testAddListenerValue, "Event1");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
new file mode 100644
index 0000000..40d3335
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link org.apache.tamaya.events.FrozenPropertySource}.
+ */
+public class FrozenPropertySourceTest {
+
+ private static final PropertySource myPS = new SystemPropertySource();
+
+ @Test
+ public void testOf() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ assertNotNull(ps);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ String name = ps.getName();
+ assertNotNull(name);
+ assertEquals(name, ps.getName());
+ }
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ assertEquals(myPS.getOrdinal(), ps.getOrdinal());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ assertNotNull(ps);
+ myPS.getProperties().entrySet().forEach(
+ e -> assertEquals(ps.get(e.getKey()), e.getValue())
+ );
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ assertNotNull(ps);
+ assertNotNull(ps.getProperties());
+ assertFalse(ps.getProperties().isEmpty());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ PropertySource ps1 = FrozenPropertySource.of(myPS);
+ PropertySource ps2 = FrozenPropertySource.of(myPS);
+ assertEquals(ps1.getName(), ps2.getName());
+ assertEquals(ps1.getProperties(), ps2.getProperties());
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ PropertySource ps1 = FrozenPropertySource.of(myPS);
+ PropertySource ps2 = FrozenPropertySource.of(myPS);
+ assertEquals(ps1.hashCode(), ps2.hashCode());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ PropertySource ps = FrozenPropertySource.of(myPS);
+ String toString = ps.toString();
+ assertNotNull(toString);
+ assertTrue(toString.contains("FrozenPropertySource"));
+ assertTrue(toString.contains(myPS.getName()));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java b/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
index 8e9296a..bc3d087 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ObservedConfigTest.java
@@ -18,27 +18,124 @@
*/
package org.apache.tamaya.events;
+import org.apache.commons.io.FileUtils;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.Test;
import java.io.File;
+import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
/**
* Test (currently manual) to test configuration changes.
*/
public class ObservedConfigTest {
+ private static Path getSourceFile(String name) throws Exception {
+ URL url = ObservedConfigTest.class.getResource("/data");
+ File testFile = new File(new File(url.toURI()), name);
+ return Paths.get(testFile.toURI());
+ }
+
+ private static Path getTargetFile(String name) {
+ File testFile = new File(TestObservingProvider.getTestDirectory(), name);
+ return Paths.get(testFile.toURI());
+ }
+
+ /**
+ * Test method that periodically prints out what is happening.
+ */
+ public static void main() {
+ while (true) {
+ System.out.println("1: " + ConfigurationProvider.getConfiguration().get("1"));
+ System.out.println("2: " + ConfigurationProvider.getConfiguration().get("2"));
+ System.out.println("3: " + ConfigurationProvider.getConfiguration().get("3"));
+ System.out.println("4: " + ConfigurationProvider.getConfiguration().get("4"));
+ System.out.println("5: " + ConfigurationProvider.getConfiguration().get("5"));
+ System.out.println("6: " + ConfigurationProvider.getConfiguration().get("6"));
+ System.out.println("=======================================================================");
+ try {
+ Thread.sleep(2000L);
+ } catch (Exception e) {
+ // stop here...
+ }
+ }
+ }
+
+ @AfterClass
+ public static void cleanup() throws Exception {
+ // cleanup directory
+ Files.deleteIfExists(getTargetFile("test1.properties"));
+ Files.deleteIfExists(getTargetFile("test2.properties"));
+ Files.deleteIfExists(getTargetFile("test3.properties"));
+ }
+
+ @Before
+ public void setup() throws IOException {
+ // create some temporary config
+ Path tempDir = Files.createTempDirectory("observedFolder");
+
+ TestObservingProvider.propertyLocation = tempDir;
+
+ FileUtils.copyInputStreamToFile(
+ getClass().getResourceAsStream("/test.properties"),
+ new File(tempDir.toFile(), "test.properties"));
+ }
+
+ public void testInitialConfig() throws IOException {
+ Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ Map<String, String> props = config.getProperties();
+
+ assertEquals(props.get("test"), "test2");
+ assertEquals(props.get("testValue1"), "value");
+ assertNull(props.get("a"));
+
+ }
+
+ @Test
+ public void testChangingConfig() throws IOException {
+ Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ Map<String, String> props = config.getProperties();
+ assertEquals(props.get("test"), "test2");
+ assertEquals(props.get("testValue1"), "value");
+ assertNull(props.get("testValue2"));
+
+ //insert a new properties file into the tempdirectory
+ FileUtils.writeStringToFile(
+ new File(TestObservingProvider.propertyLocation.toFile(), "test2.properties"),
+ "testValue2=anotherValue");
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ props = config.getProperties();
+
+ assertEquals(props.get("test"), "test2");
+ assertEquals(props.get("testValue1"), "value");
+ assertEquals(props.get("testValue2"), "anotherValue");
+ }
+
@Test
//Y TODO Check tests later
- public void testConfigChanges()throws Exception{
+ public void testConfigChanges() throws Exception {
// // test empty directory
// testEmpty();
// // add a file, test for changes
@@ -85,17 +182,6 @@ public class ObservedConfigTest {
// testEmpty();
}
- private static Path getSourceFile(String name) throws Exception{
- URL url = ObservedConfigTest.class.getResource("/data");
- File testFile = new File(new File(url.toURI()), name);
- return Paths.get(testFile.toURI());
- }
-
- private static Path getTargetFile(String name) {
- File testFile = new File(TestObservingProvider.getTestDirectory(), name);
- return Paths.get(testFile.toURI());
- }
-
private void testEmpty() {
assertNull(ConfigurationProvider.getConfiguration().get("1"));
assertNull(ConfigurationProvider.getConfiguration().get("2"));
@@ -142,32 +228,4 @@ public class ObservedConfigTest {
assertNull(ConfigurationProvider.getConfiguration().get("6"));
}
- /**
- * Test method that periodically prints out what is happening.
- */
- public static void main() {
- while(true){
- System.out.println("1: " + ConfigurationProvider.getConfiguration().get("1"));
- System.out.println("2: " + ConfigurationProvider.getConfiguration().get("2"));
- System.out.println("3: " + ConfigurationProvider.getConfiguration().get("3"));
- System.out.println("4: " + ConfigurationProvider.getConfiguration().get("4"));
- System.out.println("5: " + ConfigurationProvider.getConfiguration().get("5"));
- System.out.println("6: " + ConfigurationProvider.getConfiguration().get("6"));
- System.out.println("=======================================================================");
- try {
- Thread.sleep(2000L);
- } catch (Exception e) {
- // stop here...
- }
- }
- }
-
- @AfterClass
- public static void cleanup()throws Exception{
- // cleanup directory
- Files.deleteIfExists(getTargetFile("test1.properties"));
- Files.deleteIfExists(getTargetFile("test2.properties"));
- Files.deleteIfExists(getTargetFile("test3.properties"));
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
new file mode 100644
index 0000000..ab6135d
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -0,0 +1,90 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+/**
+ * Created by Anatole on 24.03.2015.
+ */
+public class TestConfigView implements ConfigOperator{
+
+ private static final TestConfigView INSTANCE = new TestConfigView();
+
+ private TestConfigView(){}
+
+ public static ConfigOperator of(){
+ return INSTANCE;
+ }
+
+ @Override
+ public Configuration operate(Configuration config) {
+ return new Configuration() {
+ @Override
+ public Map<String, String> getProperties() {
+ return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
+ Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
+ }
+ /**
+ * Accesses the current String value for the given key and tries to convert it
+ * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @param <T> the value type
+ * @return the converted value, never null.
+ */
+ @Override
+ public <T> T get(String key, TypeLiteral<T> type) {
+ String value = get(key);
+ if (value != null) {
+ List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext()
+ .getPropertyConverters(type);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value);
+ if (t != null) {
+ return t;
+ }
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName())
+ .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: "
+ + value, e);
+ }
+ }
+ throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key);
+ }
+ return null;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
index 5b5a3aa..775de58 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
@@ -40,8 +40,10 @@ import java.util.logging.Logger;
*/
public class TestObservingProvider extends ObservingPropertySourceProvider{
+ public static Path propertyLocation;
+
public TestObservingProvider(){
- super(Paths.get(getTestPath()),
+ super(propertyLocation,
new PropertiesFormat());
Logger.getLogger(getClass().getName()).info("Using test directory: " + getTestPath());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
new file mode 100644
index 0000000..5640b81
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.events.delta;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test class for {@link org.apache.tamaya.events.delta.ConfigurationContextChange}.
+ */
+public class ConfigurationContextChangeTest {
+
+ @Test
+ public void testEmptyChangeSet() throws Exception {
+ ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet();
+ assertNotNull(change);
+ assertTrue(change.isEmpty());
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertNotNull(change.getVersion());
+ change = ConfigurationContextChangeBuilder.of().setVersion("version2").build();
+ assertNotNull(change.getVersion());
+ assertEquals("version2", change.getVersion());
+ }
+
+ @Test
+ public void testGetTimestamp() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue((System.currentTimeMillis() - change.getTimestamp()) <= 10L);
+ change = ConfigurationContextChangeBuilder.of().setTimestamp(10L).build();
+ assertEquals(10L, change.getTimestamp());
+ }
+
+ @Test
+ public void testGetPropertySourceChanges() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ }
+
+ @Test
+ public void testGetPropertySourceUpdates() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceUpdates(). isEmpty());
+ }
+
+ @Test
+ public void testGetRemovedPropertySources() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getRemovedPropertySources(). isEmpty());
+ }
+
+ @Test
+ public void testGetAddedPropertySources() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getAddedPropertySources().isEmpty());
+ }
+
+ @Test
+ public void testGetUpdatedPropertySources() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getPropertySourceChanges(). isEmpty());
+ change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.getUpdatedPropertySources().isEmpty());
+ }
+
+ @Test
+ public void testIsAffected() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ PropertySource ps = new SystemPropertySource();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().changedPropertySource(
+ PropertySourceChangeBuilder.of(ps, ChangeType.UPDATED).build()
+ ).build();
+ String toString = change.toString();
+ assertTrue(change.isAffected(ps));
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build();
+ assertTrue(change.isEmpty());
+ change = ConfigurationContextChangeBuilder.of().newPropertySource(new SystemPropertySource()).build();
+ assertFalse(change.isEmpty());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().newPropertySource(new SystemPropertySource()).build();
+ String toString = change.toString();
+ assertNotNull(toString);
+ assertTrue(toString.contains(new SystemPropertySource().getName()));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
new file mode 100644
index 0000000..b3b6145
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
@@ -0,0 +1,191 @@
+/*
+ * 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.events.delta;
+
+import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.resource.PropertySourceBuilder;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link org.apache.tamaya.events.delta.PropertySourceChange} and its builder.
+ */
+public class PropertySourceChangeTest {
+
+ private static final PropertySource myPS = new SystemPropertySource();
+
+ @Test
+ public void testGetChangeType() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED).build();
+ assertEquals(change.getChangeType(), ChangeType.DELETED);
+ change = PropertySourceChangeBuilder.of(myPS, ChangeType.UPDATED).build();
+ assertEquals(change.getChangeType(), ChangeType.UPDATED);
+ }
+
+ @Test
+ public void testGetPropertySource() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED).build();
+ assertEquals(change.getPropertySource().getName(), myPS.getName());
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED)
+ .setVersion("myVersion1").build();
+ assertEquals(change.getVersion(), "myVersion1");
+ }
+
+ @Test
+ public void testGetTimestamp() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED)
+ .setTimestamp(111L).build();
+ assertEquals(change.getTimestamp(), 111L);
+ }
+
+ @Test
+ public void testGetEvents() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED)
+ .addChanges(
+ new EnvironmentPropertySource()
+ ).build();
+ assertTrue(change.getEvents().size()>0);
+ }
+
+ @Test
+ public void testGetRemovedSize() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.UPDATED)
+ .addChanges(
+ new EnvironmentPropertySource()
+ ).build();
+ assertTrue(change.getRemovedSize()>0);
+ }
+
+ @Test
+ public void testGetAddedSize() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED)
+ .addChanges(
+ new EnvironmentPropertySource()
+ ).build();
+ assertTrue(change.getAddedSize()>0);
+ }
+
+ @Test
+ public void testGetUpdatedSize() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED)
+ .addChanges(
+ new EnvironmentPropertySource()
+ ).build();
+ assertTrue(change.getUpdatedSize()==0);
+ }
+
+ @Test
+ public void testIsRemoved() throws Exception {
+ PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
+ .add("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
+ .add("key3", "value3").build();
+ PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
+ .addChanges(
+ ps2
+ ).build();
+ assertFalse(change.isRemoved("key1"));
+ assertTrue(change.isRemoved("key2"));
+ assertFalse(change.isRemoved("key3"));
+ }
+
+ @Test
+ public void testIsAdded() throws Exception {
+ PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
+ .add("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
+ .add("key3", "value3").build();
+ PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
+ .addChanges(
+ ps2
+ ).build();
+ assertTrue(change.isAdded("key3"));
+ assertFalse(change.isAdded("key2"));
+ assertFalse(change.isAdded("key1"));
+ }
+
+ @Test
+ public void testIsUpdated() throws Exception {
+ PropertySource ps1 = PropertySourceBuilder.of("test").add("key1", "value1")
+ .add("key2", "value2").build();
+ PropertySource ps2 = PropertySourceBuilder.of("test").add("key1", "value2")
+ .add("key3", "value3").build();
+ PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
+ .addChanges(
+ ps2
+ ).build();
+ assertTrue(change.isUpdated("key1"));
+ assertFalse(change.isUpdated("key2"));
+ assertFalse(change.isUpdated("key3"));
+ }
+
+ @Test
+ public void testContainsKey() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED)
+ .addChanges(
+ myPS
+ ).build();
+ assertTrue(change.containsKey("java.version"));
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception {
+ PropertySourceChange change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED)
+ .build();
+ assertTrue(change.isEmpty());
+ change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED)
+ .addChanges(
+ myPS
+ ).build();
+ assertFalse(change.isEmpty());
+ }
+
+ @Test
+ public void testOfAdded() throws Exception {
+ PropertySourceChange change = PropertySourceChange.ofAdded(myPS);
+ assertNotNull(change);
+ assertEquals(change.getChangeType(), ChangeType.NEW);
+ }
+
+ @Test
+ public void testOfDeleted() throws Exception {
+ PropertySourceChange change = PropertySourceChange.ofDeleted(myPS);
+ assertNotNull(change);
+ assertEquals(change.getChangeType(), ChangeType.DELETED);
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ PropertySourceChange change = PropertySourceChange.ofAdded(myPS);
+ String toString = change.toString();
+ assertNotNull(toString);
+ assertTrue(toString.contains(myPS.getName()));
+ change = PropertySourceChange.ofDeleted(myPS);
+ toString = change.toString();
+ assertNotNull(toString);
+ assertTrue(toString.contains(myPS.getName()));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultEventSupportSpiTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultEventSupportSpiTest.java b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultEventSupportSpiTest.java
new file mode 100644
index 0000000..f650b9d
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultEventSupportSpiTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.events.internal;
+
+import org.apache.tamaya.events.Listener;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link org.apache.tamaya.events.internal.DefaultEventSupportSpi}.
+ */
+public class DefaultEventSupportSpiTest {
+
+ private DefaultEventSupportSpi spi = new DefaultEventSupportSpi();
+ private String testAddListenerValue;
+
+ @Test
+ public void testAddListener() throws Exception {
+ Listener<String> testListener = new Listener<String>() {
+
+ @Override
+ public void onEvent(String event) {
+ testAddListenerValue = event;
+ }
+ };
+ spi.addListener(testListener);
+ spi.fireEvent("Event1", String.class);
+ assertEquals(testAddListenerValue, "Event1");
+ spi.removeListener(testListener);
+ spi.fireEvent("Event2", String.class);
+ assertEquals(testAddListenerValue, "Event1");
+
+ }
+
+ @Test
+ public void testRemoveListener() throws Exception {
+ Listener<String> testListener = new Listener<String>() {
+
+ @Override
+ public void onEvent(String event) {
+ testAddListenerValue = event;
+ }
+ };
+ spi.removeListener(testListener);
+ spi.removeListener(testListener);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3013dbd5/modules/events/src/test/resources/test.properties
----------------------------------------------------------------------
diff --git a/modules/events/src/test/resources/test.properties b/modules/events/src/test/resources/test.properties
new file mode 100644
index 0000000..af06631
--- /dev/null
+++ b/modules/events/src/test/resources/test.properties
@@ -0,0 +1,21 @@
+#
+# 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 current 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.
+#
+testValue1=value
+test=test2
+a=b
\ No newline at end of file
[14/15] incubator-tamaya git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4927cad8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4927cad8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4927cad8
Branch: refs/heads/master
Commit: 4927cad8acb7d06ed2edfd2f937c713a9bb0e326
Parents: f534cb6 f49c07c
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:46:19 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:46:19 2015 +0200
----------------------------------------------------------------------
.gitignore | 3 ++-
.../tamaya/spi/ServiceContextManager.java | 7 ++++-
.../internal/DefaultConfigurationProvider.java | 6 ++++-
....apache.tamaya.core.resources.ResourceLoader | 19 -------------
...pache.tamaya.spi.ConfigurationContextBuilder | 19 +++++++++++++
.../org.apache.tamaya.spi.PropertySource | 3 +--
...tServiceContextTest$InvalidPriorityInterface | 3 +--
...efaultServiceContextTest$MultiImplsInterface | 2 +-
.../internal/DefaultConfigurationContext.java | 9 ++++++-
.../internal/DefaultConfigurationProvider.java | 9 ++++++-
....apache.tamaya.core.resources.ResourceLoader | 19 -------------
...pache.tamaya.spi.ConfigurationContextBuilder | 19 +++++++++++++
.../org.apache.tamaya.spi.PropertySource | 2 +-
jqassistant/default.xml | 1 +
jqassistant/serviceloader-rules.xml | 28 ++++++++++++++++++--
.../org.apache.tamaya.spi.PropertySource | 2 +-
...org.apache.tamaya.spi.PropertySourceProvider | 19 -------------
17 files changed, 99 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
[13/15] incubator-tamaya git commit: Triggering commit.
Posted by an...@apache.org.
Triggering commit.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/f534cb6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/f534cb6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/f534cb6f
Branch: refs/heads/master
Commit: f534cb6fe36b200493ec6b6ae5b0c5f5bbcadbad
Parents: 9af32c0
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:42:07 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:42:07 2015 +0200
----------------------------------------------------------------------
.../META-INF/services/org.apache.tamaya.spi.PropertySourceProvider | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f534cb6f/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
index 7e19865..7484bcd 100644
--- a/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ b/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -17,3 +17,4 @@
# under the License.
#
org.aspache.tamaya.examples.fileobserver.TestObservingProvider
+
[11/15] incubator-tamaya git commit: Adapted to common TypeLiteral
changes. TAMAYA-79: Removed file system direct dep.
Posted by an...@apache.org.
Adapted to common TypeLiteral changes.
TAMAYA-79: Removed file system direct dep.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/324151d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/324151d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/324151d4
Branch: refs/heads/master
Commit: 324151d41feb52c7fbbfe57b0e35f28b6b9959f1
Parents: 82b83f2
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:36:26 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:36:26 2015 +0200
----------------------------------------------------------------------
.../delta/ConfigurationChangeBuilder.java | 12 ++
.../events/internal/DefaultEventSupportSpi.java | 4 +-
.../events/delta/ConfigurationChangeTest.java | 155 +++++++++++++++++++
3 files changed, 169 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
index dc0add8..6274ad9 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
@@ -140,6 +140,17 @@ public final class ConfigurationChangeBuilder {
}
/**
+ * Applies a single key/value change.
+ * @param key the changed key
+ * @param value the new value.
+ * @return this instance for chining.
+ */
+ public ConfigurationChangeBuilder addChange(String key, String value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key), value));
+ return this;
+ }
+
+ /**
* Get the current values, also considering any changes recorded within this change set.
*
* @param key the key current the entry, not null.
@@ -241,4 +252,5 @@ public final class ConfigurationChangeBuilder {
", delta=" + delta + "]";
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
index b92bc49..743de7f 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
@@ -62,7 +62,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
@Override
public <T> void addListener(Listener<T> l) {
- Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), Listener.class)[0];
List<Listener> listeners = listenerMap.computeIfAbsent(type,
(k) -> Collections.synchronizedList(new ArrayList<>()));
synchronized (listeners) {
@@ -74,7 +74,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
@Override
public <T> void removeListener(Listener<T> l) {
- Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), Listener.class)[0];
List<Listener> listeners = listenerMap.get(type);
if (listeners != null) {
synchronized (listeners) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
new file mode 100644
index 0000000..58aff64
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.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.events.delta;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test class for {@link org.apache.tamaya.events.delta.ConfigurationChange}.
+ */
+public class ConfigurationChangeTest {
+
+ @Test
+ public void testEmptyChangeSet() throws Exception {
+ ConfigurationChange change = ConfigurationChange.emptyChangeSet(ConfigurationProvider.getConfiguration());
+ assertNotNull(change);
+ assertTrue(change.isEmpty());
+ }
+
+ @Test
+ public void testGetConfiguration() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+ assertNotNull(change);
+ assertTrue(change.isEmpty());
+ config.getProperties().entrySet().forEach(
+ en -> {
+ if (!"[meta]frozenAt".equals(en.getKey())) {
+ assertEquals("Error for " + en.getKey(), en.getValue(), change.getConfiguration().get(en.getKey()));
+ }
+ }
+ );
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+ assertNotNull(change.getVersion());
+ change = ConfigurationChangeBuilder.of(config).setVersion("version2").build();
+ assertNotNull(change.getVersion());
+ assertEquals("version2", change.getVersion());
+ }
+
+ @Test
+ public void testGetTimestamp() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+ assertTrue((System.currentTimeMillis() - change.getTimestamp()) <= 10L);
+ change = ConfigurationChangeBuilder.of(config).setTimestamp(10L).build();
+ assertEquals(10L, change.getTimestamp());
+ }
+
+ @Test
+ public void testGetEvents() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("key1", "key2").build();
+ assertTrue(change.getEvents().size() == 2);
+ change = ConfigurationChangeBuilder.of(config).addChange("key1Added", "value1Added").build();
+ assertTrue(change.getEvents().size() == 1);
+ }
+
+ @Test
+ public void testGetRemovedSize() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("java.version", "key2").build();
+ assertTrue(change.getRemovedSize() == 2);
+ assertTrue(change.getAddedSize() == 0);
+ }
+
+ @Test
+ public void testGetAddedSize() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+ assertTrue(change.getAddedSize() == 1);
+ assertTrue(change.getRemovedSize() == 0);
+ }
+
+ @Test
+ public void testGetUpdatedSize() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
+ assertTrue(change.getUpdatedSize() == 1);
+ }
+
+ @Test
+ public void testIsRemoved() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+ assertTrue(change.isRemoved("java.version"));
+ }
+
+ @Test
+ public void testIsAdded() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+ assertTrue(change.isAdded("key1"));
+ }
+
+ @Test
+ public void testIsUpdated() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
+ assertTrue(change.isUpdated("java.version"));
+ }
+
+ @Test
+ public void testContainsKey() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+ assertTrue(change.containsKey("key1"));
+ assertFalse(change.containsKey("key2"));
+ change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+ assertFalse(change.containsKey("java.version"));
+ assertFalse(change.containsKey("key2"));
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+ assertTrue(change.isEmpty());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+ change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+ assertTrue(change.toString().contains("timestamp"));
+ assertTrue(change.toString().contains("version"));
+ assertTrue(change.toString().contains("configuration"));
+ assertFalse(change.toString().contains("key1"));
+ assertFalse(change.toString().contains("key2"));
+ }
+}
\ No newline at end of file
[15/15] incubator-tamaya git commit: Made class/constrcutor public so
it can be loaded by ServiceLoader.
Posted by an...@apache.org.
Made class/constrcutor public so it can be loaded by ServiceLoader.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d941df7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d941df7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d941df7f
Branch: refs/heads/master
Commit: d941df7fcab5b04271771fed76cf310454dfb5e0
Parents: 4927cad
Author: anatole <an...@apache.org>
Authored: Thu May 21 09:40:06 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 09:40:06 2015 +0200
----------------------------------------------------------------------
.../tamaya/core/internal/DefaultConfigurationContextBuilder.java | 4 ++--
.../tamaya/core/internal/DefaultConfigurationContextBuilder.java | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d941df7f/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
index 85e3c7a..2c44689 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
@@ -38,14 +38,14 @@ import java.util.Objects;
/**
* Default implementation of {@link org.apache.tamaya.spi.ConfigurationContextBuilder}.
*/
-class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
+public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
Map<String, PropertySource> propertySources = new HashMap<>();
List<PropertyFilter> propertyFilters = new ArrayList<>();
Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
PropertyValueCombinationPolicy combinationPolicy;
- DefaultConfigurationContextBuilder(){
+ public DefaultConfigurationContextBuilder(){
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d941df7f/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
index 0f3ce3d..c181373 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
@@ -41,14 +41,14 @@ import java.util.stream.Collectors;
/**
* Default implementation of {@link org.apache.tamaya.spi.ConfigurationContextBuilder}.
*/
-class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
+public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
List<PropertySource> propertySources = new ArrayList<>();
List<PropertyFilter> propertyFilters = new ArrayList<>();
Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
PropertyValueCombinationPolicy combinationPolicy;
- DefaultConfigurationContextBuilder(){
+ public DefaultConfigurationContextBuilder(){
}
@Override
[04/15] incubator-tamaya git commit: Fixed rat issues.
Posted by an...@apache.org.
Fixed rat issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4048625b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4048625b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4048625b
Branch: refs/heads/master
Commit: 4048625bea1a629ef5b528c250991384c5e38e3f
Parents: 28e5694
Author: anatole <an...@apache.org>
Authored: Fri May 15 14:15:16 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri May 15 14:15:16 2015 +0200
----------------------------------------------------------------------
.../EnvironmentPropertySourceTest.java | 21 ++++++++++++++++++++
.../EnvironmentPropertySourceTest.java | 21 ++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4048625b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
index 995c7ad..280351e 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.junit.Test;
@@ -7,6 +25,9 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+/**
+ * Tests for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}.
+ */
public class EnvironmentPropertySourceTest {
private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4048625b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
index 995c7ad..280351e 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.junit.Test;
@@ -7,6 +25,9 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+/**
+ * Tests for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}.
+ */
public class EnvironmentPropertySourceTest {
private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
[07/15] incubator-tamaya git commit: Fixed default method in API fir
Java 8. Javadoc merge.
Posted by an...@apache.org.
Fixed default method in API fir Java 8.
Javadoc merge.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/216af2a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/216af2a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/216af2a9
Branch: refs/heads/master
Commit: 216af2a9048b40141e96d7347093a39f4b5259fa
Parents: 391671a
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:32:16 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:32:16 2015 +0200
----------------------------------------------------------------------
java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java | 8 ++++----
java8/api/src/main/java/org/apache/tamaya/Configuration.java | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/216af2a9/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index b29a699..ce5da22 100644
--- a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -123,10 +123,10 @@ public class TypeLiteral<T> implements Serializable {
}
/**
- * Returns basic raw Java type.
- *
- * @return the actual type represented by this object
- */
+ * Returns basic raw Java type.
+ *
+ * @return the actual type represented by this object
+ */
public final Class<T> getRawType() {
Class<T> rawType = null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/216af2a9/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index 7830225..583a1bf 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -51,7 +51,7 @@ public interface Configuration {
* @return the property's value or {@code null}.
*/
default String get(String key) {
- return get(key, String.class);
+ return getProperties().get(key);
}
[09/15] incubator-tamaya git commit: Fixed module list.
Posted by an...@apache.org.
Fixed module list.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7a39d865
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7a39d865
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7a39d865
Branch: refs/heads/master
Commit: 7a39d865e25883c2b1b372f755f6151179197549
Parents: 88a862d
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:33:51 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:33:51 2015 +0200
----------------------------------------------------------------------
examples/pom.xml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7a39d865/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 8cdb4be..05ea342 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -34,13 +34,13 @@ under the License.
<packaging>pom</packaging>
<modules>
- <module>minimal-example</module>
- <module>simple-propertysource-example</module>
- <!-- module>resources-example</module>
- <module>resolver-example</module>
- <module>formats-example</module>
- <module>injection-example</module>
- <module>events-example</module -->
+ <module>1-minimal-example</module>
+ <module>2-simple-propertysource-example</module>
+ <module>3-resources-example</module>
+ <module>4-resolver-example</module>
+ <module>6-fileobserver-example</module>
+ <module>5-injection-example</module>
+ <module>7-builder-example</module>
<!-- module>remote-example</module -->
</modules>
[03/15] incubator-tamaya git commit: Deactivated jqAssistant,
because I lost again useless time because the tool was breaking the
build. Discussions on tooling is required IMO.
Posted by an...@apache.org.
Deactivated jqAssistant, because I lost again useless time because the tool was breaking the build. Discussions on tooling is required IMO.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/28e56941
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/28e56941
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/28e56941
Branch: refs/heads/master
Commit: 28e56941c85cc18fafa7987953708bf94ea04648
Parents: 58bda32
Author: anatole <an...@apache.org>
Authored: Fri May 15 14:10:46 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri May 15 14:10:46 2015 +0200
----------------------------------------------------------------------
pom.xml | 35 -----------------------------------
1 file changed, 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/28e56941/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7b466c4..efa54b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,7 +56,6 @@ under the License.
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jackson.version>2.5.1</jackson.version>
<junit.version>4.12</junit.version>
- <jqassistant.version>1.0.0</jqassistant.version>
<!-- Dependency and plugin relate version properties go here -->
<arquillian.version>1.1.7.Final</arquillian.version>
@@ -472,45 +471,12 @@ under the License.
<version>3.3</version>
<inherited>true</inherited>
</plugin>
- <plugin>
- <groupId>com.buschmais.jqassistant.scm</groupId>
- <artifactId>jqassistant-maven-plugin</artifactId>
- <version>${jqassistant.version}</version>
- <configuration>
- <storeDirectory>jqassistant.datastore</storeDirectory>
- </configuration>
-
- <executions>
- <execution>
- <id>scan</id>
- <goals>
- <goal>scan</goal>
- </goals>
- </execution>
- <execution>
- <id>analyze</id>
- <goals>
- <goal>analyze</goal>
- </goals>
- <configuration>
- <!-- @todo Enable after 1.0.0-RC2 -->
- <failOnViolations>true</failOnViolations>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
</plugins>
</pluginManagement>
<plugins>
<plugin>
- <groupId>com.buschmais.jqassistant.scm</groupId>
- <artifactId>jqassistant-maven-plugin</artifactId>
- </plugin>
-
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
</plugin>
@@ -681,7 +647,6 @@ under the License.
<checkstyle.skip>true</checkstyle.skip>
<findbugs.skip>true</findbugs.skip>
<rat.skip>true</rat.skip>
- <jqassistant.skip>true</jqassistant.skip>
</properties>
</profile>
[12/15] incubator-tamaya git commit: Made experimental modules
compilable. Moved code from former dormant parts (which is removed now).
Posted by an...@apache.org.
Made experimental modules compilable.
Moved code from former dormant parts (which is removed now).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9af32c09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9af32c09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9af32c09
Branch: refs/heads/master
Commit: 9af32c09292ed7331c4373c6f704ee6831a628c8
Parents: 324151d
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:37:47 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:37:47 2015 +0200
----------------------------------------------------------------------
.../internal/InitialEnvironmentProvider.java | 44 ++++++++++----------
.../internal/SingleEnvironmentManager.java | 11 +++--
.../tamaya/environment/spi/ContextSpi.java | 4 +-
.../functions/ConfigurationFunctions.java | 1 -
.../tamaya/functions/FilteredConfiguration.java | 18 ++++++++
.../tamaya/functions/MappedConfiguration.java | 18 ++++++++
.../tamaya/functions/MappedPropertySource.java | 28 +++++++++----
.../functions/MetaEnrichedPropertySource.java | 18 ++++++++
.../functions/ValueFilteredPropertySource.java | 28 +++++++++++--
9 files changed, 127 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
index bf97d9c..062becc 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.environment.internal;
import java.net.InetAddress;
import java.util.Collections;
@@ -29,47 +29,45 @@ import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+import org.apache.tamaya.environment.RuntimeContext;
import org.apache.tamaya.environment.spi.ContextDataProvider;
-import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.environment.RuntimeContextBuilder;
/**
- * Default {@link org.apache.tamaya.metamodel.environment.RuntimeContext}.
+ * Default {@link org.apache.tamaya.environment.RuntimeContext}.
*/
public final class InitialEnvironmentProvider implements ContextDataProvider{
- private Map<String,String> contextData = new HashMap<>();
+ private static final String STAGE_PROP = "env.STAGE";
+ private Map<String,String> contextData = new HashMap<>();
public InitialEnvironmentProvider() {
- Properties props = System.getProperties();
- if(props instanceof ConfiguredSystemProperties){
- props = ((ConfiguredSystemProperties)props).getInitialProperties();
- }
- String stageValue = props.getProperty(RuntimeContextBuilder.STAGE_PROP);
- contextData.put(RuntimeContextBuilder.STAGE_PROP, stageValue);
- contextData.put("timezone", TimeZone.getDefault().getID());
- contextData.put("locale", Locale.getDefault().toString());
try {
contextData.put("host", InetAddress.getLocalHost().toString());
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
}
- // Copy env properties....
+ contextData.put("timezone", TimeZone.getDefault().getID());
+ contextData.put("locale", Locale.getDefault().toString());
+ // Copy all env properties....
for (Entry<String, String> en : System.getenv().entrySet()) {
contextData.put(en.getKey(), en.getValue());
}
+ String value = System.getProperty(STAGE_PROP);
+ if(value==null) {
+ value = System.getenv(STAGE_PROP);
+ }
+ if(value==null){
+ value = "DEVELOPMENT";
+ }
+ contextData.put(STAGE_PROP, value);
contextData = Collections.unmodifiableMap(contextData);
}
- @Override
- public boolean isActive(){
- return true;
- }
@Override
- public Map<String,String> getContextData() {
- return contextData;
- }
-
+ public RuntimeContext getContext(RuntimeContext currentContext) {
+ return RuntimeContextBuilder.of("root").withParentContext(currentContext)
+ .setAll(contextData).build();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
index fb636c7..7ed63b8 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
@@ -16,18 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.environment.internal;
-import org.apache.tamaya.metamodel.environment.RuntimeContext;
-import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.environment.RuntimeContext;
+import org.apache.tamaya.environment.RuntimeContextBuilder;
import org.apache.tamaya.spi.ServiceContext;
import java.util.*;
/**
- * Service for accessing {@link org.apache.tamaya.metamodel.environment.RuntimeContext}. Environments are used to
+ * Service for accessing {@link org.apache.tamaya.environment.RuntimeContext}. Environments are used to
* access/determine configurations.<br/>
* <h3>Implementation PropertyMapSpec</h3> This class is
* <ul>
@@ -35,7 +34,7 @@ import java.util.*;
* <li>and behaves contextual.
* </ul>
*/
-public class SingleEnvironmentManager implements org.apache.tamaya.metamodel.environment.spi.ContextSpi {
+public class SingleEnvironmentManager implements org.apache.tamaya.environment.spi.ContextSpi{
private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
private RuntimeContext rootEnvironment = getCurrentEnvironment();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
index ef4519a..1651aaa 100644
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
@@ -16,9 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.spi;
+package org.apache.tamaya.environment.spi;
+import org.apache.tamaya.environment.RuntimeContext;
+
/**
* Service for accessing the current ids that identify a runtime environment. Environments are used to
* access/determine configurations.<br/>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index 1f1c571..9a588fc 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -24,7 +24,6 @@ import org.apache.tamaya.Configuration;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiPredicate;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
index 1b731c1..2f92331 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
@@ -1,3 +1,21 @@
+/*
+ * 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.functions;
import org.apache.tamaya.Configuration;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
index a7af911..df1f43c 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
@@ -1,3 +1,21 @@
+/*
+ * 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.functions;
import org.apache.tamaya.Configuration;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
index ae37168..8491fa6 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.functions;
import org.apache.tamaya.spi.PropertySource;
@@ -5,7 +23,6 @@ import org.apache.tamaya.spi.PropertySource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.function.UnaryOperator;
/**
@@ -54,13 +71,8 @@ class MappedPropertySource implements PropertySource {
}
@Override
- public Optional<String> get(String key){
- return Optional.of(getProperties().get(key));
- }
-
- @Override
- public boolean isEmpty() {
- return this.propertySource.isEmpty();
+ public String get(String key){
+ return getProperties().get(key);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
index f43d65e..6ef32c3 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.functions;
import org.apache.tamaya.spi.PropertySource;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
index 23a5434..3180b0c 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.functions;
import org.apache.tamaya.spi.PropertySource;
@@ -31,10 +49,12 @@ class ValueFilteredPropertySource implements PropertySource{
}
@Override
- public Optional<String> get(String key) {
- String value = this.source.get(key).orElse(null);
- value = valueFilter.apply(key, value);
- return Optional.ofNullable(value);
+ public String get(String key) {
+ String value = this.source.get(key);
+ if(value!=null) {
+ return valueFilter.apply(key, value);
+ }
+ return null;
}
@Override
[10/15] incubator-tamaya git commit: TAMAYA-79: removed dep on local
filesystem.
Posted by an...@apache.org.
TAMAYA-79: removed dep on local filesystem.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/82b83f20
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/82b83f20
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/82b83f20
Branch: refs/heads/master
Commit: 82b83f20c1f1db835043bc7b389304c7d21d7e2e
Parents: 7a39d86
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:34:55 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:34:55 2015 +0200
----------------------------------------------------------------------
examples/6-fileobserver-example/pom.xml | 8 +-
.../src/data/test.properties | 21 ---
.../fileobserver/TestObservingProvider.java | 35 -----
...org.apache.tamaya.spi.PropertySourceProvider | 19 ---
.../fileobserver/ObservedConfigExampleTest.java | 145 +++++++++++++++++++
.../fileobserver/ObservedConfigTest.java | 54 -------
.../examples/fileobserver/TestConfigView.java | 90 ++++++++++++
.../fileobserver/TestObservingProvider.java | 37 +++++
...org.apache.tamaya.spi.PropertySourceProvider | 19 +++
.../src/test/resources/test.properties | 21 +++
10 files changed, 319 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/pom.xml b/examples/6-fileobserver-example/pom.xml
index fbe4af0..96bbba4 100644
--- a/examples/6-fileobserver-example/pom.xml
+++ b/examples/6-fileobserver-example/pom.xml
@@ -25,7 +25,8 @@ under the License.
<version>1.0-incubating-SNAPSHOT</version>
<name>Apache Tamaya Example: File Observer</name>
<description>This project contains a simple example observing a directory for (config) file changes, that updates
- the configuration correspondingly.</description>
+ the configuration correspondingly.
+ </description>
<packaging>jar</packaging>
@@ -46,6 +47,11 @@ under the License.
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/data/test.properties
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/data/test.properties b/examples/6-fileobserver-example/src/data/test.properties
deleted file mode 100644
index af06631..0000000
--- a/examples/6-fileobserver-example/src/data/test.properties
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# 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 current 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.
-#
-testValue1=value
-test=test2
-a=b
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestObservingProvider.java b/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestObservingProvider.java
deleted file mode 100644
index b1f5dcf..0000000
--- a/examples/6-fileobserver-example/src/main/java/org/apache/tamaya/examples/fileobserver/TestObservingProvider.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.examples.fileobserver;
-
-import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
-import org.apache.tamaya.format.formats.PropertiesFormat;
-
-import java.nio.file.Paths;
-
-/**
- * Test configuration property source provider that observes a directory and updated the config if necessary.
- */
-public class TestObservingProvider extends ObservingPropertySourceProvider{
-
- public TestObservingProvider(){
- super(Paths.get("C:\\Users\\Anatole\\IdeaProjects\\incubator-tamaya\\examples\\6-fileobserver-example\\src\\data"),
- new PropertiesFormat());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/examples/6-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index 4792667..0000000
--- a/examples/6-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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 current 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.
-#
-org.apache.tamaya.examples.fileobserver.TestObservingProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
new file mode 100644
index 0000000..936d5ac
--- /dev/null
+++ b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.aspache.tamaya.examples.fileobserver;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test (currently manual) to test configuration changes.
+ */
+public class ObservedConfigExampleTest {
+
+ @Before
+ public void setup() throws IOException {
+ // create some temporary config
+ Path tempDir = Files.createTempDirectory("observedFolder");
+
+ TestObservingProvider.propertyLocation = tempDir;
+
+ FileUtils.copyInputStreamToFile(
+ getClass().getResourceAsStream("/test.properties"),
+ new File(tempDir.toFile(), "test.properties"));
+ }
+
+
+// private static Path getSourceFile(String name) throws Exception {
+// URL url = ObservedConfigExampleTest.class.getResource("/data");
+// File testFile = new File(new File(url.toURI()), name);
+// return Paths.get(testFile.toURI());
+// }
+//
+// private static Path getTargetFile(String name) {
+// File testFile = new File(TestObservingProvider.getTestDirectory(), name);
+// return Paths.get(testFile.toURI());
+// }
+
+ /**
+ * Test method that periodically prints out what is happening.
+ */
+ public static void main() {
+ while (true) {
+ System.out.println("1: " + ConfigurationProvider.getConfiguration().get("1"));
+ System.out.println("2: " + ConfigurationProvider.getConfiguration().get("2"));
+ System.out.println("3: " + ConfigurationProvider.getConfiguration().get("3"));
+ System.out.println("4: " + ConfigurationProvider.getConfiguration().get("4"));
+ System.out.println("5: " + ConfigurationProvider.getConfiguration().get("5"));
+ System.out.println("6: " + ConfigurationProvider.getConfiguration().get("6"));
+ System.out.println("=======================================================================");
+ try {
+ Thread.sleep(2000L);
+ } catch (Exception e) {
+ // stop here...
+ }
+ }
+ }
+
+// @AfterClass
+// public static void cleanup() throws Exception {
+// // cleanup directory
+// Files.deleteIfExists(getTargetFile("test1.properties"));
+// Files.deleteIfExists(getTargetFile("test2.properties"));
+// Files.deleteIfExists(getTargetFile("test3.properties"));
+// }
+
+
+
+ public void testInitialConfig() throws IOException {
+ Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ Map<String, String> props = config.getProperties();
+
+ assertThat(props.get("test"), is("test2"));
+ assertThat(props.get("testValue1"), is("value"));
+ assertNull(props.get("a"));
+
+ }
+
+ @Test
+ public void testChangingConfig() throws IOException {
+ Configuration config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ Map<String, String> props = config.getProperties();
+ assertThat(props.get("test"), is("test2"));
+ assertThat(props.get("testValue1"), is("value"));
+ assertNull(props.get("testValue2"));
+
+ //insert a new properties file into the tempdirectory
+ FileUtils.writeStringToFile(
+ new File(TestObservingProvider.propertyLocation.toFile(), "test2.properties"),
+ "testValue2=anotherValue");
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ config = ConfigurationProvider.getConfiguration().with(TestConfigView.of());
+
+ props = config.getProperties();
+
+ assertThat(props.get("test"), is("test2"));
+ assertThat(props.get("testValue1"), is("value"));
+ assertThat(props.get("testValue2"), is("anotherValue"));
+ }
+
+ private static String dump(Map<String, String> properties) {
+ StringBuilder b = new StringBuilder();
+ new TreeMap<>(properties).forEach((k,v)->b.append(" " + k + " = " + v + '\n'));
+ return b.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigTest.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigTest.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigTest.java
deleted file mode 100644
index 674a35d..0000000
--- a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.aspache.tamaya.examples.fileobserver;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.examples.fileobserver.TestConfigView;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Test (currently manual) to test configuration changes.
- */
-public class ObservedConfigTest {
-
- @Test
- public void testInitialConfig(){
- for(int i=0;i<100;i++){
- System.out.println(dump(ConfigurationProvider.getConfiguration().with(TestConfigView.of()).getProperties()));
- System.out.println("=======================================================================");
- try{
- Thread.sleep(2000L);
- }
- catch(Exception e){
- // ignore
- e.printStackTrace();
- }
- }
-
- }
-
- private static String dump(Map<String, String> properties) {
- StringBuilder b = new StringBuilder();
- new TreeMap<>(properties).forEach((k,v)->b.append(" " + k + " = " + v + '\n'));
- return b.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestConfigView.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestConfigView.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestConfigView.java
new file mode 100644
index 0000000..0095f19
--- /dev/null
+++ b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestConfigView.java
@@ -0,0 +1,90 @@
+/*
+ * 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.aspache.tamaya.examples.fileobserver;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+/**
+ * Created by Anatole on 24.03.2015.
+ */
+public class TestConfigView implements ConfigOperator{
+
+ private static final TestConfigView INSTANCE = new TestConfigView();
+
+ private TestConfigView(){}
+
+ public static ConfigOperator of(){
+ return INSTANCE;
+ }
+
+ @Override
+ public Configuration operate(Configuration config) {
+ return new Configuration() {
+ @Override
+ public Map<String, String> getProperties() {
+ return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
+ Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
+ }
+ /**
+ * Accesses the current String value for the given key and tries to convert it
+ * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @param <T> the value type
+ * @return the converted value, never null.
+ */
+ @Override
+ public <T> T get(String key, TypeLiteral<T> type) {
+ String value = get(key);
+ if (value != null) {
+ List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext()
+ .getPropertyConverters(type);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value);
+ if (t != null) {
+ return t;
+ }
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName())
+ .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: "
+ + value, e);
+ }
+ }
+ throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key);
+ }
+ return null;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
new file mode 100644
index 0000000..0588f13
--- /dev/null
+++ b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
@@ -0,0 +1,37 @@
+/*
+ * 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.aspache.tamaya.examples.fileobserver;
+
+import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
+import org.apache.tamaya.format.formats.PropertiesFormat;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Test configuration property source provider that observes a directory and updated the config if necessary.
+ */
+public class TestObservingProvider extends ObservingPropertySourceProvider{
+
+ public static Path propertyLocation;
+
+ public TestObservingProvider(){
+ super(propertyLocation, new PropertiesFormat());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..7e19865
--- /dev/null
+++ b/examples/6-fileobserver-example/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.aspache.tamaya.examples.fileobserver.TestObservingProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82b83f20/examples/6-fileobserver-example/src/test/resources/test.properties
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/resources/test.properties b/examples/6-fileobserver-example/src/test/resources/test.properties
new file mode 100644
index 0000000..af06631
--- /dev/null
+++ b/examples/6-fileobserver-example/src/test/resources/test.properties
@@ -0,0 +1,21 @@
+#
+# 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 current 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.
+#
+testValue1=value
+test=test2
+a=b
\ No newline at end of file