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 2018/04/20 13:23:16 UTC
[1/4] deltaspike git commit: DELTASPIKE-1338 tests for
@TestControl#classFilter
Repository: deltaspike
Updated Branches:
refs/heads/master aabbc879e -> 6475f49ce
DELTASPIKE-1338 tests for @TestControl#classFilter
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6475f49c
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6475f49c
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6475f49c
Branch: refs/heads/master
Commit: 6475f49ce82cf568430792b81b58117e41423b17
Parents: 1c18704
Author: gpetracek <gp...@apache.org>
Authored: Fri Apr 20 15:13:44 2018 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Fri Apr 20 15:22:40 2018 +0200
----------------------------------------------------------------------
.../testcontrol/uc019/DefaultTestService.java | 31 ++++++++++
.../testcontrol/uc019/TestBeanClassFilter.java | 65 ++++++++++++++++++++
.../test/testcontrol/uc019/TestLabeled.java | 34 ++++++++++
.../uc019/TestLabeledAlternativeFilter.java | 56 +++++++++++++++++
.../test/testcontrol/uc019/TestService.java | 24 ++++++++
.../testcontrol/uc019/TestServiceLabelX.java | 34 ++++++++++
.../uc019/TestServiceLabelXTest.java | 61 ++++++++++++++++++
.../testcontrol/uc019/TestServiceLabelY.java | 34 ++++++++++
.../uc019/TestServiceLabelYTest.java | 61 ++++++++++++++++++
.../META-INF/apache-deltaspike.properties | 3 +
.../impl/src/test/resources/META-INF/beans.xml | 4 ++
11 files changed, 407 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/DefaultTestService.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/DefaultTestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/DefaultTestService.java
new file mode 100644
index 0000000..ea153a2
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/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.uc019;
+
+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/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestBeanClassFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestBeanClassFilter.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestBeanClassFilter.java
new file mode 100644
index 0000000..4953f3e
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestBeanClassFilter.java
@@ -0,0 +1,65 @@
+/*
+ * 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.uc019;
+
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.spi.filter.ClassFilter;
+import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.testcontrol.api.TestControl;
+
+//!!!not!!! needed with cdi 1.1+ and @Priority (which is the target of this use-case)
+//only needed because our test-suite is based on cdi v1.0
+
+//also useful to test DELTASPIKE-1337
+public class TestBeanClassFilter implements ClassFilter
+{
+ @Override
+ public boolean isFiltered(Class<?> targetClass)
+ {
+ if (!targetClass.getName().startsWith("org.apache.deltaspike.test."))
+ {
+ return false;
+ }
+
+ String currentTestOrigin = ConfigResolver.getPropertyValue(TestControl.class.getName());
+
+ if (currentTestOrigin == null) //no known origin (no @TestControl is used)
+ {
+ //filter all classes which are located in packages using tests with class-filters
+ //(since we test the feature with ambiguous beans which isn't valid without filtering)
+ return getClass().getPackage().getName().equals(targetClass.getPackage().getName());
+ }
+ else
+ {
+ Class<?> currentOrigin = ClassUtils.tryToLoadClassForName(currentTestOrigin);
+ //origin is in one of the packages for class-filtering tests
+ if (getClass().getPackage().getName().equals(currentOrigin.getPackage().getName()))
+ {
+ TestControl testControl = currentOrigin.getAnnotation(TestControl.class);
+ return ClassUtils.tryToInstantiateClass(testControl.classFilter()).isFiltered(targetClass);
+ }
+ return isInSamePackage(targetClass);
+ }
+ }
+
+ private boolean isInSamePackage(Class<?> targetClass)
+ {
+ return targetClass.getPackage().getName().equals(getClass().getPackage().getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeled.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeled.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeled.java
new file mode 100644
index 0000000..fdabf91
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeled.java
@@ -0,0 +1,34 @@
+/*
+ * 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.uc019;
+
+import org.apache.deltaspike.testcontrol.api.TestControl;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(RUNTIME)
+@Target(TYPE)
+public @interface TestLabeled
+{
+ Class<? extends TestControl.Label> value();
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeledAlternativeFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeledAlternativeFilter.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeledAlternativeFilter.java
new file mode 100644
index 0000000..1f25d7b
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestLabeledAlternativeFilter.java
@@ -0,0 +1,56 @@
+/*
+ * 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.uc019;
+
+import org.apache.deltaspike.core.spi.filter.ClassFilter;
+import org.apache.deltaspike.testcontrol.api.TestControl;
+
+import javax.enterprise.inject.Alternative;
+
+public abstract class TestLabeledAlternativeFilter implements ClassFilter
+{
+ private final Class<? extends TestControl.Label> activeLabel;
+
+ protected TestLabeledAlternativeFilter(Class<? extends TestControl.Label> activeLabel)
+ {
+ this.activeLabel = activeLabel;
+ }
+
+ @Override
+ public boolean isFiltered(Class<?> targetClass)
+ {
+ if (!targetClass.isAnnotationPresent(Alternative.class))
+ {
+ return false;
+ }
+
+ TestLabeled testLabeled = targetClass.getAnnotation(TestLabeled.class);
+
+ if (testLabeled == null)
+ {
+ return false;
+ }
+
+ if (testLabeled.value().equals(activeLabel))
+ {
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestService.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestService.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestService.java
new file mode 100644
index 0000000..049d07e
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/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.uc019;
+
+public interface TestService
+{
+ String getValue();
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelX.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelX.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelX.java
new file mode 100644
index 0000000..6adf4b2
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelX.java
@@ -0,0 +1,34 @@
+/*
+ * 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.uc019;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+
+@Alternative
+@TestLabeled(TestServiceLabelXTest.TestLabelX.class)
+@ApplicationScoped
+public class TestServiceLabelX implements TestService
+{
+ @Override
+ public String getValue()
+ {
+ return "result-x";
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelXTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelXTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelXTest.java
new file mode 100644
index 0000000..b3ec01d
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelXTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.uc019;
+
+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 = TestServiceLabelXTest.TestLabelX.class,
+ classFilter = TestServiceLabelXTest.LabelXFilter.class)
+public class TestServiceLabelXTest
+{
+ @Inject
+ private TestService testService;
+
+ @Test
+ public void resultX()
+ {
+ Assert.assertEquals("result-x", testService.getValue());
+ }
+
+ public static class TestLabelX implements TestControl.Label
+ {
+ }
+
+ //replaces the text based config of labeled-alternatives
+ public static class LabelXFilter extends TestLabeledAlternativeFilter
+ {
+ public LabelXFilter()
+ {
+ super(TestLabelX.class);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelY.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelY.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelY.java
new file mode 100644
index 0000000..1d4f9eb
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelY.java
@@ -0,0 +1,34 @@
+/*
+ * 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.uc019;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+
+@Alternative
+@TestLabeled(TestServiceLabelYTest.TestLabelY.class)
+@ApplicationScoped
+public class TestServiceLabelY implements TestService
+{
+ @Override
+ public String getValue()
+ {
+ return "result-y";
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelYTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelYTest.java b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelYTest.java
new file mode 100644
index 0000000..db45c8a
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc019/TestServiceLabelYTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.uc019;
+
+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.TestLabelY.class,
+ classFilter = TestServiceLabelYTest.LabelYFilter.class)
+public class TestServiceLabelYTest
+{
+ @Inject
+ private TestService testService;
+
+ @Test
+ public void resultY()
+ {
+ Assert.assertEquals("result-y", testService.getValue());
+ }
+
+ public static class TestLabelY implements TestControl.Label
+ {
+ }
+
+ //replaces the text based config of labeled-alternatives
+ public static class LabelYFilter extends TestLabeledAlternativeFilter
+ {
+ public LabelYFilter()
+ {
+ super(TestServiceLabelYTest.TestLabelY.class);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/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 357e2b6..d86331a 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
@@ -31,3 +31,6 @@ labeledAlternatives[lbl].org.apache.deltaspike.test.testcontrol.uc015.TestServic
labeledAlternatives[label].org.apache.deltaspike.test.testcontrol.uc017.DefaultTestServiceProducer=org.apache.deltaspike.test.testcontrol.uc017.LabeledTestServiceProducer
labeledAlternatives[label].org.apache.deltaspike.test.testcontrol.uc018.InterceptedTestServiceProducer=org.apache.deltaspike.test.testcontrol.uc018.LabeledTestServiceProducer
+
+#only needed because our test-suite is based on cdi v1.0. with v1.1+ and @Priority (which is the target of this use-case) the following part isn't needed:
+org.apache.deltaspike.core.spi.filter.ClassFilter=org.apache.deltaspike.test.testcontrol.uc019.TestBeanClassFilter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6475f49c/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
index d1b25a7..d22d695 100644
--- a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
+++ b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
@@ -28,5 +28,9 @@
<alternatives>
<class>org.apache.deltaspike.test.testcontrol.CustomMockManager</class>
+
+ <!-- with cdi 1.1+ the following can be replaced with @Priority(...)-->
+ <class>org.apache.deltaspike.test.testcontrol.uc019.TestServiceLabelX</class>
+ <class>org.apache.deltaspike.test.testcontrol.uc019.TestServiceLabelY</class>
</alternatives>
</beans>
[4/4] deltaspike git commit: DELTASPIKE-1322 cleanup
Posted by gp...@apache.org.
DELTASPIKE-1322 cleanup
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/a67888d4
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/a67888d4
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/a67888d4
Branch: refs/heads/master
Commit: a67888d4b666f0b492c1e410fa96056eec5f54ba
Parents: aabbc87
Author: gpetracek <gp...@apache.org>
Authored: Fri Apr 20 12:03:20 2018 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Fri Apr 20 15:22:40 2018 +0200
----------------------------------------------------------------------
.../core/api/config/ConfigResolver.java | 22 --------------------
1 file changed, 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a67888d4/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 fe05771..fdb8245 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
@@ -21,14 +21,12 @@ package org.apache.deltaspike.core.api.config;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.TimeUnit;
-import java.util.logging.Logger;
import javax.enterprise.inject.Typed;
@@ -67,9 +65,6 @@ public final class ConfigResolver
*/
public static final String DELTASPIKE_LOG_CONFIG = "deltaspike.config.log";
-
- private static final Logger LOG = Logger.getLogger(ConfigResolver.class.getName());
-
private static ConfigProvider configProvider;
private ConfigResolver()
@@ -369,23 +364,6 @@ public final class ConfigResolver
return getConfigProvider().getConfig().getConfigSources();
}
- 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;
- }
-
-
/**
* Filter the configured value.
* This can e.g. be used for decryption.
[3/4] deltaspike git commit: DELTASPIKE-1338 support for ClassFilter
per @TestControl test
Posted by gp...@apache.org.
DELTASPIKE-1338 support for ClassFilter per @TestControl test
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1c187042
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1c187042
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1c187042
Branch: refs/heads/master
Commit: 1c187042577258360680de517151d748807ff6c8
Parents: b780892
Author: gpetracek <gp...@apache.org>
Authored: Fri Apr 20 15:12:56 2018 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Fri Apr 20 15:22:40 2018 +0200
----------------------------------------------------------------------
.../deltaspike/testcontrol/api/TestControl.java | 9 +++++
.../testcontrol/api/junit/CdiTestRunner.java | 2 +-
.../api/junit/CdiTestSuiteRunner.java | 40 ++++++++++++++++----
.../api/literal/TestControlLiteral.java | 7 ++++
4 files changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c187042/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 5753250..7885fb2 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
@@ -18,6 +18,7 @@
*/
package org.apache.deltaspike.testcontrol.api;
+import org.apache.deltaspike.core.spi.filter.ClassFilter;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
import java.lang.annotation.Annotation;
@@ -64,6 +65,14 @@ public @interface TestControl
*/
Class<? extends Label> activeAlternativeLabel() default Label.class;
+ //with cdi 1.1+ it can be used to implement labeled-alternatives without text based config
+ //(details see DELTASPIKE-1338)
+ /**
+ * low-level filter (mainly needed for special cases if labeled-alternatives aren't enough)
+ * @return the class-filter class which should be used for the current test-class
+ */
+ Class<? extends ClassFilter> classFilter() default ClassFilter.class;
+
interface Label
{
}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c187042/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 f50650c..11be0d4 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
@@ -467,7 +467,7 @@ 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");
- CdiTestSuiteRunner.applyAlternativeLabel(testClass);
+ CdiTestSuiteRunner.applyTestSpecificMetaData(testClass);
container.boot(CdiTestSuiteRunner.getTestContainerConfig());
setContainerStarted();
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c187042/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 bfe0b45..5a31765 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
@@ -22,6 +22,7 @@ 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.apache.deltaspike.core.spi.filter.ClassFilter;
import org.apache.deltaspike.core.spi.activation.Deactivatable;
import org.apache.deltaspike.core.spi.config.ConfigSource;
import org.apache.deltaspike.core.util.ClassDeactivationUtils;
@@ -111,7 +112,7 @@ public class CdiTestSuiteRunner extends Suite
if (!containerStarted)
{
- applyAlternativeLabel(getTestClass().getJavaClass());
+ applyTestSpecificMetaData(getTestClass().getJavaClass());
container.boot(getTestContainerConfig());
containerStarted = true;
@@ -219,16 +220,17 @@ public class CdiTestSuiteRunner extends Suite
}
//just here, because all shared methods are in this class
- static void applyAlternativeLabel(Class<?> currentAnnotationSource)
+ static void applyTestSpecificMetaData(Class<?> currentAnnotationSource)
{
- String activeAlternativeLabel = checkForLabeledAlternativeConfig(currentAnnotationSource);
- initTestEnvConfig(currentAnnotationSource, activeAlternativeLabel);
+ TestControl testControl = currentAnnotationSource.getAnnotation(TestControl.class);
+ String activeAlternativeLabel = checkForLabeledAlternativeConfig(testControl);
+
+ initTestEnvConfig(currentAnnotationSource, activeAlternativeLabel, testControl);
}
- private static String checkForLabeledAlternativeConfig(Class<?> currentAnnotationSource)
+ private static String checkForLabeledAlternativeConfig(TestControl testControl)
{
String activeAlternativeLabel = "";
- TestControl testControl = currentAnnotationSource.getAnnotation(TestControl.class);
if (testControl != null)
{
@@ -258,7 +260,7 @@ public class CdiTestSuiteRunner extends Suite
return activeAlternativeLabel;
}
- private static void initTestEnvConfig(Class<?> testClass, String activeAlternativeLabel)
+ private static void initTestEnvConfig(Class<?> testClass, String activeAlternativeLabel, TestControl testControl)
{
if (ClassDeactivationUtils.isActivated(TestConfigSource.class))
{
@@ -283,6 +285,18 @@ public class CdiTestSuiteRunner extends Suite
testConfigSource.getProperties().put("activeAlternativeLabel", activeAlternativeLabel);
testConfigSource.getProperties().put("activeAlternativeLabelSource", testClass.getName());
+
+ if (testControl != null)
+ {
+ testConfigSource.getProperties().put(TestControl.class.getName(), testClass.getName());
+ testConfigSource.getProperties().put(ClassFilter.class.getName(), testControl.classFilter().getName());
+ }
+ else
+ {
+ //reset it to avoid leaks between tests
+ testConfigSource.getProperties().put(TestControl.class.getName(), TestControl.class.getName());
+ testConfigSource.getProperties().put(ClassFilter.class.getName(), ClassFilter.class.getName());
+ }
}
else
{
@@ -290,6 +304,18 @@ public class CdiTestSuiteRunner extends Suite
System.setProperty("activeAlternativeLabel", activeAlternativeLabel); //will be picked up by ds-core
System.setProperty("activeAlternativeLabelSource", testClass.getName()); //can be used for custom logic
+
+ if (testControl != null) //can be used for custom logic
+ {
+ System.setProperty(TestControl.class.getName(), testClass.getName());
+ System.setProperty(ClassFilter.class.getName(), testControl.classFilter().getName());
+ }
+ else
+ {
+ //reset it to avoid leaks between tests
+ System.setProperty(TestControl.class.getName(), TestControl.class.getName());
+ System.setProperty(ClassFilter.class.getName(), ClassFilter.class.getName());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c187042/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 f9d789b..80a15d0 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
@@ -18,6 +18,7 @@
*/
package org.apache.deltaspike.testcontrol.api.literal;
+import org.apache.deltaspike.core.spi.filter.ClassFilter;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
import org.apache.deltaspike.testcontrol.api.TestControl;
@@ -66,4 +67,10 @@ public class TestControlLiteral extends AnnotationLiteral<TestControl> implement
{
return defaultInstance.activeAlternativeLabel();
}
+
+ @Override
+ public Class<? extends ClassFilter> classFilter()
+ {
+ return defaultInstance.classFilter();
+ }
}
[2/4] deltaspike git commit: DELTASPIKE-1337 optional ClassFilter
Posted by gp...@apache.org.
DELTASPIKE-1337 optional ClassFilter
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b7808929
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b7808929
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b7808929
Branch: refs/heads/master
Commit: b7808929786eee130e9a724390ff148644d0b127
Parents: a67888d
Author: gpetracek <gp...@apache.org>
Authored: Fri Apr 20 13:07:28 2018 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Fri Apr 20 15:22:40 2018 +0200
----------------------------------------------------------------------
.../deltaspike/core/spi/filter/ClassFilter.java | 26 +++++++++++
.../exclude/extension/ExcludeExtension.java | 45 +++++++++++++++++---
2 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b7808929/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/filter/ClassFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/filter/ClassFilter.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/filter/ClassFilter.java
new file mode 100644
index 0000000..6a891da
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/filter/ClassFilter.java
@@ -0,0 +1,26 @@
+/*
+ * 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.core.spi.filter;
+
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+
+public interface ClassFilter extends Deactivatable
+{
+ boolean isFiltered(Class<?> currentClass);
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b7808929/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 ade000d..183d1d9 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
@@ -18,21 +18,23 @@
*/
package org.apache.deltaspike.core.impl.exclude.extension;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
import org.apache.deltaspike.core.api.config.base.CoreBaseConfig;
import org.apache.deltaspike.core.api.exclude.Exclude;
-import org.apache.deltaspike.core.impl.util.AnnotationInstanceUtils;
-import org.apache.deltaspike.core.spi.alternative.AlternativeBeanClassProvider;
-import org.apache.deltaspike.core.util.ServiceUtils;
-import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
-import org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter;
-import org.apache.deltaspike.core.impl.exclude.GlobalAlternative;
-import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.spi.filter.ClassFilter;
import org.apache.deltaspike.core.api.interpreter.ExpressionInterpreter;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
+import org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter;
+import org.apache.deltaspike.core.impl.exclude.GlobalAlternative;
import org.apache.deltaspike.core.impl.interpreter.PropertyExpressionInterpreter;
+import org.apache.deltaspike.core.impl.util.AnnotationInstanceUtils;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.spi.alternative.AlternativeBeanClassProvider;
import org.apache.deltaspike.core.util.ClassDeactivationUtils;
import org.apache.deltaspike.core.util.ClassUtils;
import org.apache.deltaspike.core.util.ProjectStageProducer;
+import org.apache.deltaspike.core.util.ServiceUtils;
+import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Alternative;
@@ -80,6 +82,10 @@ public class ExcludeExtension implements Extension, Deactivatable
private Map<String, String> globalAlternatives = new HashMap<String, String>();
private Annotation priorityAnnotationInstance;
+ //overruling the filter is supported via config-ordinal - for now only one is supported to keep it simple
+ //a custom filter can always delegate to multiple filters
+ //(e.g. in combination with ServiceUtils or querying all config-sources explicitly)
+ private ClassFilter classFilter;
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
@@ -107,6 +113,20 @@ public class ExcludeExtension implements Extension, Deactivatable
priorityAnnotationInstance = AnnotationInstanceUtils.getPriorityAnnotationInstance(priorityValue);
}
}
+
+ boolean isClassFilterActivated = ClassDeactivationUtils.isActivated(ClassFilter.class);
+
+ if (isClassFilterActivated)
+ {
+ String classFilterClassName = ClassFilter.class.getName();
+ String activeClassFilterName =
+ ConfigResolver.getProjectStageAwarePropertyValue(classFilterClassName, classFilterClassName);
+
+ if (!classFilterClassName.equals(activeClassFilterName))
+ {
+ classFilter = ClassUtils.tryToInstantiateClassForName(activeClassFilterName, ClassFilter.class);
+ }
+ }
}
private void loadGlobalAlternativeConfigs()
@@ -164,6 +184,17 @@ public class ExcludeExtension implements Extension, Deactivatable
return;
}
+ if (classFilter != null)
+ {
+ Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass();
+
+ if (classFilter.isFiltered(beanClass))
+ {
+ veto(processAnnotatedType, classFilter.getClass().getName());
+ return;
+ }
+ }
+
//TODO needs further discussions for a different feature CodiStartupBroadcaster.broadcastStartup();
//also forces deterministic project-stage initialization