[
https://issues.apache.org/jira/browse/DELTASPIKE-1338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16445736#comment-16445736
]
ASF subversion and git services commented on DELTASPIKE-1338:
-------------------------------------------------------------
Commit 9429dd07ce38359d905b30f86a5cfbe9a108841b in deltaspike's branch
refs/heads/deltaspike-1.8.x from [~gpetracek]
[ https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;h=9429dd0 ]
DELTASPIKE-1338 tests for @TestControl#classFilter
> support class-filter per test
> -----------------------------
>
> Key: DELTASPIKE-1338
> URL: https://issues.apache.org/jira/browse/DELTASPIKE-1338
> Project: DeltaSpike
> Issue Type: New Feature
> Components: TestControl
> Affects Versions: 1.8.1
> Reporter: Gerhard Petracek
> Assignee: Gerhard Petracek
> Priority: Major
> Fix For: 1.8.2
>
>
> based on DELTASPIKE-1337 it should be possible to define a class-filter per
> test.
> it allows type-safe isolation for tests and with cdi 1.1+ e.g. to build
> labeled-alternatives without text-based config.
> a possible approach looks like:
> {code:java}
> @Retention(RUNTIME)
> @Target(TYPE)
> public @interface Labeled {
> Class<? extends TestControl.Label> value();
> }
> public abstract class AbstractLabeledAlternativeFilter implements ClassFilter
> {
> private final Class<? extends TestControl.Label> activeLabel;
> protected AbstractLabeledAlternativeFilter(Class<? extends
> TestControl.Label> activeLabel) {
> this.activeLabel = activeLabel;
> }
> @Override
> public boolean isFiltered(Class<?> targetClass) {
> if (!targetClass.isAnnotationPresent(Alternative.class)) {
> return false;
> }
> Labeled labeled = targetClass.getAnnotation(Labeled.class);
> if (labeled == null) {
> return false;
> }
> if (labeled.value().equals(activeLabel)) {
> return false;
> }
> return true;
> }
> }
> {code}
> {code:java}
> @Labeled(Label1Test.Label1.class)
> @Alternative
> @Priority(1)
> public class MyLabeledAlternativeBean1 extends MyBean { /*...*/ }
> @RunWith(CdiTestRunner.class)
> @TestControl(activeAlternativeLabel = Label1Test.Label1.class, classFilter =
> Label1Test.Label1Filter.class)
> public class Label1Test {
> @Inject
> private MyBean myBean;
> //tests
> public static class Label1 implements TestControl.Label {
> }
> public static class Label1Filter extends AbstractLabeledAlternativeFilter
> {
> public Label1Filter() {
> super(Label1.class);
> }
> }
> }
> {code}
> besides that other custom concepts are possible as well (not even bound to
> alternative-beans).
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)