deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsme...@apache.org
Subject [1/2] deltaspike git commit: DELTASPIKE-892 type-safe static config * Type-safe fluent API for ConfigResolver * properties are easily typed * added Class and Double to types * new optional strict mode for resolution -- only falls back to default, not to
Date Mon, 04 May 2015 23:47:14 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 320ae6e1f -> 25b2b8cc0


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerBaseConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerBaseConfig.java
b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerBaseConfig.java
index 63f33e1..c406ae9 100644
--- a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerBaseConfig.java
+++ b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerBaseConfig.java
@@ -18,35 +18,53 @@
  */
 package org.apache.deltaspike.scheduler.impl;
 
-import org.apache.deltaspike.core.api.config.base.TypedConfig;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
 
 //keep it in the impl. module for now, because it's mainly quartz specific config
 public interface SchedulerBaseConfig
 {
     interface JobCustomization
     {
+        String JOB_CLASS_NAME_KEY = "deltaspike.scheduler.job-class";
+
         //don't type it to class to keep quartz optional
-        TypedConfig<String> DEFAULT_JOB_FACTORY_CLASS_NAME =
-            new TypedConfig<String>("deltaspike.scheduler.DefaultJobFactory",
-                "org.quartz.simpl.PropertySettingJobFactory");
+        String DEFAULT_JOB_FACTORY_CLASS_NAME = ConfigResolver.resolve("deltaspike.scheduler.DefaultJobFactory")
+                .withCurrentProjectStage(true)
+                .withDefault("org.quartz.simpl.PropertySettingJobFactory")
+                .getValue();
 
         //don't type it to class to keep quartz optional
-        TypedConfig<String> JOB_CLASS_NAME =
-            new TypedConfig<String>("deltaspike.scheduler.job-class", "org.quartz.Job");
+        String JOB_CLASS_NAME = ConfigResolver.resolve(JOB_CLASS_NAME_KEY)
+                .withCurrentProjectStage(true)
+                .withDefault("org.quartz.Job")
+                .getValue();
     }
 
-    TypedConfig<String> SCHEDULER_CONFIG_FILE =
-        new TypedConfig<String>("deltaspike.scheduler.quartz_config-file", "quartz");
+    String SCHEDULER_CONFIG_FILE = ConfigResolver.resolve("deltaspike.scheduler.quartz_config-file")
+            .withCurrentProjectStage(true)
+            .withDefault("quartz")
+            .getValue();
 
     interface Lifecycle
     {
-        TypedConfig<Boolean> START_SCOPES_PER_JOB =
-                new TypedConfig<Boolean>("deltaspike.scheduler.start_scopes_for_jobs",
Boolean.TRUE);
+        String START_SCOPES_PER_JOB_KEY = "deltaspike.scheduler.start_scopes_for_jobs";
+
+        Boolean START_SCOPES_PER_JOB = ConfigResolver.resolve(START_SCOPES_PER_JOB_KEY)
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.TRUE)
+                .getValue();
 
-        TypedConfig<Boolean> FORCE_STOP =
-                new TypedConfig<Boolean>("deltaspike.scheduler.force_stop", Boolean.TRUE);
+        Boolean FORCE_STOP = ConfigResolver.resolve("deltaspike.scheduler.force_stop")
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.TRUE)
+                .getValue();
 
