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-39 Added JSON supporting implementation of ConfigurationFormat.
Date Sun, 01 Mar 2015 17:09:14 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 7f1b64536 -> a26f11b3e


TAMAYA-39 Added JSON supporting implementation of ConfigurationFormat.


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

Branch: refs/heads/master
Commit: a26f11b3efbc545b28cd3d13d91654d8ccd2b1c3
Parents: 7f1b645
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sun Mar 1 18:08:27 2015 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sun Mar 1 18:08:27 2015 +0100

----------------------------------------------------------------------
 .../apache/tamaya/modules/json/JSONFormat.java  |  35 ++--
 ...org.apache.tamaya.format.ConfigurationFormat |  19 ++
 .../json/CommonJSONTestCaseCollection.java      | 173 +++++++++++++++++++
 .../modules/json/ConfigurationDataUCD.java      |  44 +++++
 .../tamaya/modules/json/JSONFormatIT.java       |  47 +++++
 .../tamaya/modules/json/JSONFormatTest.java     |  13 +-
 .../modules/json/JSONPropertySourceTest.java    | 166 +-----------------
 .../modules/json/JSONPropertySourceUCD.java     |  39 +++++
 .../tamaya/modules/json/UnifiedConfigData.java  |  32 ++++
 9 files changed, 390 insertions(+), 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONFormat.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONFormat.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONFormat.java
index f7f9361..21def33 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONFormat.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONFormat.java
@@ -18,13 +18,20 @@
  */
 package org.apache.tamaya.modules.json;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.tamaya.ConfigException;
 import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationDataBuilder;
 import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.format.InputStreamCloser;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.HashMap;
 import java.util.Objects;
