You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2013/06/07 12:08:36 UTC

[1/3] git commit: general configuration section should go before executions

Updated Branches:
  refs/heads/master 4ed338e7c -> 4b636c8ce


general configuration section should go before executions


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

Branch: refs/heads/master
Commit: 4b636c8cebd3334d08ee8d8f0fa6b97a001fa217
Parents: 7631ac6
Author: Mark Struberg <st...@apache.org>
Authored: Fri Jun 7 12:06:02 2013 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Jun 7 12:06:30 2013 +0200

----------------------------------------------------------------------
 deltaspike/parent/pom.xml |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4b636c8c/deltaspike/parent/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/parent/pom.xml b/deltaspike/parent/pom.xml
index fef94b4..fa04d09 100644
--- a/deltaspike/parent/pom.xml
+++ b/deltaspike/parent/pom.xml
@@ -679,6 +679,11 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-checkstyle-plugin</artifactId>
                 <version>${maven.checkstyle.plugin.version}</version>
+                <configuration>
+                    <configLocation>deltaspike/default-checks.xml</configLocation>
+                    <headerLocation>deltaspike/asf-header.txt</headerLocation>
+                    <consoleOutput>true</consoleOutput>
+                </configuration>
                 <executions>
                     <execution>
                         <id>verify-style</id>
@@ -688,11 +693,6 @@
                         </goals>
                     </execution>
                 </executions>
-                <configuration>
-                    <configLocation>deltaspike/default-checks.xml</configLocation>
-                    <headerLocation>deltaspike/asf-header.txt</headerLocation>
-                    <consoleOutput>true</consoleOutput>
-                </configuration>
                 <dependencies>
                     <dependency>
                         <groupId>org.apache.deltaspike</groupId>


[3/3] git commit: DELTASPIKE-378 more unit tests for geProjectStageAwarePropertyValue

Posted by st...@apache.org.
DELTASPIKE-378 more unit tests for geProjectStageAwarePropertyValue


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

Branch: refs/heads/master
Commit: 96d9ec7160efc69388bceb746898ea47311dd5f8
Parents: 4ed338e
Author: Mark Struberg <st...@apache.org>
Authored: Fri Jun 7 08:53:34 2013 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Jun 7 12:06:30 2013 +0200

----------------------------------------------------------------------
 .../test/api/config/ConfigResolverTest.java        |    8 ++++++++
 .../test/api/config/TestConfigSource.java          |    8 ++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/96d9ec71/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 70c00e8..91ebb22 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
