[ 
https://issues.apache.org/jira/browse/DELTASPIKE-1338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16579466#comment-16579466
 ] 

Matej Novotny commented on DELTASPIKE-1338:
-------------------------------------------

Tests are failing with {{Weld2}} profile because according to CDI 1.2 spec you 
cannot have an enabled alternative declared in {{beans.xml}} which is not 
actually a bean.

This was later on changed for CDI 2.0 (which is why \{{Weld3}} profile works 
just fine), or reverted to what it was prior to 1.2, if you like.

 

The change was covered in https://issues.jboss.org/browse/CDI-627

> 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)

Reply via email to