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/03/24 22:20:27 UTC

[10/16] incubator-tamaya git commit: Fixed bugs.

Fixed bugs.


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

Branch: refs/heads/master
Commit: 312010acbf112b214822169d562004879c1cd268
Parents: 54bf732
Author: anatole <an...@apache.org>
Authored: Tue Mar 24 18:04:51 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 24 18:04:51 2015 +0100

----------------------------------------------------------------------
 .../core/internal/PropertyConverterManager.java | 32 ++++-----
 .../propertysource/SimplePropertySource.java    | 19 +----
 .../propertysource/SystemPropertySource.java    | 18 ++---
 .../apache/tamaya/core/ConfigurationTest.java   |  2 +
 .../core/internal/PropetiesFileLoaderTest.java  | 75 --------------------
 .../PropertiesFilePropertySourceTest.java       | 14 ++--
 .../SystemPropertySourceTest.java               |  8 +--
 .../META-INF/javaconfiguration.properties       | 22 ++++++
 .../test/resources/javaconfiguration.properties | 22 ------
 .../test/resources/overrideOrdinal.properties   |  2 +-
 .../core/src/test/resources/testfile.properties |  2 +-
 java7/core/src/test/resources/x34.properties    | 19 +++++
 12 files changed, 76 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/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 c93e84d..fa7d0d4 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
