You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2015/03/05 19:20:04 UTC

[5/5] incubator-tamaya git commit: TAMAYA-60 A ConfigException will be thrown if there is no configuration format able to handle the given property resource.

TAMAYA-60 A ConfigException will be thrown if there is no configuration format able to handle the given property resource.


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

Branch: refs/heads/master
Commit: dc984efc9a6c4873e0cf3c91713ac677df90faca
Parents: 51d893a
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Thu Mar 5 19:20:31 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Thu Mar 5 19:19:49 2015 +0100

----------------------------------------------------------------------
 .../modules/builder/ConfigurationBuilder.java    | 18 +++++++++++++++++-
 .../builder/ConfigurationBuilderTest.java        | 11 +++++++++++
 .../test/resources/configfiles/other/simple.oml  | 19 +++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc984efc/modules/builder/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/modules/builder/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
index 465b180..8c314e1 100644
--- a/modules/builder/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ b/modules/builder/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
@@ -43,6 +43,8 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import static java.lang.String.format;
+
 /* TODO LIST FOR TAMAYA-60
  *
  * - configurable loading of provided PropertyConverter DONE
@@ -99,7 +101,8 @@ public class ConfigurationBuilder {
 
     public ConfigurationBuilder addPropertySource(URL url) {
         try {
-            ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
+            ConfigurationData data = getConfigurationDataFromURL(url);
+
             FlattenedDefaultPropertySource propertySource = new FlattenedDefaultPropertySource(data);
             addPropertySources(propertySource);
         } catch (IOException e) {
@@ -109,6 +112,19 @@ public class ConfigurationBuilder {
         return this;
     }
 
+    private ConfigurationData getConfigurationDataFromURL(URL url) throws IOException {
+        ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
+
+        if (null == data) {
+            String mesg = format("No configuration format found which is able " +
+                                 "to read properties from %s.", url.toString());
+
+            throw new ConfigException(mesg);
+        }
+
+        return data;
+    }
+
     public ConfigurationBuilder addPropertySource(URL url, URL... urls) {
         Stream.of(Collections.singletonList(url), Arrays.asList(urls))
               .flatMap(Collection::stream)

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc984efc/modules/builder/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java b/modules/builder/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
index 5997aeb..1ddce26 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
@@ -766,6 +766,17 @@ public class ConfigurationBuilderTest {
      * Tests for loading resources via URL (as String)
      */
 
+    @Test(expected = ConfigException.class)
+    public void tryToLoadOneUnsupportedPropertySourceViaStringURL() {
+        URL resource = this.getClass().getResource("/configfiles/other/simple.oml");
+
+        assertThat(resource, CoreMatchers.notNullValue());
+
+        ConfigurationBuilder builder = new ConfigurationBuilder();
+
+        builder.addPropertySource(resource.toString()).build();
+    }
+
     @Test
     public void loadOneJSONPropertySourceViaStringURL() {
         URL resource = this.getClass().getResource("/configfiles/json/simple.json");

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc984efc/modules/builder/src/test/resources/configfiles/other/simple.oml
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/resources/configfiles/other/simple.oml b/modules/builder/src/test/resources/configfiles/other/simple.oml
new file mode 100644
index 0000000..494dba3
--- /dev/null
+++ b/modules/builder/src/test/resources/configfiles/other/simple.oml
@@ -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.
+#
+Key:=Value