I'm not sure how to use my custom CDI qualifiers to achieve my goal. Care to send a blog post or a link to an example?
I guess one of the confounding problems might be a test executing in Maven has two bean archives: - target/classes - target/test-classes So whatever solution needs to recognize that target/classes might have its own bean.xml (for production). Do I need an @Alternative or something? Thanks! Any tips would be greatly appreciated. On Wed, Feb 10, 2016 at 9:24 AM, Gerhard Petracek < [email protected]> wrote: > hi, > > you can use your own cdi-qualifier/s or you can use just one (central) > producer which has at least one parameter of type > javax.enterprise.inject.spi.InjectionPoint. > (InjectionPoint allows to get information about the target > -> you can produce dependent-scoped instances e.g. based on the target > test-class). > > regards, > gerhard > > > > 2016-02-10 14:27 GMT+01:00 Karl Pietrzak <[email protected]>: > > > Thanks to Java EE 7, or maybe even before it, you can inject a > > java.security.Principal > > <https://docs.oracle.com/javaee/7/tutorial/cdi-adv004.htm>. > > > > This is awesome, and I'd love to use this functionality to unit test my > > code with my own Principal's. > > > > Something like: > > > > @Dependent > > > > @RunWith(CdiTestRunner.*class*) > > > > *public* *class* AliceUnitTest { > > > > @Produces > > > > *public* Principal customPrincipal() { > > > > *return* *new* CustomPrincipal("[email protected]"); > > > > } > > > > @Inject > > > > Principal principal; > > > > > > @Test > > > > *public* *void* injection() { > > > > *assertThat*(principal.getName(), *is*("[email protected]")); > > > > } > > > > @Dependent > > > > @RunWith(CdiTestRunner.*class*) > > > > *public* *class* BobUnitTest { > > > > @Produces > > > > *public* Principal customPrincipal() { > > > > *return* *new* CustomPrincipal("[email protected]"); > > > > } > > > > > > @Inject > > > > Principal principal; > > > > > > @Test > > > > *public* *void* injection() { > > > > *assertThat*(principal.getName(), *is*("[email protected]")); > > > > } > > > > > > } > > > > > > This results in "WELD-001409: Ambiguous dependencies for type Principal > > with qualifiers @Default" and "WELD-001318: Cannot resolve an ambiguous > > dependency between: ". > > > > I think I tried every different scope and bean-discovery-mode. Is this > > supported at all? > > > > Code available at > > > > > https://github.com/The-Alchemist/javaeetesting/tree/testing-different-principals/deltaspike > > > > Any tips would be greatly appreciated. :) > > > > -- > > Karl > > > -- Karl