-        TypedConfig<Integer> DELAYED_START_IN_SECONDS =
-                new TypedConfig<Integer>("deltaspike.scheduler.delayed_start_in_seconds",
1);
+        Integer DELAYED_START_IN_SECONDS = ConfigResolver.resolve("deltaspike.scheduler.delayed_start_in_seconds")
+                .as(Integer.class)
+                .withCurrentProjectStage(true)
+                .withDefault(1)
+                .getValue();
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerExtension.java
b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerExtension.java
index 05ea9c2..ea113bc 100644
--- a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerExtension.java
+++ b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/SchedulerExtension.java
@@ -59,7 +59,7 @@ public class SchedulerExtension implements Extension, Deactivatable
 
         if (this.isActivated)
         {
-            String jobClassName = SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME.getValue();
+            String jobClassName = SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME;
 
             this.jobClass = ClassUtils.tryToLoadClassForName(jobClassName);
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomConfigSource.java
b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomConfigSource.java
index aa6947c..534a959 100644
--- a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomConfigSource.java
+++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomConfigSource.java
@@ -29,7 +29,7 @@ public class CustomConfigSource implements ConfigSource
 {
     private Map<String, String> config = new HashMap<String, String>()
     {{
-        put(SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME.getKey(), CustomJob.class.getName());
+        put(SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME_KEY, CustomJob.class.getName());
         put(ClassDeactivator.class.getName(), QuartzDeactivator.class.getName());
     }};
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java
b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java
index 4129b6b..cec57a1 100644
--- a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java
+++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java
@@ -29,8 +29,8 @@ public class CustomDeactivatedConfigSource implements ConfigSource
 {
     private Map<String, String> config = new HashMap<String, String>()
     {{
-            put(SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME.getKey(), CustomJob.class.getName());
-            put(SchedulerBaseConfig.Lifecycle.START_SCOPES_PER_JOB.getKey(), Boolean.FALSE.toString());
+            put(SchedulerBaseConfig.JobCustomization.JOB_CLASS_NAME_KEY, CustomJob.class.getName());
+            put(SchedulerBaseConfig.Lifecycle.START_SCOPES_PER_JOB_KEY, Boolean.FALSE.toString());
             put(ClassDeactivator.class.getName(), QuartzDeactivator.class.getName());
     }};
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
index 09114b7..4ef1deb 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
@@ -82,7 +82,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 
     static
     {
-        USE_TEST_CLASS_AS_CDI_BEAN = TestBaseConfig.ContainerIntegration.USE_TEST_CLASS_AS_CDI_BEAN.getValue();
+        USE_TEST_CLASS_AS_CDI_BEAN = TestBaseConfig.ContainerIntegration.USE_TEST_CLASS_AS_CDI_BEAN;
     }
 
     private static ThreadLocal<Boolean> automaticScopeHandlingActive = new ThreadLocal<Boolean>();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
index 1c849e0..e24dda6 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
@@ -63,7 +63,7 @@ public class CdiTestSuiteRunner extends Suite
 
     static
     {
-        STOP_CONTAINER = TestBaseConfig.ContainerIntegration.STOP_CONTAINER.getValue();
+        STOP_CONTAINER = TestBaseConfig.ContainerIntegration.STOP_CONTAINER;
     }
 
     public CdiTestSuiteRunner(Class<?> klass, RunnerBuilder builder) throws InitializationError

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
index 416f940..217649d 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
@@ -18,27 +18,42 @@
  */
 package org.apache.deltaspike.testcontrol.api.junit;
 
-import org.apache.deltaspike.core.api.config.base.TypedConfig;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
 
 public interface TestBaseConfig
 {
     interface ContainerIntegration
     {
         //default is false to improve the compatibility with @Before and @After
-        TypedConfig<Boolean> USE_TEST_CLASS_AS_CDI_BEAN =
-            new TypedConfig<Boolean>("deltaspike.testcontrol.use_test_class_as_cdi_bean",
Boolean.FALSE);
+        Boolean USE_TEST_CLASS_AS_CDI_BEAN = ConfigResolver.resolve("deltaspike.testcontrol.use_test_class_as_cdi_bean")
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.FALSE)
+                .getValue();
 
-        TypedConfig<Boolean> STOP_CONTAINER =
-            new TypedConfig<Boolean>("deltaspike.testcontrol.stop_container", Boolean.TRUE);
+        Boolean STOP_CONTAINER = ConfigResolver.resolve("deltaspike.testcontrol.stop_container")
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.TRUE)
+                .getValue();
     }
 
     interface MockIntegration
     {
-        TypedConfig<Boolean> ALLOW_MOCKED_BEANS =
-                new TypedConfig<Boolean>("deltaspike.testcontrol.mock-support.allow_mocked_beans",
Boolean.FALSE);
+        String ALLOW_MOCKED_BEANS_KEY = "deltaspike.testcontrol.mock-support.allow_mocked_beans";
+        String ALLOW_MOCKED_PRODUCERS_KEY = "deltaspike.testcontrol.mock-support.allow_mocked_producers";
 
-        TypedConfig<Boolean> ALLOW_MOCKED_PRODUCERS =
-                new TypedConfig<Boolean>("deltaspike.testcontrol.mock-support.allow_mocked_producers",
Boolean.FALSE);
+        Boolean ALLOW_MOCKED_BEANS = ConfigResolver.resolve(ALLOW_MOCKED_BEANS_KEY)
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.FALSE)
+                .getValue();
+
+        Boolean ALLOW_MOCKED_PRODUCERS = ConfigResolver.resolve(ALLOW_MOCKED_PRODUCERS_KEY)
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.FALSE)
+                .getValue();
 
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java
index 4ffe785..5e990a9 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java
@@ -60,7 +60,7 @@ public class MyFacesContainerAdapter implements TestAware, ExternalContainer
                 if (testConfig == null || DEFAULT_TEST_CONFIG_LITERAL.webappResourcePath().equals(
                     testConfig.webappResourcePath()))
                 {
-                    return MyFacesTestBaseConfig.WEBAPP_RESOURCE_PATH.getValue();
+                    return MyFacesTestBaseConfig.WEBAPP_RESOURCE_PATH;
                 }
                 return testConfig.webappResourcePath();
             }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesTestBaseConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesTestBaseConfig.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesTestBaseConfig.java
