Repository: deltaspike Updated Branches: refs/heads/master 7256bb043 -> 41a333ffd
DELTASPIKE-785 added unit-test, unified handling and config-name Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/41a333ff Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/41a333ff Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/41a333ff Branch: refs/heads/master Commit: 41a333ffdc24d4dd7176ff8d405ef0cc1100b612 Parents: 7256bb0 Author: gpetracek <[email protected]> Authored: Thu Nov 20 12:52:09 2014 +0100 Committer: gpetracek <[email protected]> Committed: Thu Nov 20 13:05:09 2014 +0100 ---------------------------------------------------------------------- .../testcontrol/api/junit/CdiTestRunner.java | 20 ++-------- .../api/junit/CdiTestSuiteRunner.java | 16 +++++++- .../testcontrol/uc013/ContainerConfigTest.java | 41 ++++++++++++++++++++ .../apache-deltaspike_test-container.properties | 24 ++++++++++++ 4 files changed, 83 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/41a333ff/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 c6f12ef..2287810 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 @@ -23,7 +23,6 @@ import org.apache.deltaspike.cdise.api.CdiContainer; import org.apache.deltaspike.cdise.api.CdiContainerLoader; import org.apache.deltaspike.cdise.api.ContextControl; import org.apache.deltaspike.core.api.config.ConfigResolver; -import org.apache.deltaspike.core.api.config.PropertyLoader; import org.apache.deltaspike.core.api.projectstage.ProjectStage; import org.apache.deltaspike.core.api.provider.BeanManagerProvider; import org.apache.deltaspike.core.api.provider.BeanProvider; @@ -58,7 +57,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Properties; import java.util.Set; import java.util.Stack; import java.util.concurrent.CopyOnWriteArraySet; @@ -77,12 +75,6 @@ import java.util.logging.Logger; */ public class CdiTestRunner extends BlockJUnit4ClassRunner { - /** - * The configuration switch to define the configuration properties file. - * By default the property file which gets loaded has the exactly same name. - */ - public static final String TEST_RUNNER_CONFIG = "cdiTestRunnerConfig"; - private static final Logger LOGGER = Logger.getLogger(CdiTestRunner.class.getName()); private static final boolean USE_TEST_CLASS_AS_CDI_BEAN; @@ -138,14 +130,6 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner }); } - public static Properties getTestContainerConfig() - { - String cdiTestRunnerConfig = - ConfigResolver.getProjectStageAwarePropertyValue(TEST_RUNNER_CONFIG, TEST_RUNNER_CONFIG); - return PropertyLoader.getProperties(cdiTestRunnerConfig); - } - - @Override public void run(RunNotifier runNotifier) { @@ -456,6 +440,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner foundProjectStageClass = this.testControl.projectStage(); } this.projectStage = ProjectStage.valueOf(foundProjectStageClass.getSimpleName()); + + ProjectStageProducer.setProjectStage(this.projectStage); } boolean isContainerStarted() @@ -477,7 +463,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner { if (!CdiTestSuiteRunner.isContainerStarted()) { - container.boot(getTestContainerConfig()); + container.boot(CdiTestSuiteRunner.getTestContainerConfig()); setContainerStarted(); bootExternalContainers(testClass); http://git-wip-us.apache.org/repos/asf/deltaspike/blob/41a333ff/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 fc4448c..7f442a0 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 @@ -21,6 +21,7 @@ package org.apache.deltaspike.testcontrol.api.junit; import org.apache.deltaspike.cdise.api.CdiContainer; import org.apache.deltaspike.cdise.api.CdiContainerLoader; import org.apache.deltaspike.core.api.config.ConfigResolver; +import org.apache.deltaspike.core.api.config.PropertyLoader; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.notification.Failure; @@ -31,12 +32,18 @@ import org.junit.runners.model.InitializationError; import org.junit.runners.model.RunnerBuilder; import java.util.List; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @SuppressWarnings("UnusedDeclaration") public class CdiTestSuiteRunner extends Suite { + /** + * The configuration switch to define the configuration properties file. + */ + public static final String TEST_RUNNER_CONFIG_KEY = "deltaspike.testcontrol.boot_config"; + private static final String TEST_RUNNER_DEFAULT_CONFIG_NAME = "META-INF/apache-deltaspike_test-container"; private static final boolean STOP_CONTAINER; @@ -88,7 +95,7 @@ public class CdiTestSuiteRunner extends Suite if (!containerStarted) { - container.boot(CdiTestRunner.getTestContainerConfig()); + container.boot(getTestContainerConfig()); containerStarted = true; } @@ -185,4 +192,11 @@ public class CdiTestSuiteRunner extends Suite } } } + + public static Properties getTestContainerConfig() + { + String cdiTestRunnerConfig = ConfigResolver.getProjectStageAwarePropertyValue( + TEST_RUNNER_CONFIG_KEY, TEST_RUNNER_DEFAULT_CONFIG_NAME); + return PropertyLoader.getProperties(cdiTestRunnerConfig); + } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/41a333ff/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc013/ContainerConfigTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc013/ContainerConfigTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc013/ContainerConfigTest.java new file mode 100644 index 0000000..7f4ed28 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc013/ContainerConfigTest.java @@ -0,0 +1,41 @@ +/* + * 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.testcontrol.uc013; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestSuiteRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + + + +public class ContainerConfigTest +{ + @Test + public void configForTestContainer() + { + Assert.assertNotNull(CdiTestSuiteRunner.getTestContainerConfig()); + Assert.assertEquals("jdbc:hsqldb:mem:demoDB", + CdiTestSuiteRunner.getTestContainerConfig().getProperty("demoDatabase.JdbcUrl")); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/41a333ff/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike_test-container.properties ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike_test-container.properties b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike_test-container.properties new file mode 100644 index 0000000..a766a00 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike_test-container.properties @@ -0,0 +1,24 @@ +# 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. + + +#can be used to configure the underlying test-container +#(currently the only container supported by deltaspike +#(out-of-the-box) which supports that config is openejb-embedded) + +#just random config-entries +demoDatabase.JdbcUrl=jdbc:hsqldb:mem:demoDB