@@ -185,52 +185,52 @@ public class PropertyConverterManager {
     private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
         Type parameterType = targetType.getType();
         if(parameterType == int.class){
-            return TypeLiteral.of(Integer.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
         }
         if(parameterType == short.class){
-            return TypeLiteral.of(Short.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
         }
         if(parameterType == byte.class){
-            return TypeLiteral.of(Byte.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
         }
         if(parameterType == long.class){
-            return TypeLiteral.of(Long.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
         }
         if(parameterType == boolean.class){
-            return TypeLiteral.of(Boolean.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
         }
         if(parameterType == char.class){
-            return TypeLiteral.of(Character.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
         }
         if(parameterType == float.class){
-            return TypeLiteral.of(Float.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
         }
         if(parameterType == double.class){
-            return TypeLiteral.of(Double.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
         }
         if(parameterType == int[].class){
-            return TypeLiteral.of(Integer[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
         }
         if(parameterType == short[].class){
-            return TypeLiteral.of(Short[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
         }
         if(parameterType == byte[].class){
-            return TypeLiteral.of(Byte[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
         }
         if(parameterType == long[].class){
-            return TypeLiteral.of(Long[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
         }
         if(parameterType == boolean.class){
-            return TypeLiteral.of(Boolean.class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
         }
         if(parameterType == char[].class){
-            return TypeLiteral.of(Character[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
         }
         if(parameterType == float[].class){
-            return TypeLiteral.of(Float[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
         }
         if(parameterType == double[].class){
-            return TypeLiteral.of(Double[].class);
+            return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
index 128cc52..8129189 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
@@ -75,30 +75,15 @@ public class SimplePropertySource extends BasePropertySource{
     }
 
     @Override
-    public int getOrdinal() {
-        return 0;
-    }
-
-    @Override
     public String getName() {
         return name;
     }
 
     @Override
-    public String get(String key) {
-        return null;
-    }
-
-    @Override
     public Map<String, String> getProperties() {
         return this.properties;
     }
 
-    @Override
-    public boolean isScannable() {
-        return false;
-    }
-
     /**
      * loads the Properties from the given URL
      *
@@ -115,8 +100,8 @@ public class SimplePropertySource extends BasePropertySource{
             if (stream != null) {
                 props.load(stream);
             }
-            for(Map.Entry<Object,Object> en:props.entrySet()){
-                properties.put(en.getKey().toString(), en.getValue().toString());
+            for(String key:props.stringPropertyNames()){
+                 properties.put(key, props.getProperty(key));
             }
         } catch (IOException e) {
             throw new ConfigException("Error loading properties " + propertiesFile, e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
index 09f48bd..f75e1eb 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 public class SystemPropertySource implements PropertySource {
 
     /**
-     * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertiesPropertySource}
+     * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
      */
     public static final int DEFAULT_ORDINAL = 1000;
 
@@ -54,8 +54,8 @@ public class SystemPropertySource implements PropertySource {
     private Map<String, String> loadProperties() {
         Map<String,String> props = new HashMap<>();
         Properties sysProps = System.getProperties();
-        for(Map.Entry<Object,Object> en: sysProps.entrySet()) {
-            props.put(en.toString(), en.toString());
+        for(String name: sysProps.stringPropertyNames()) {
+            props.put(name,sysProps.getProperty(name));
         }
         return props;
     }
@@ -78,18 +78,12 @@ public class SystemPropertySource implements PropertySource {
     @Override
     public Map<String, String> getProperties() {
         // only need to reload and fill our map if something has changed
-        // synchonization was removed, Instance was marked as volatile. In the worst case it
+        // synchronization was removed, Instance was marked as volatile. In the worst case it
         // is reloaded twice, but the values will be the same.
         if (previousHash != System.getProperties().hashCode()) {
-            Properties systemProperties = System.getProperties();
-            Map<String, String> properties = new HashMap<>();
-
-            for (String propertyName : systemProperties.stringPropertyNames()) {
-                properties.put(propertyName, System.getProperty(propertyName));
-            }
-
+            Map<String, String> properties = loadProperties();
             this.cachedProperties = Collections.unmodifiableMap(properties);
-            previousHash = systemProperties.hashCode();
+            previousHash = System.getProperties().hashCode();
         }
         return this.cachedProperties;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 0eb2181..f6012e7 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 /**
@@ -66,4 +67,5 @@ public class ConfigurationTest {
             System.out.println("   " + entry.getKey()+" = " + entry.getValue());
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
deleted file mode 100644
index c125641..0000000
--- a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
+++ /dev/null
@@ -1,75 +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.internal;
-
-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/312010ac/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
index 9fef3be..8527881 100644
--- 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
@@ -21,20 +21,14 @@ 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"));
-    }
+    private SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
+            .getContextClassLoader().getResource("testfile.properties"));
+    private SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
+            Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
 
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/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
index 2eba79e..0b26ff4 100644
--- 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
@@ -48,7 +48,7 @@ public class SystemPropertySourceTest {
 
     @Test
     public void testGetName() throws Exception {
-        Assert.assertEquals("system-properties", new SystemPropertySource().getName());
+        Assert.assertEquals("system-properties", testPropertySource.getName());
     }
 
     @Test
@@ -56,11 +56,9 @@ public class SystemPropertySourceTest {
         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.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
+                SystemPropertySource.class.getSimpleName(), property);
         Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
-
-
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/javaconfiguration.properties b/java7/core/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..33beabb
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/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

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/javaconfiguration.properties b/java7/core/src/test/resources/javaconfiguration.properties
deleted file mode 100644
index 33beabb..0000000
--- a/java7/core/src/test/resources/javaconfiguration.properties
+++ /dev/null
@@ -1,22 +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.
-
-confkey1=javaconf-value1
-confkey2=javaconf-value2
-confkey3=javaconf-value3
-confkey4=javaconf-value4
-confkey5=javaconf-value5

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/overrideOrdinal.properties b/java7/core/src/test/resources/overrideOrdinal.properties
index 5384d91..96935a8 100644
--- a/java7/core/src/test/resources/overrideOrdinal.properties
+++ b/java7/core/src/test/resources/overrideOrdinal.properties
@@ -22,4 +22,4 @@ mykey1=myval1
 mykey2=myval2
 mykey3=myval3
 mykey4=myval4
-mykey5=myval5
+mykey5=myval5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/testfile.properties b/java7/core/src/test/resources/testfile.properties
index 4dc3b91..abd7ee8 100644
--- a/java7/core/src/test/resources/testfile.properties
+++ b/java7/core/src/test/resources/testfile.properties
@@ -19,4 +19,4 @@ key1=val1
 key2=val2
 key3=val3
 key4=val4
-key5=val5
+key5=val5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/312010ac/java7/core/src/test/resources/x34.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/x34.properties b/java7/core/src/test/resources/x34.properties
new file mode 100644
index 0000000..f2c4a0a
--- /dev/null
+++ b/java7/core/src/test/resources/x34.properties
@@ -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 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.
+
+x34=x34
+x34.a.b.c=C