tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya git commit: TAMAYA-48 added PropertiesFilePropertySource and JavaConfigurationProvider
Date Tue, 06 Jan 2015 06:56:09 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master a83ba18f1 -> a2a36f16a


TAMAYA-48 added PropertiesFilePropertySource and JavaConfigurationProvider

Signed-off-by: Oliver B. Fischer <plexus@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a2a36f16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a2a36f16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a2a36f16

Branch: refs/heads/master
Commit: a2a36f16a52093428b6e183bb5162ce5d6917f53
Parents: a83ba18
Author: Reinhard Sandtner <reinhard.sandtner@gmail.com>
Authored: Mon Jan 5 22:04:14 2015 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Tue Jan 6 07:55:08 2015 +0100

----------------------------------------------------------------------
 .../core/internal/PropertiesFileLoader.java     | 102 +++++++++++++++++++
 .../core/propertysource/DefaultOrdinal.java     |   7 +-
 .../PropertiesFilePropertySource.java           |  47 +++++++++
 .../PropertiesPropertySource.java               |  51 ++++++++++
 .../propertysource/SystemPropertySource.java    |  15 ++-
 .../provider/JavaConfigurationProvider.java     |  60 +++++++++++
 .../test/internal/PropetiesFileLoaderTest.java  |  76 ++++++++++++++
 .../PropertiesFilePropertySourceTest.java       |  71 +++++++++++++
 .../provider/JavaConfigurationProviderTest.java |  53 ++++++++++
 ...org.apache.tamaya.spi.PropertySourceProvider |   3 +-
 .../test/resources/javaconfiguration.properties |  22 ++++
 .../test/resources/overrideOrdinal.properties   |  25 +++++
 core/src/test/resources/testfile.properties     |  22 ++++
 13 files changed, 542 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
