Gerhard Petracek created DELTASPIKE-1338:
--------------------------------------------

             Summary: support class-filter per test
                 Key: DELTASPIKE-1338
                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1338
             Project: DeltaSpike
          Issue Type: Improvement
          Components: TestControl
    Affects Versions: 1.8.1
            Reporter: Gerhard Petracek
            Assignee: Gerhard Petracek
             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)

Reply via email to