Repository: deltaspike Updated Branches: refs/heads/master 1c3a16be1 -> 7177eda1f
DELTASPIKE-1319 labeled alternatives Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/036c8e95 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/036c8e95 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/036c8e95 Branch: refs/heads/master Commit: 036c8e95e36e57f0fd5c7b4c6a1946ad27f1367a Parents: 1c3a16b Author: gpetracek <gpetra...@apache.org> Authored: Tue Feb 27 20:03:16 2018 +0100 Committer: gpetracek <gpetra...@apache.org> Committed: Tue Feb 27 20:03:16 2018 +0100 ---------------------------------------------------------------------- .../exclude/extension/ExcludeExtension.java | 24 ++++++++- .../deltaspike/testcontrol/api/TestControl.java | 9 ++++ .../testcontrol/api/junit/CdiTestRunner.java | 39 ++++++++++++++- .../api/literal/TestControlLiteral.java | 6 +++ .../testcontrol/uc014/DefaultTestService.java | 31 ++++++++++++ .../test/testcontrol/uc014/TestLabelX.java | 25 ++++++++++ .../test/testcontrol/uc014/TestService.java | 24 +++++++++ .../testcontrol/uc014/TestServiceLabelX.java | 33 +++++++++++++ .../testcontrol/uc014/TestServiceLabelY.java | 33 +++++++++++++ .../uc014/TestServiceLabelYTest.java | 50 +++++++++++++++++++ .../uc014/TestServiceNoLabelTest.java | 44 +++++++++++++++++ .../uc014/TestServiceTestLabelXTest.java | 46 +++++++++++++++++ .../uc015/AlternativeServiceTest.java | 44 +++++++++++++++++ .../testcontrol/uc015/DefaultTestService.java | 31 ++++++++++++ .../uc015/GlobalAlternativeTestService.java | 33 +++++++++++++ .../testcontrol/uc015/LabeledServiceTest.java | 52 ++++++++++++++++++++ .../testcontrol/uc015/LabeledTestService.java | 33 +++++++++++++ .../test/testcontrol/uc015/TestService.java | 24 +++++++++ .../META-INF/apache-deltaspike.properties | 6 +++ 19 files changed, 585 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java index f521665..85b0221 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java @@ -66,6 +66,8 @@ import java.util.logging.Logger; public class ExcludeExtension implements Extension, Deactivatable { private static final String GLOBAL_ALTERNATIVES = "globalAlternatives."; + private static final String LABELED_ALTERNATIVES = "labeledAlternatives"; + private static final String ACTIVE_ALTERNATIVE_LABEL_KEY = "activeAlternativeLabel"; private static final Logger LOG = Logger.getLogger(ExcludeExtension.class.getName()); @@ -95,10 +97,30 @@ public class ExcludeExtension implements Extension, Deactivatable ClassDeactivationUtils.isActivated(GlobalAlternative.class); if (isGlobalAlternativeActivated) { + String alternativeLabel = ConfigResolver.getPropertyValue(ACTIVE_ALTERNATIVE_LABEL_KEY); + + String activeQualifierLabel = null; + if (alternativeLabel != null) + { + activeQualifierLabel = LABELED_ALTERNATIVES + "[" + alternativeLabel + "]."; + } + Map<String, String> allProperties = ConfigResolver.getAllProperties(); for (Map.Entry<String, String> property : allProperties.entrySet()) { - if (property.getKey().startsWith(GLOBAL_ALTERNATIVES)) + if (activeQualifierLabel != null && property.getKey().startsWith(activeQualifierLabel)) + { + String interfaceName = property.getKey().substring(activeQualifierLabel.length()); + String implementation = property.getValue(); + if (LOG.isLoggable(Level.FINE)) + { + LOG.fine("Enabling labeled alternative for interface " + + interfaceName + ": " + implementation); + } + + globalAlternatives.put(interfaceName, implementation); + } + else if (property.getKey().startsWith(GLOBAL_ALTERNATIVES)) { String interfaceName = property.getKey().substring(GLOBAL_ALTERNATIVES.length()); String implementation = property.getValue(); http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java index baba3cb..5753250 100644 --- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java +++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java @@ -58,4 +58,13 @@ public @interface TestControl * Currently only supported on class-level */ boolean startExternalContainers() default true; + + /** + * allows to label alternative cdi-beans similar to global alternatives to bind them to 0-n tests + */ + Class<? extends Label> activeAlternativeLabel() default Label.class; + + interface Label + { + } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/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 e05b871..0da1feb 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 @@ -50,6 +50,7 @@ import javax.enterprise.context.SessionScoped; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Named; import javax.inject.Singleton; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -452,7 +453,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner return this.testControl.logHandler(); } - void applyBeforeClassConfig(Class testClass) + void applyBeforeClassConfig(Class<?> testClass) { CdiContainer container = CdiContainerLoader.getCdiContainer(); @@ -467,6 +468,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner // Note that Weld 1 was "flat" anyway, so this property only affects newer versions of Weld System.setProperty("org.jboss.weld.se.archive.isolation", "false"); + checkForLabeledAlternativeConfig(testClass); + container.boot(CdiTestSuiteRunner.getTestContainerConfig()); setContainerStarted(); @@ -490,6 +493,40 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner startScopes(container, testClass, null, restrictedScopes.toArray(new Class[restrictedScopes.size()])); } + private void checkForLabeledAlternativeConfig(Class<?> testClass) + { + String activeAlternativeLabel = ""; + TestControl testControl = testClass.getAnnotation(TestControl.class); + + if (testControl != null) + { + Class<? extends TestControl.Label> activeTypedAlternativeLabel = + testControl.activeAlternativeLabel(); + + if (!TestControl.Label.class.equals(activeTypedAlternativeLabel)) + { + Named labelName = activeTypedAlternativeLabel.getAnnotation(Named.class); + + if (labelName != null) + { + activeAlternativeLabel = labelName.value(); + } + else + { + String labelClassName = activeTypedAlternativeLabel.getSimpleName(); + activeAlternativeLabel = labelClassName.substring(0, 1).toLowerCase(); + + if (labelClassName.length() > 1) + { + activeAlternativeLabel += labelClassName.substring(1); + } + } + } + } + //always set it even if it is empty (it might overrule the value of the prev. test + System.setProperty("activeAlternativeLabel", activeAlternativeLabel); //will be picked up by ds-core + } + private void bootExternalContainers(Class testClass) { if (!this.testControl.startExternalContainers()) http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java index 071cdf6..f9d789b 100644 --- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java +++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java @@ -60,4 +60,10 @@ public class TestControlLiteral extends AnnotationLiteral<TestControl> implement { return defaultInstance.startExternalContainers(); } + + @Override + public Class<? extends Label> activeAlternativeLabel() + { + return defaultInstance.activeAlternativeLabel(); + } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/DefaultTestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/DefaultTestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/DefaultTestService.java new file mode 100644 index 0000000..02a30c1 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/DefaultTestService.java @@ -0,0 +1,31 @@ +/* + * 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.uc014; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class DefaultTestService implements TestService +{ + @Override + public String getValue() + { + return "default-result"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestLabelX.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestLabelX.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestLabelX.java new file mode 100644 index 0000000..d1095ae --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestLabelX.java @@ -0,0 +1,25 @@ +/* + * 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.uc014; + +import org.apache.deltaspike.testcontrol.api.TestControl; + +public class TestLabelX implements TestControl.Label +{ +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestService.java new file mode 100644 index 0000000..0712668 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestService.java @@ -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. + */ +package org.apache.deltaspike.test.testcontrol.uc014; + +public interface TestService +{ + String getValue(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelX.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelX.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelX.java new file mode 100644 index 0000000..55438ac --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelX.java @@ -0,0 +1,33 @@ +/* + * 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.uc014; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Alternative; + +@Alternative +@ApplicationScoped +public class TestServiceLabelX implements TestService +{ + @Override + public String getValue() + { + return "result-x"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelY.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelY.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelY.java new file mode 100644 index 0000000..2d0d793 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelY.java @@ -0,0 +1,33 @@ +/* + * 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.uc014; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Alternative; + +@Alternative +@ApplicationScoped +public class TestServiceLabelY implements TestService +{ + @Override + public String getValue() + { + return "result-y"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelYTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelYTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelYTest.java new file mode 100644 index 0000000..406bce6 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceLabelYTest.java @@ -0,0 +1,50 @@ +/* + * 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.uc014; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.TestControl; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + +@RunWith(CdiTestRunner.class) +@TestControl(activeAlternativeLabel = TestServiceLabelYTest.Y.class) +public class TestServiceLabelYTest +{ + @Inject + private TestService testService; + + @Test + public void resultY() + { + Assert.assertEquals("result-y", testService.getValue()); + } + + class Y implements TestControl.Label + { + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceNoLabelTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceNoLabelTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceNoLabelTest.java new file mode 100644 index 0000000..49571c4 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceNoLabelTest.java @@ -0,0 +1,44 @@ +/* + * 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.uc014; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + +@RunWith(CdiTestRunner.class) +public class TestServiceNoLabelTest +{ + @Inject + private TestService testService; + + @Test + public void noLabel() + { + Assert.assertEquals("default-result", testService.getValue()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceTestLabelXTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceTestLabelXTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceTestLabelXTest.java new file mode 100644 index 0000000..304fa5a --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc014/TestServiceTestLabelXTest.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.testcontrol.uc014; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.TestControl; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + +@RunWith(CdiTestRunner.class) +@TestControl(activeAlternativeLabel = TestLabelX.class) +public class TestServiceTestLabelXTest +{ + @Inject + private TestService testService; + + @Test + public void resultX() + { + Assert.assertEquals("result-x", testService.getValue()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/AlternativeServiceTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/AlternativeServiceTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/AlternativeServiceTest.java new file mode 100644 index 0000000..80532c1 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/AlternativeServiceTest.java @@ -0,0 +1,44 @@ +/* + * 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.uc015; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + +@RunWith(CdiTestRunner.class) +public class AlternativeServiceTest +{ + @Inject + private TestService testService; + + @Test + public void defaultValue() + { + Assert.assertEquals("alternative-result", testService.getValue()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/DefaultTestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/DefaultTestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/DefaultTestService.java new file mode 100644 index 0000000..8335a3f --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/DefaultTestService.java @@ -0,0 +1,31 @@ +/* + * 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.uc015; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class DefaultTestService implements TestService +{ + @Override + public String getValue() + { + return "default-result"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/GlobalAlternativeTestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/GlobalAlternativeTestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/GlobalAlternativeTestService.java new file mode 100644 index 0000000..9a037f0 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/GlobalAlternativeTestService.java @@ -0,0 +1,33 @@ +/* + * 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.uc015; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Alternative; + +@Alternative +@ApplicationScoped +public class GlobalAlternativeTestService implements TestService +{ + @Override + public String getValue() + { + return "alternative-result"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledServiceTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledServiceTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledServiceTest.java new file mode 100644 index 0000000..137db7f --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledServiceTest.java @@ -0,0 +1,52 @@ +/* + * 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.uc015; + +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.testcontrol.api.TestControl; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.inject.Named; + +//Usually NOT needed! Currently only needed due to our arquillian-setup +@Category(SeCategory.class) + +@RunWith(CdiTestRunner.class) +@TestControl(activeAlternativeLabel = LabeledServiceTest.Label.class) +public class LabeledServiceTest +{ + @Inject + private TestService testService; + + @Test + public void resultLbl() + { + Assert.assertEquals("result-lbl", testService.getValue()); + } + + @Named("lbl") + class Label implements TestControl.Label + { + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledTestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledTestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledTestService.java new file mode 100644 index 0000000..e42de1a --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/LabeledTestService.java @@ -0,0 +1,33 @@ +/* + * 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.uc015; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Alternative; + +@Alternative +@ApplicationScoped +public class LabeledTestService implements TestService +{ + @Override + public String getValue() + { + return "result-lbl"; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/TestService.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/TestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/TestService.java new file mode 100644 index 0000000..127a000 --- /dev/null +++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc015/TestService.java @@ -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. + */ +package org.apache.deltaspike.test.testcontrol.uc015; + +public interface TestService +{ + String getValue(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/036c8e95/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike.properties ---------------------------------------------------------------------- diff --git a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike.properties b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike.properties index 882ce29..64820bf 100644 --- a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike.properties +++ b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/apache-deltaspike.properties @@ -22,3 +22,9 @@ deltaspike.testcontrol.mock-support.allow_mocked_producers=true org.apache.deltaspike.core.spi.activation.ClassDeactivator=org.apache.deltaspike.test.testcontrol.InternalTestClassDeactivator deltaspike.testcontrol.test-container.config-file.UnitTest=META-INF/test/dsTestContainerBootConfig.properties + +labeledAlternatives[testLabelX].org.apache.deltaspike.test.testcontrol.uc014.TestService=org.apache.deltaspike.test.testcontrol.uc014.TestServiceLabelX +labeledAlternatives[y].org.apache.deltaspike.test.testcontrol.uc014.TestService=org.apache.deltaspike.test.testcontrol.uc014.TestServiceLabelY + +globalAlternatives.org.apache.deltaspike.test.testcontrol.uc015.TestService=org.apache.deltaspike.test.testcontrol.uc015.GlobalAlternativeTestService +labeledAlternatives[lbl].org.apache.deltaspike.test.testcontrol.uc015.TestService=org.apache.deltaspike.test.testcontrol.uc015.LabeledTestService