b/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
new file mode 100644
index 0000000..b79a756
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
@@ -0,0 +1,102 @@
+/*
+ * 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.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+public final class PropertiesFileLoader {
+
+
+    private PropertiesFileLoader() {
+        // no instantiation
+    }
+
+
+    /**
+     * loads all properties-files with the given name.
+     * If the name do not end with {@code .properties} it will be appended
+     *
+     * @param name of the properties file
+     *
+     * @return URLs of properties-files or
+     *         an empty {@link Set} if no files has been found
+     *
+     * @throws IOException in case of problems loading the properties-files
+     */
+    public static Set<URL> resolvePropertiesFiles(String name) throws IOException {
+        Objects.requireNonNull(name);
+
+        if (!name.endsWith(".properties")) {
+            name = name + ".properties";
+        }
+
+        Set<URL> urls = new HashSet<>();
+
+        Enumeration<URL> files = Thread.currentThread().getContextClassLoader().getResources(name);
+        while (files.hasMoreElements()) {
+            urls.add(files.nextElement());
+        }
+
+        return urls;
+    }
+
+
+    /**
+     * loads the Properties from the given URL
+     *
+     * @param propertiesFile {@link URL} to load Properties from
+     *
+     * @return loaded {@link Properties}
+     *
+     * @throws IllegalStateException in case of an error while reading properties-file
+     */
+    public static Properties load(URL propertiesFile) {
+
+        Properties properties = new Properties();
+
+        InputStream stream = null;
+        try {
+            stream = propertiesFile.openStream();
+
+            if (stream != null) {
+                properties.load(stream);
+            }
+        } catch (IOException e) {
+            throw new IllegalStateException("Error loading Properties " + propertiesFile,
e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    // bad luck -> stream is already closed
+                }
+            }
+        }
+
+        return properties;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
b/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
index 9e5d5dc..ff35e3f 100644
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
+++ b/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
@@ -36,8 +36,6 @@ public final class DefaultOrdinal {
      */
     public static final int PROPERTY_SOURCE = 1000;
 
-    //X TODO disuss default ordinal of SystemProperties
-
     /**
      * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
      */
@@ -48,4 +46,9 @@ public final class DefaultOrdinal {
      */
     public static final int ENVIRONMENT_PROPERTIES = 300;
 
+    /**
+     * default ordinal for {@link org.apache.tamaya.core.propertysource.PropertiesFilePropertySource}
+     */
+    public static final int FILE_PROPERTIES = 100;
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
new file mode 100644
index 0000000..e117a12
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
@@ -0,0 +1,47 @@
+/*
+ * 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.internal.PropertiesFileLoader;
+
+import java.net.URL;
+
+/**
+ * {@link org.apache.tamaya.spi.PropertySource} for properties-files
+ */
+public class PropertiesFilePropertySource extends PropertiesPropertySource {
+
+
+    private String fileName;
+
+
+    public PropertiesFilePropertySource(URL propertiesFile) {
+        super(PropertiesFileLoader.load(propertiesFile));
+
+        initializeOrdinal(DefaultOrdinal.FILE_PROPERTIES);
+        this.fileName = propertiesFile.toExternalForm();
+    }
+
+
+    @Override
+    public String getName() {
+        return fileName;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
new file mode 100644
index 0000000..cf68bd6
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * base class for {@link org.apache.tamaya.spi.PropertySource}s which are based on
+ * {@link java.util.Properties}
+ */
+abstract class PropertiesPropertySource extends BasePropertySource {
+
+    protected Map<String, String> properties;
+
+
+    // package private to not expose this class
+    PropertiesPropertySource(Properties properties) {
+        Map<String, String> props = new HashMap<>();
+
+        for (String key : properties.stringPropertyNames()) {
+            props.put(key, properties.getProperty(key));
+        }
+
+        this.properties = Collections.unmodifiableMap(props);
+    }
+
+
+    @Override
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
b/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
index 4ead5ab..50d788d 100644
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -26,12 +26,7 @@ import java.util.Properties;
 /**
  * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
  */
-public class SystemPropertySource extends BasePropertySource {
-
-    /**
-     * cached System.getProperties() filled in our Map
-     */
-    private Map<String, String> properties;
+public class SystemPropertySource extends PropertiesPropertySource {
 
     /**
      * previous System.getProperties().hashCode()
@@ -41,6 +36,8 @@ public class SystemPropertySource extends BasePropertySource {
 
 
     public SystemPropertySource() {
+        super(System.getProperties());
+        previousHash = System.getProperties().hashCode();
         initializeOrdinal(DefaultOrdinal.SYSTEM_PROPERTIES);
     }
 
@@ -54,11 +51,11 @@ public class SystemPropertySource extends BasePropertySource {
     public Map<String, String> getProperties() {
 
         // only need to reload and fill our map if something has changed
-        if (properties == null || previousHash != System.getProperties().hashCode()) {
+        if (previousHash != System.getProperties().hashCode()) {
 
             synchronized (this) {
 
-                if (properties == null || previousHash != System.getProperties().hashCode())
{
+                if (previousHash != System.getProperties().hashCode()) {
 
                     Properties systemProperties = System.getProperties();
                     Map<String, String> properties = new HashMap<>();
@@ -73,6 +70,6 @@ public class SystemPropertySource extends BasePropertySource {
             }
         }
 
-        return properties;
+        return super.getProperties();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
b/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
new file mode 100644
index 0000000..0341c0e
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.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.core.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ */
+public class JavaConfigurationProvider implements PropertySourceProvider {
+
+
+    @Override
+    public Collection<PropertySource> getPropertySources() {
+
+        List<PropertySource> propertySources = new ArrayList<>();
+
+        //X TODO maybe put javaconf... in META-INF
+
+        try {
+            propertySources.addAll(
+                    PropertiesFileLoader.resolvePropertiesFiles("javaconfiguration.properties")
+                            .stream()
+                            .map(PropertiesFilePropertySource::new)
+                            .collect(Collectors.toList()));
+
+
+        } catch (IOException e) {
+            throw new IllegalStateException("error loading javaconfiguration.properties",
e);
+        }
+
+        return Collections.unmodifiableList(propertySources);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
b/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
new file mode 100644
index 0000000..985b5d5
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Properties;
+import java.util.Set;
+
+public class PropetiesFileLoaderTest {
+
+
+    @Test
+    public void testResolvePropertiesFiles() throws Exception {
+        Properties expectedProperties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+        {
+            // with .properties
+            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
+            Assert.assertNotNull(urls);
+            Assert.assertFalse(urls.isEmpty());
+
+            Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+            Assert.assertEquals(expectedProperties.size(), properties.size());
+        }
+
+        {
+            // without .properties
+            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
+            Assert.assertNotNull(urls);
+            Assert.assertFalse(urls.isEmpty());
+
+            Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+            Assert.assertEquals(expectedProperties.size(), properties.size());
+        }
+
+        {
+            // with a while which doesn't exist
+            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
+            Assert.assertNotNull(urls);
+            Assert.assertTrue(urls.isEmpty());
+        }
+
+    }
+
+    @Test
+    public void testLoad() {
+        Properties properties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+        Assert.assertNotNull(properties);
+        Assert.assertEquals(5, properties.size());
+
+        for (int i = 1; i < 6; i++) {
+            Assert.assertEquals(properties.getProperty("key" + i), "val" + i);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
b/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..6a1c9e7
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+public class PropertiesFilePropertySourceTest {
+
+    private PropertiesFilePropertySource testfilePropertySource;
+    private PropertiesFilePropertySource overrideOrdinalPropertySource;
+
+
+    @Before
+    public void initTest() {
+        testfilePropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+        overrideOrdinalPropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+    }
+
+
+    @Test
+    public void testGetOrdinal() {
+        Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
+        Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL).get()),
overrideOrdinalPropertySource.getOrdinal());
+    }
+
+
+    @Test
+    public void testGet() {
+        Assert.assertEquals("val3", testfilePropertySource.get("key3").get());
+        Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get());
+        Assert.assertFalse(testfilePropertySource.get("nonpresentkey").isPresent());
+    }
+
+
+    @Test
+    public void testGetProperties() throws Exception {
+        Properties expectedProperties = PropertiesFileLoader.load(new URL(testfilePropertySource.getName()));
+
+        Assert.assertEquals(expectedProperties.size(), testfilePropertySource.getProperties().size());
+
+        for (Map.Entry<String, String> entry : testfilePropertySource.getProperties().entrySet())
{
+            Assert.assertEquals(expectedProperties.getProperty(entry.getKey()), entry.getValue());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
b/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..5c5fefc
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.Configuration;
+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;
+
+public class JavaConfigurationProviderTest {
+
+    @Test
+    public void testJavaConfigurationProvider() {
+
+        Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+        Assert.assertNotNull(propertySources);
+        Assert.assertEquals(1, propertySources.size());
+
+        PropertySource propertySource = propertySources.iterator().next();
+        for (int i = 1; i < 6; i++) {
+            String key = "confkey" + i;
+            String value = "javaconf-value" + i;
+
+            Assert.assertEquals(value, propertySource.get(key).get());
+
+            // check if we had our key in configuration.current
+            Assert.assertTrue(Configuration.current().getProperties().containsKey(key));
+            Assert.assertEquals(value, Configuration.current().get(key).get());
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
index c45e07c..afc8910 100644
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -16,4 +16,5 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.tamaya.core.testdata.TestPropertySourceProvider
\ No newline at end of file
+org.apache.tamaya.core.testdata.TestPropertySourceProvider
+org.apache.tamaya.core.provider.JavaConfigurationProvider
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/javaconfiguration.properties b/core/src/test/resources/javaconfiguration.properties
new file mode 100644
index 0000000..b461414
--- /dev/null
+++ b/core/src/test/resources/javaconfiguration.properties
@@ -0,0 +1,22 @@
+# 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.
+
+confkey1=javaconf-value1
+confkey2=javaconf-value2
+confkey3=javaconf-value3
+confkey4=javaconf-value4
+confkey5=javaconf-value5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/overrideOrdinal.properties b/core/src/test/resources/overrideOrdinal.properties
new file mode 100644
index 0000000..96935a8
--- /dev/null
+++ b/core/src/test/resources/overrideOrdinal.properties
@@ -0,0 +1,25 @@
+# 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.
+
+#override ordinal
+tamaya.ordinal=16784
+
+mykey1=myval1
+mykey2=myval2
+mykey3=myval3
+mykey4=myval4
+mykey5=myval5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a2a36f16/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/testfile.properties b/core/src/test/resources/testfile.properties
new file mode 100644
index 0000000..abd7ee8
--- /dev/null
+++ b/core/src/test/resources/testfile.properties
@@ -0,0 +1,22 @@
+# 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.
+
+key1=val1
+key2=val2
+key3=val3
+key4=val4
+key5=val5
\ No newline at end of file


Mime
View raw message