deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-1139 also fix a NPE if the configured value is not set and logValues is enabled
Date Fri, 13 May 2016 14:04:08 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 07f519952 -> e60776cc7


DELTASPIKE-1139 also fix a NPE if the configured value is not set and logValues is enabled


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

Branch: refs/heads/master
Commit: e60776cc76c12e10b214db5950fcbf0d80f883e3
Parents: 07f5199
Author: Mark Struberg <struberg@apache.org>
Authored: Fri May 13 16:03:13 2016 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Fri May 13 16:03:13 2016 +0200

----------------------------------------------------------------------
 .../core/api/config/ConfigResolver.java         |  5 +-
 .../test/api/config/ConfigResolverTest.java     | 42 ++++++++++++++-
 ...ache.deltaspike.core.spi.config.ConfigSource | 57 --------------------
 3 files changed, 44 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e60776cc/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index 98de4f1..a2b8ed6 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -900,15 +900,16 @@ public final class ConfigResolver
 
             value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
 
-            if (logChanges && (value != null && lastValue == null || !value.equals(lastValue))
)
+            if (logChanges && (value != null && !value.equals(lastValue)
|| (value == null && lastValue != null)) )
             {
                 LOG.log(Level.INFO, "New value {0} for key {1}.",
                     new Object[]{filterConfigValueForLog(keyOriginal, valueStr), keyOriginal});
             }
 
+            lastValue = value;
+
             if (cacheTimeMs > 0)
             {
-                lastValue = value;
                 reloadAfter = now + cacheTimeMs;
             }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e60776cc/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
index b2745f7..6afdce7 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.test.api.config;
 import org.apache.deltaspike.core.api.config.ConfigResolver;
 import org.apache.deltaspike.core.api.projectstage.ProjectStage;
 import org.apache.deltaspike.core.spi.config.ConfigFilter;
+import org.apache.deltaspike.core.spi.config.ConfigSource;
 import org.apache.deltaspike.core.util.ProjectStageProducer;
 import org.junit.Assert;
 import org.junit.Before;
@@ -160,8 +161,8 @@ public class ConfigResolverTest
             String url = ConfigResolver.getPropertyValue("deltaspike.test.nonexisting.variable",
true);
             Assert.assertEquals("${does.not.exist}/someservice/myendpoint", url);
         }
-
     }
+
     @Test
     public void testConfigVariableRecursiveDeclaration()
     {
@@ -173,6 +174,44 @@ public class ConfigResolverTest
         Assert.assertEquals("pre-crazy-post/ohgosh/crazy", tr.getValue());
     }
 
+    @Test
+    public void testTypedResolver_NonExistingValue()
+    {
+        final String key = "non.existing.key";
+
+        ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve(key)
+            .logChanges(true);
+
+        Assert.assertNull(resolver.getValue());
+
+        setTestConfigSourceValue(key, "somevalue");
+        Assert.assertEquals("somevalue", resolver.getValue());
+
+        setTestConfigSourceValue(key, null);
+        Assert.assertNull(resolver.getValue());
+    }
+
+    private void setTestConfigSourceValue(String key, String value)
+    {
+        ConfigSource[] configSources = ConfigResolver.getConfigSources();
+        for (ConfigSource configSource : configSources)
+        {
+            if (configSource instanceof TestConfigSource)
+            {
+                if (value == null)
+                {
+                    configSource.getProperties().remove(key);
+                }
+                else
+                {
+                    configSource.getProperties().put(key, value);
+                }
+
+                break;
+            }
+        }
+    }
+
     public static class TestConfigFilter implements ConfigFilter
     {
         @Override
@@ -195,4 +234,5 @@ public class ConfigResolverTest
             return value;
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e60776cc/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
b/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
index 441c504..84d5875 100644
--- a/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
+++ b/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
@@ -1,60 +1,3 @@
-#
-# 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.
-#
-
-#
-# 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.
-#
-
-#
-# 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.
-#
-
 #####################################################################################
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements. See the NOTICE file


Mime
View raw message