You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/02/20 18:57:44 UTC
git commit: DELTASPIKE-95 tested order - as documented
Updated Branches:
refs/heads/master 53bbc13cf -> 1e2dd6712
DELTASPIKE-95 tested order - as documented
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/1e2dd671
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/1e2dd671
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/1e2dd671
Branch: refs/heads/master
Commit: 1e2dd6712241cdfad81786f10015cf2a7b96d723
Parents: 53bbc13
Author: gpetracek <gp...@apache.org>
Authored: Mon Feb 20 18:52:50 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Mon Feb 20 18:56:26 2012 +0100
----------------------------------------------------------------------
.../deltaspike/core/api/config/ConfigResolver.java | 50 ++++++---
.../test/api/config/ConfigResolverTest.java | 46 ++++++++
.../test/api/config/TestConfigSourceProvider.java | 89 +++++++++++++++
...deltaspike.core.spi.config.ConfigSourceProvider | 20 ++++
.../core/api/exclude/ExcludeIntegrationTest.java | 3 +
5 files changed, 191 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/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 3efb649..bc50cb4 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
@@ -19,6 +19,7 @@
package org.apache.deltaspike.core.api.config;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -58,7 +59,7 @@ public final class ConfigResolver
/**
* Resolve the property value by going through the list of configured {@link ConfigSource}s
* and use the one with the highest priority.
- *
+ *
* @param key the property key.
* @return the configured property value from the {@link ConfigSource} with the highest ordinal or
* null if there is no configured value for it.
@@ -66,13 +67,13 @@ public final class ConfigResolver
public static String getPropertyValue(String key)
{
ConfigSource[] appConfigSources = getConfigSources();
-
+
for (ConfigSource cs : appConfigSources)
{
String val = cs.getPropertyValue(key);
if (val != null)
{
- LOG.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.",
+ LOG.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.",
new Object[]{val, key, cs.getConfigName()});
return val;
}
@@ -80,8 +81,8 @@ public final class ConfigResolver
LOG.log(Level.FINER, "NO value found for key {0} in ConfigSource {1}.",
new Object[]{key, cs.getConfigName()});
}
-
- return null;
+
+ return null;
}
/**
@@ -95,9 +96,9 @@ public final class ConfigResolver
*/
public static List<String> getAllPropertyValues(String key)
{
- ConfigSource[] appConfigSources = getConfigSources();
+ List<ConfigSource> appConfigSources = sortAscending(Arrays.asList(getConfigSources()));
List<String> allPropValues = new ArrayList<String>();
-
+
for (ConfigSource cs : appConfigSources)
{
String val = cs.getPropertyValue(key);
@@ -106,30 +107,29 @@ public final class ConfigResolver
allPropValues.add(val);
}
}
-
+
return allPropValues;
}
-
-
+
private static synchronized ConfigSource[] getConfigSources()
{
ClassLoader currentCl = ClassUtils.getClassLoader(null);
-
+
ConfigSource[] appConfigSources = configSources.get(currentCl);
-
+
if (appConfigSources == null)
{
appConfigSources = sortDescending(resolveConfigSources());
-
- if (LOG.isLoggable(Level.FINE))
+
+ if (LOG.isLoggable(Level.FINE))
{
for (ConfigSource cs : appConfigSources)
{
- LOG.log(Level.FINE, "Adding ordinal {0} ConfigSource {1}",
+ LOG.log(Level.FINE, "Adding ordinal {0} ConfigSource {1}",
new Object[]{cs.getOrdinal(), cs.getConfigName()});
}
}
-
+
configSources.put(currentCl, appConfigSources);
}
@@ -161,9 +161,25 @@ public final class ConfigResolver
@Override
public int compare(ConfigSource configSource1, ConfigSource configSource2)
{
- return (configSource1.getOrdinal() > configSource2.getOrdinal()) ? -1 : 1 ;
+ return (configSource1.getOrdinal() > configSource2.getOrdinal()) ? -1 : 1;
}
});
return configSources.toArray(new ConfigSource[configSources.size()]);
}
+
+ private static List<ConfigSource> sortAscending(List<ConfigSource> configSources)
+ {
+ Collections.sort(configSources, new Comparator<ConfigSource>()
+ {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare(ConfigSource configSource1, ConfigSource configSource2)
+ {
+ return (configSource1.getOrdinal() > configSource2.getOrdinal()) ? 1 : -1;
+ }
+ });
+ return configSources;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/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
new file mode 100644
index 0000000..f44ba47
--- /dev/null
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deltaspike.test.api.config;
+
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public class ConfigResolverTest
+{
+ @Test
+ public void testOverruledValue()
+ {
+ String result = ConfigResolver.getPropertyValue("test");
+
+ Assert.assertEquals("test2", result);
+ }
+
+ @Test
+ public void testOrderOfAllValues()
+ {
+ List<String> result = ConfigResolver.getAllPropertyValues("test");
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals("test1", result.get(0));
+ Assert.assertEquals("test2", result.get(1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSourceProvider.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSourceProvider.java
new file mode 100644
index 0000000..a73fe17
--- /dev/null
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSourceProvider.java
@@ -0,0 +1,89 @@
+/*
+ * 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.deltaspike.test.api.config;
+
+import org.apache.deltaspike.core.spi.config.ConfigSource;
+import org.apache.deltaspike.core.spi.config.ConfigSourceProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ConfigSourceProvider for basic unit-test
+ */
+public class TestConfigSourceProvider implements ConfigSourceProvider
+{
+ @Override
+ public List<ConfigSource> getConfigSources()
+ {
+ return new ArrayList<ConfigSource>()
+ {
+ {
+ add(new ConfigSource()
+ {
+ @Override
+ public int getOrdinal()
+ {
+ return 1;
+ }
+
+ @Override
+ public String getPropertyValue(String key)
+ {
+ if ("test".equals(key))
+ {
+ return "test1";
+ }
+ return null;
+ }
+
+ @Override
+ public String getConfigName()
+ {
+ return TestConfigSourceProvider.class.getName() + "-1";
+ }
+ });
+ add(new ConfigSource()
+ {
+ @Override
+ public int getOrdinal()
+ {
+ return 2;
+ }
+
+ @Override
+ public String getPropertyValue(String key)
+ {
+ if ("test".equals(key))
+ {
+ return "test2";
+ }
+ return null;
+ }
+
+ @Override
+ public String getConfigName()
+ {
+ return TestConfigSourceProvider.class.getName() + "-2";
+ }
+ });
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/deltaspike/core/api/src/test/resources/.keepfolder
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/resources/.keepfolder b/deltaspike/core/api/src/test/resources/.keepfolder
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSourceProvider
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSourceProvider b/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSourceProvider
new file mode 100644
index 0000000..8c86732
--- /dev/null
+++ b/deltaspike/core/api/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSourceProvider
@@ -0,0 +1,20 @@
+#####################################################################################
+# 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.
+#####################################################################################
+
+org.apache.deltaspike.test.api.config.TestConfigSourceProvider
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/1e2dd671/deltaspike/core/integration-test/src/test/java/org/apache/deltaspike/integration/core/api/exclude/ExcludeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/integration-test/src/test/java/org/apache/deltaspike/integration/core/api/exclude/ExcludeIntegrationTest.java b/deltaspike/core/integration-test/src/test/java/org/apache/deltaspike/integration/core/api/exclude/ExcludeIntegrationTest.java
index 99ca141..e008e25 100644
--- a/deltaspike/core/integration-test/src/test/java/org/apache/deltaspike/integration/core/api/exclude/ExcludeIntegrationTest.java
+++ b/deltaspike/core/integration-test/src/test/java/org/apache/deltaspike/integration/core/api/exclude/ExcludeIntegrationTest.java
@@ -23,6 +23,7 @@ import org.apache.deltaspike.core.api.projectstage.ProjectStage;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.apache.deltaspike.core.util.ProjectStageProducer;
import org.apache.deltaspike.integration.core.api.projectstage.IntegrationTestProjectStageProducer;
+import org.apache.deltaspike.test.category.WebProfileCategory;
import org.apache.deltaspike.test.core.api.exclude.AlwaysActiveBean;
import org.apache.deltaspike.test.core.api.exclude.CustomExpressionBasedBean;
import org.apache.deltaspike.test.core.api.exclude.CustomExpressionBasedNoBean;
@@ -38,6 +39,7 @@ import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import java.net.URL;
@@ -46,6 +48,7 @@ import java.net.URL;
* Integration tests for {@link org.apache.deltaspike.core.api.exclude.Exclude}
*/
@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
public class ExcludeIntegrationTest
{
/**