-import java.util.concurrent.locks.StampedLock;
 
 /**
  * Implementation of the {@link org.apache.tamaya.format.ConfigurationFormat}
@@ -33,10 +40,6 @@ import java.util.concurrent.locks.StampedLock;
  * @see <a href="http://www.json.org">JSON format specification</a>
  */
 public class JSONFormat implements ConfigurationFormat {
-    /**
-     * Lock for internal synchronization.
-     */
-    private StampedLock lock = new StampedLock();
 
     @Override
     public boolean accepts(URL url) {
@@ -45,24 +48,24 @@ public class JSONFormat implements ConfigurationFormat {
         boolean isAFile = url.getProtocol().equals("file");
         boolean isJSON = url.getPath().endsWith(".json");
 
-
         return isAFile && isJSON;
     }
 
     @Override
     public ConfigurationData readConfiguration(String resource, InputStream inputStream)
{
 
-//        try (InputStream is = new InputStreamCloser(inputStream)){
-//            ObjectMapper mapper = new ObjectMapper();
-//            JsonNode root = mapper.readTree(is);
-
-
-//        } catch (IOException e) {
-//            throw new ConfigException("Failed to ");
-//        }
-
+        try (InputStream is = new InputStreamCloser(inputStream)){
+            ObjectMapper mapper = new ObjectMapper();
+            JsonNode root = mapper.readTree(is);
 
+            HashMap<String, String> values = new HashMap<>();
+            JSONVisitor visitor = new JSONVisitor((ObjectNode) root, values);
+            visitor.run();
 
-        throw new RuntimeException("Not implemented yet!");
+            return ConfigurationDataBuilder.of(resource, this).addProperties(values)
+                                           .build();
+        } catch (IOException e) {
+            throw new ConfigException("Failed to read data from " + resource);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
b/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
new file mode 100644
index 0000000..a482df3
--- /dev/null
+++ b/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
@@ -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.apache.tamaya.modules.json.JSONFormat
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/CommonJSONTestCaseCollection.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/CommonJSONTestCaseCollection.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/CommonJSONTestCaseCollection.java
new file mode 100644
index 0000000..2929bfa
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/CommonJSONTestCaseCollection.java
@@ -0,0 +1,173 @@
+/*
+ * 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.modules.json;
+
+import org.apache.tamaya.ConfigException;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import java.net.URL;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+
+/**
+ * Class with a collection of common test cases each JSON processing
+ * class must be able to pass.
+ */
+public abstract class CommonJSONTestCaseCollection {
+
+    abstract UnifiedConfigData getPropertiesFrom(URL source) throws Exception;
+
+    @Test
+    public void canReadNestedStringOnlyJSONConfigFile() throws Exception {
+        URL configURL = JSONPropertySourceTest.class
+                .getResource("/configs/valid/simple-nested-string-only-config-1.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        assertThat(properties.getProperties().keySet(), hasSize(5));
+
+        String keyB = properties.get("b");
+        String keyDO = properties.get("d.o");
+        String keyDP = properties.get("d.p");
+
+        assertThat(keyB, notNullValue());
+        assertThat(keyB, equalTo("B"));
+        assertThat(keyDO, notNullValue());
+        assertThat(keyDO, equalTo("O"));
+        assertThat(keyDP, Matchers.notNullValue());
+        assertThat(keyDP, is("P"));
+    }
+
+    @Test
+    public void canReadNestedStringOnlyJSONConfigFileWithObjectInTheMiddle()
+            throws Exception {
+        URL configURL = JSONPropertySourceTest.class
+                .getResource("/configs/valid/simple-nested-string-only-config-2.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        assertThat(properties.getProperties().keySet(), hasSize(4));
+
+        String keyA = properties.get("a");
+        String keyDO = properties.get("b.o");
+        String keyDP = properties.get("b.p");
+        String keyC = properties.get("c");
+
+        assertThat(keyA, notNullValue());
+        assertThat(keyA, is("A"));
+        assertThat(keyC, notNullValue());
+        assertThat(keyC, equalTo("C"));
+        assertThat(keyDO, notNullValue());
+        assertThat(keyDO, equalTo("O"));
+        assertThat(keyDP, notNullValue());
+        assertThat(keyDP, is("P"));
+    }
+
+    @Test(expected = ConfigException.class)
+    public void canHandleIllegalJSONFileWhichContainsAnArray() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/with-array.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        getPropertiesFrom(configURL).getProperties();
+    }
+
+    @Test(expected = ConfigException.class)
+    public void canHandleIllegalJSONFileConsistingOfOneOpeningBracket() throws Exception
{
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/only-opening-bracket.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        getPropertiesFrom(configURL).getProperties();
+    }
+
+    @Test(expected = ConfigException.class)
+    public void canHandleIllegalJSONFileWhichIsEmpty() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/empty-file.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        getPropertiesFrom(configURL).getProperties();
+    }
+
+    @Test
+    public void priorityInConfigFileOverwriteExplicitlyGivenPriority() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        assertThat(properties.getOrdinal(), is(16784));
+    }
+
+    @Test
+    public void canReadFlatStringOnlyJSONConfigFile() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-flat-string-only-config.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        assertThat(properties.getProperties().keySet(), hasSize(3));
+
+        String keyA = properties.get("a");
+        String keyB = properties.get("b");
+        String keyC = properties.get("c");
+
+        assertThat(keyA, notNullValue());
+        assertThat(keyA, equalTo("A"));
+        assertThat(keyB, notNullValue());
+        assertThat(keyB, is("B"));
+        assertThat(keyC, notNullValue());
+        assertThat(keyC, is("C"));
+    }
+
+    @Test(expected = ConfigException.class)
+    public void emptyJSONFileResultsInConfigException() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/empty-file.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        properties.getProperties();
+    }
+
+    @Test
+    public void canHandleEmptyJSONObject() throws Exception {
+        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/empty-object-config.json");
+
+        assertThat(configURL, CoreMatchers.notNullValue());
+
+        UnifiedConfigData properties = getPropertiesFrom(configURL);
+
+        assertThat(properties.getProperties().keySet(), hasSize(0));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/ConfigurationDataUCD.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/ConfigurationDataUCD.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/ConfigurationDataUCD.java
new file mode 100644
index 0000000..9de90e0
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/ConfigurationDataUCD.java
@@ -0,0 +1,44 @@
+/*
+ * 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.modules.json;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+
+public class ConfigurationDataUCD implements UnifiedConfigData {
+    private ConfigurationData data;
+
+    public ConfigurationDataUCD(ConfigurationData configurationData) {
+        data = configurationData;
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return data.getDefaultSection();
+    }
+
+    @Override
+    public int getOrdinal() {
+        String value = data.getDefaultSection().get(PropertySource.TAMAYA_ORDINAL);
+
+        return Integer.parseInt(value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatIT.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatIT.java b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatIT.java
new file mode 100644
index 0000000..3c3fee1
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatIT.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.modules.json;
+
+import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.spi.ServiceContext;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+
+/**
+ * Integration tests for {@link JSONFormat}.
+ */
+public class JSONFormatIT {
+    @Test
+    public void jsonFormatCanBeFoundViaServiceLoader() throws Exception {
+        List<ConfigurationFormat> formats = ServiceContext.getInstance()
+                                                          .getServices(ConfigurationFormat.class);
+
+        ConfigurationFormat format = formats.stream()
+                                            .filter(s -> s instanceof JSONFormat)
+                                            .findFirst().get();
+
+        assertThat(format, notNullValue());
+        assertThat(format, instanceOf(JSONFormat.class));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatTest.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatTest.java
index f5f2d96..b6473d8 100644
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatTest.java
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONFormatTest.java
@@ -19,14 +19,16 @@
 package org.apache.tamaya.modules.json;
 
 
+import org.apache.tamaya.format.ConfigurationData;
 import org.junit.Test;
 
+import java.io.InputStream;
 import java.net.URL;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 
-public class JSONFormatTest {
+public class JSONFormatTest extends CommonJSONTestCaseCollection {
     private JSONFormat format = new JSONFormat();
 
     @Test(expected = NullPointerException.class)
@@ -61,4 +63,13 @@ public class JSONFormatTest {
 
         assertThat(format.accepts(url), is(false));
     }
+
+    @Override
+    UnifiedConfigData getPropertiesFrom(URL source) throws Exception {
+        try (InputStream is = source.openStream()) {
+            ConfigurationData data = format.readConfiguration(source.toString(), is);
+
+            return new ConfigurationDataUCD(data);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
index e391f92..92bb123 100644
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
@@ -18,118 +18,16 @@
  */
 package org.apache.tamaya.modules.json;
 
-import org.apache.tamaya.ConfigException;
 import org.apache.tamaya.spi.PropertySource;
 import org.hamcrest.CoreMatchers;
-import org.hamcrest.Matchers;
 import org.junit.Test;
 
-import java.io.File;
-import java.net.URISyntaxException;
 import java.net.URL;
 
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
 
-public class JSONPropertySourceTest {
-
-    @Test(expected = ConfigException.class)
-    public void emptyJSONFileResultsInConfigException() throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/empty-file.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        source.getProperties();
-    }
-
-    @Test
-    public void canHandleEmptyJSONObject() throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/empty-object-config.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        assertThat(source.getProperties().keySet(), hasSize(0));
-    }
-
-    @Test
-    public void canReadFlatStringOnlyJSONConfigFile() throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-flat-string-only-config.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        assertThat(source.getProperties().keySet(), hasSize(3));
-
-        String keyA = source.get("a");
-        String keyB = source.get("b");
-        String keyC = source.get("c");
-
-        assertThat(keyA, notNullValue());
-        assertThat(keyA, equalTo("A"));
-        assertThat(keyB, notNullValue());
-        assertThat(keyB, is("B"));
-        assertThat(keyC, notNullValue());
-        assertThat(keyC, is("C"));
-    }
-
-    @Test
-    public void canReadNestedStringOnlyJSONConfigFile() throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-nested-string-only-config-1.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        assertThat(source.getProperties().keySet(), hasSize(5));
-
-        String keyB = source.get("b");
-        String keyDO = source.get("d.o");
-        String keyDP = source.get("d.p");
-
-        assertThat(keyB, notNullValue());
-        assertThat(keyB, equalTo("B"));
-        assertThat(keyDO, notNullValue());
-        assertThat(keyDO, equalTo("O"));
-        assertThat(keyDP, Matchers.notNullValue());
-        assertThat(keyDP, is("P"));
-    }
-
-    @Test
-    public void canReadNestedStringOnlyJSONConfigFileWithObjectInTheMiddle()
-            throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-nested-string-only-config-2.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        File configFile = new File(configURL.toURI());
-
-        JSONPropertySource source = new JSONPropertySource(configFile.toString(), 10);
-
-        assertThat(source.getProperties().keySet(), hasSize(4));
-
-        String keyA = source.get("a");
-        String keyDO = source.get("b.o");
-        String keyDP = source.get("b.p");
-        String keyC = source.get("c");
-
-        assertThat(keyA, notNullValue());
-        assertThat(keyA, is("A"));
-        assertThat(keyC, notNullValue());
-        assertThat(keyC, equalTo("C"));
-        assertThat(keyDO, notNullValue());
-        assertThat(keyDO, equalTo("O"));
-        assertThat(keyDP, notNullValue());
-        assertThat(keyDP, is("P"));
-    }
+public class JSONPropertySourceTest extends CommonJSONTestCaseCollection {
 
     @Test
     public void tamayaOrdinalKeywordIsNotPropagatedAsNormalProperty() throws Exception {
@@ -142,64 +40,10 @@ public class JSONPropertySourceTest {
         assertThat(source.get(PropertySource.TAMAYA_ORDINAL), nullValue());
     }
 
-    @Test
-    public void priorityInConfigFileOverwriteExplicitlyGivenPriority() throws URISyntaxException
{
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        assertThat(source.getOrdinal(), is(16784));
-    }
-
-    @Test
-    public void priorityInConfigFileIsReturnedPriority() throws URISyntaxException {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        File configFile = new File(configURL.toURI());
-
-        JSONPropertySource source = new JSONPropertySource(configFile.toString());
-
-        assertThat(source.getOrdinal(), is(16784));
-
-    }
-
-    @Test(expected = ConfigException.class)
-    public void canHandleIllegalJSONFileConsistingOfOneOpeningBracket() {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/only-opening-bracket.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        new JSONPropertySource(configURL).getProperties();
-    }
-
-    @Test(expected = ConfigException.class)
-    public void canHandleIllegalJSONFileWhichIsEmpty() {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/empty-file.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        new JSONPropertySource(configURL).getProperties();
-    }
-
-    @Test(expected = ConfigException.class)
-    public void canHandleIllegalJSONFileWhichConsistsOnlyOfAnArray() {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/array.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        new JSONPropertySource(configURL).getProperties();
-    }
-    @Test(expected = ConfigException.class)
-    public void canHandleIllegalJSONFileWhichContainsAnArray() {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/invalid/with-array.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
+    @Override
+    UnifiedConfigData getPropertiesFrom(URL source) throws Exception {
+        JSONPropertySource propertySource = new JSONPropertySource(source);
 
-        new JSONPropertySource(configURL).getProperties();
+        return new JSONPropertySourceUCD(propertySource);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceUCD.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceUCD.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceUCD.java
new file mode 100644
index 0000000..fef09a9
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceUCD.java
@@ -0,0 +1,39 @@
+/*
+ * 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.modules.json;
+
+import java.util.Map;
+
+public class JSONPropertySourceUCD implements UnifiedConfigData {
+    private JSONPropertySource propertySource;
+
+    public JSONPropertySourceUCD(JSONPropertySource source) {
+        propertySource = source;
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return propertySource.getProperties();
+    }
+
+    @Override
+    public int getOrdinal() {
+        return propertySource.getOrdinal();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a26f11b3/modules/json/src/test/java/org/apache/tamaya/modules/json/UnifiedConfigData.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/UnifiedConfigData.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/UnifiedConfigData.java
new file mode 100644
index 0000000..fca37d5
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/UnifiedConfigData.java
@@ -0,0 +1,32 @@
+/*
+ * 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.modules.json;
+
+import java.util.Map;
+
+public interface UnifiedConfigData {
+    Map<String, String> getProperties();
+
+    int getOrdinal();
+
+    default String get(String key) {
+        return getProperties().get(key);
+    }
+
+}


Mime
View raw message