@@ -58,6 +58,14 @@ public class ConfigResolverTest
     {
         ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
         Assert.assertNull(ConfigResolver.getProjectStageAwarePropertyValue("notexisting", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey", null));
         Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey2", null));
+        Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3", null));
+        Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3", null));
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/96d9ec71/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
index ed9dc86..e9e066f 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
@@ -38,8 +38,16 @@ public class TestConfigSource implements ConfigSource
 
     public TestConfigSource()
     {
+        // a ProjectStage overloaded value
         props.put("testkey", "testvalue");
         props.put("testkey.UnitTest", "unittestvalue");
+
+        // a value without any overloading
+        props.put("testkey2", "testvalue");
+
+        // a value which got ProjectStage overloaded to an empty value
+        props.put("testkey3", "testvalue");
+        props.put("testkey3.UnitTest", "");
     }
 
     @Override


[2/3] git commit: DELTASPIKE-378 add getPropertyAwarePropertyValue

Posted by st...@apache.org.
DELTASPIKE-378 add getPropertyAwarePropertyValue

feel free to propose a better name if you find one :)


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

Branch: refs/heads/master
Commit: 7631ac6f526edf472d1383f7b82171c7ac29f0fb
Parents: 96d9ec7
Author: Mark Struberg <st...@apache.org>
Authored: Fri Jun 7 10:00:44 2013 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Jun 7 12:06:30 2013 +0200

----------------------------------------------------------------------
 .../deltaspike/core/api/config/ConfigResolver.java |   98 ++++++++++++++-
 .../test/api/config/ConfigResolverTest.java        |   34 +++++-
 .../test/api/config/TestConfigSource.java          |   14 ++
 3 files changed, 142 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7631ac6f/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 05cbc59..6b3ada2 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
@@ -162,18 +162,110 @@ public final class ConfigResolver
      * <p><b>Attention</b> This method must only be used after all ConfigSources
      * got registered and it also must not be used to determine the ProjectStage itself.</p>
      * @param key
+     * @return the configured value or if non found the defaultValue
+     *
+     */
+    public static String getProjectStageAwarePropertyValue(String key)
+    {
+        ProjectStage ps = getProjectStage();
+
+        String value = getPropertyValue(key + '.' + ps);
+        if (value == null)
+        {
+            value = getPropertyValue(key);
+        }
+
+        return value;
+    }
+    /**
+     * {@link #getProjectStageAwarePropertyValue(String)} which returns the defaultValue
+     * if the property is <code>null</code> or empty.
+     * @param key
      * @param defaultValue
      * @return the configured value or if non found the defaultValue
      *
      */
     public static String getProjectStageAwarePropertyValue(String key, String defaultValue)
     {
-        ProjectStage ps = getProjectStage();
+        String value = getProjectStageAwarePropertyValue(key);
+
+        if (value == null || value.length() == 0)
+        {
+            value = defaultValue;
+        }
+
+        return value;
+    }
+
+    /**
+     * <p>Search for the configured value in all {@link ConfigSource}s and take the
+     * current {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}
+     * and the value configured for the given property into account.</p>
+     *
+     * <p>The first step is to resolve the value of the given property. This will
+     * take the current ProjectStage into account. E.g. given the property is 'dbvendor'
+     * and the ProjectStage is 'UnitTest', the first lookup is
+     * <ul><li>'dbvendor.UnitTest'</li></ul>.
+     * If this value is not found then we will do a 2nd lookup for
+     * <ul><li>'dbvendor'</li></ul></p>
+     *
+     * <p>If a value was found for the given property (e.g. dbvendor = 'mysql'
+     * then we will use this value to lookup in the following order until we
+     * found a non-null value. If there was no value found for the property
+     * we will only do the key+ProjectStage and key lookup.
+     * In the following sample 'dataSource' is used as key parameter:
+     *
+     * <ul>
+     *      <li>'datasource.mysql.UnitTest'</li>
+     *      <li>'datasource.mysql'</li>
+     *      <li>'datasource.UnitTest'</li>
+     *      <li>'datasource'</li>
+     * </ul>
+     * </p>
+     *
+     *
+     * <p><b>Attention</b> This method must only be used after all ConfigSources
+     * got registered and it also must not be used to determine the ProjectStage itself.</p>
+     * @param key
+     * @param property the property to look up first
+     * @return the configured value or if non found the defaultValue
+     *
+     */
+    public static String getPropertyAwarePropertyValue(String key, String property)
+    {
+        String propertyValue = getProjectStageAwarePropertyValue(property);
+
+        String value = null;
+
+        if (propertyValue != null && propertyValue.length() > 0)
+        {
+            value = getProjectStageAwarePropertyValue(key + '.' + propertyValue);
+        }
 
-        String value = getPropertyValue(key + '.' + ps, defaultValue);
         if (value == null)
         {
-            value = getPropertyValue(key, defaultValue);
+            value = getProjectStageAwarePropertyValue(key);
+        }
+
+        return value;
+    }
+
+    /*
+     * <p><b>Attention</b> This method must only be used after all ConfigSources
+     * got registered and it also must not be used to determine the ProjectStage itself.</p>
+     * @param key
+     * @param property the property to look up first
+     * @param defaultValue
+     * @return the configured value or if non found the defaultValue
+     *
+    */
+    public static String getPropertyAwarePropertyValue(String key, String property, String defaultValue)
+    {
+        String value = getPropertyAwarePropertyValue(key, property);
+
+        if (value == null || value.length() == 0)
+        {
+            value = defaultValue;
         }
 
         return value;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7631ac6f/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 91ebb22..d30e7de 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
@@ -28,6 +28,7 @@ import java.util.List;
 
 public class ConfigResolverTest
 {
+    private static final String DEFAULT_VALUE = "defaultValue";
     @Test
     public void testOverruledValue()
     {
@@ -60,12 +61,43 @@ public class ConfigResolverTest
         Assert.assertNull(ConfigResolver.getProjectStageAwarePropertyValue("notexisting", null));
 
         Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey", null));
+        Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey"));
         Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey", null));
 
         Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey2", null));
+        Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2"));
         Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2", null));
 
         Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3", null));
-        Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3", null));
+        Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3"));
+        Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("testkey3", DEFAULT_VALUE));
+    }
+
+    @Test
+    public void testGetPropertyAwarePropertyValue() {
+        ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
+
+        Assert.assertNull(ConfigResolver.getPropertyAwarePropertyValue("notexisting", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey", null));
+        Assert.assertEquals("unittestvalue", ConfigResolver.getPropertyAwarePropertyValue("testkey", "dbvendor"));
+        Assert.assertEquals("unittestvalue", ConfigResolver.getPropertyAwarePropertyValue("testkey", "dbvendor", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey2", null));
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyAwarePropertyValue("testkey2", "dbvendor"));
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyAwarePropertyValue("testkey2", "dbvendor", null));
+
+        Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3", null));
+        Assert.assertEquals("", ConfigResolver.getPropertyAwarePropertyValue("testkey3", "dbvendor"));
+        Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getPropertyAwarePropertyValue("testkey3", "dbvendor", DEFAULT_VALUE));
+
+        Assert.assertEquals("TestDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendor"));
+        Assert.assertEquals("PostgreDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendor2"));
+        Assert.assertEquals("DefaultDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendorX"));
+
+        Assert.assertEquals("TestDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendor", null));
+        Assert.assertEquals("PostgreDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendor2", null));
+        Assert.assertEquals("DefaultDataSource", ConfigResolver.getPropertyAwarePropertyValue("dataSource", "dbvendorX", null));
+        Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getPropertyAwarePropertyValue("dataSourceX", "dbvendorX", DEFAULT_VALUE));
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7631ac6f/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
index e9e066f..d0f2c93 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
@@ -48,6 +48,20 @@ public class TestConfigSource implements ConfigSource
         // a value which got ProjectStage overloaded to an empty value
         props.put("testkey3", "testvalue");
         props.put("testkey3.UnitTest", "");
+
+        // now for the PropertyAware tests
+        props.put("dbvendor.UnitTest", "mysql");
+        props.put("dbvendor", "postgresql");
+
+        props.put("dataSource.mysql.Production", "java:/comp/env/MyDs");
+        props.put("dataSource.mysql.UnitTest", "TestDataSource");
+        props.put("dataSource.postgresql", "PostgreDataSource");
+        props.put("dataSource", "DefaultDataSource");
+
+        // another one
+        props.put("dbvendor2.Production", "mysql");
+        props.put("dbvendor2", "postgresql");
+
     }
 
     @Override