deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Pietrzak <kap4...@gmail.com>
Subject how to test different java.security.Principal's
Date Wed, 10 Feb 2016 13:27:33 GMT
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("alice@example.com");

    }

    @Inject

    Principal principal;


    @Test

    *public* *void* injection() {

        *assertThat*(principal.getName(), *is*("alice@example.com"));

    }

@Dependent

@RunWith(CdiTestRunner.*class*)

*public* *class* BobUnitTest {

    @Produces

    *public* Principal customPrincipal() {

        *return* *new* CustomPrincipal("bob@example.com");

    }


    @Inject

    Principal principal;


    @Test

    *public* *void* injection() {

        *assertThat*(principal.getName(), *is*("bob@example.com"));

    }


}


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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message