index 457f8d0..94a06b5 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesTestBaseConfig.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesTestBaseConfig.java
@@ -18,10 +18,13 @@
  */
 package org.apache.deltaspike.testcontrol.impl.jsf;
 
-import org.apache.deltaspike.core.api.config.base.TypedConfig;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
 
 public interface MyFacesTestBaseConfig
 {
-    TypedConfig<String> WEBAPP_RESOURCE_PATH =
-        new TypedConfig<String>("deltaspike.testcontrol.mf.test.webapp_resource_path",
"");
+    String WEBAPP_RESOURCE_PATH = ConfigResolver.resolve("deltaspike.testcontrol.mf.test.webapp_resource_path")
+            .as(String.class)
+            .withCurrentProjectStage(true)
+            .withDefault("")
+            .getValue();
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/AbstractMockManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/AbstractMockManager.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/AbstractMockManager.java
index f252e9c..daac2ae 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/AbstractMockManager.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/AbstractMockManager.java
@@ -35,13 +35,13 @@ public abstract class AbstractMockManager implements DynamicMockManager
     public void addMock(Object mockInstance, Annotation... qualifiers)
     {
         //check if this method gets used without changing the default-config
-        if (!TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS.getValue() &&
-            !TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS.getValue())
+        if (!TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS &&
+            !TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS)
         {
             throw new IllegalStateException("The support for mocked CDI-Beans is disabled
" +
                 "due to a reduced portability across different CDI-implementations. " +
-                "Please set '" + TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS.getKey()
+ "' and/or '" +
-                TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS.getKey() + "' to 'true'
" +
+                "Please set '" + TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS_KEY +
"' and/or '" +
+                TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS_KEY + "' to 'true'
" +
                 "(in 'META-INF/apache-deltaspike.properties') on your test-classpath.");
         }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/25b2b8cc/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/DefaultMockFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/DefaultMockFilter.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/DefaultMockFilter.java
index 3276cf2..2c322fd 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/DefaultMockFilter.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/mock/DefaultMockFilter.java
@@ -97,11 +97,11 @@ public class DefaultMockFilter implements MockFilter
         if ((annotated instanceof AnnotatedMethod || annotated instanceof AnnotatedField)
&&
                 annotated.getAnnotation(Produces.class) != null)
         {
-            return TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS.getValue();
+            return TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS;
         }
         else
         {
-            return TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS.getValue();
+            return TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS;
         }
     }
 


Mime
View raw message