tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <>
Subject Re: Problem with Testing OpenEJB Security - Examples
Date Sat, 12 Sep 2009 10:35:44 GMT
Oh, I actually did read that. But didn't notice the /test/ in the
path, and thus didn't realize I needed an extra ejb-jar.xml in my test
sources as well - which makes sense.

Sorry about that. Either way, I actually found a very nice way of
doing this. I'm going to write up a blog entry on it. It's basically a
small testing framework to make all this much easier. Something along
the lines of:
framework.runAs(RunAsRole.ADMIN, new Callable()
      public Object call() throws Exception

Here you would have a bunch of EJBs defined, each for a role, and then
an enum of the roles, like RunAsRole.ADMIN or .UNAUTHENTICATED, etc.
And the above method wraps the callable in the EJB. Keeps things
clean/simple, you define the EJBs only once, and you don't have to do
the lookups in every test case.

Is it possible to dynamic construct EJBs in the embedded container? If
this is possible one could even go as far as making an
openejb-junit.jar, which takes the form of:
OpenEjbTest.runAs("admin", new Callable() {

Then the static method would have an EJB which it dynamically modifies
to run as a given role.


On Fri, Sep 11, 2009 at 11:50 PM, David Blevins <> wrote:
> On Sep 8, 2009, at 8:02 AM, Quintin Beukes wrote:
>> Hey,
>> I am trying to make unit tests for my security. So I try implementing
>> the example in my code, but it's not working.
>> I worked from the first example, as it seems more robust/legible for
>> testing different security scenarios. Problem is that the static
>> classes aren't being loaded as EJBs by OpenEJB.
>> I attached my context properties, unit test code, and the log output.
>> What's wrong here? I am sure I didn't miss anything in the example.
> The log output shows only one module, so your test module isn't getting
> picked up.  You probably missed this chunk of javadoc in that example:
>    /**
>     * This little bit of magic allows our test code to execute in
>     * the desired security scope.
>     * <p/>
>     * The src/test/resource/META-INF/ejb-jar.xml will cause this
>     * EJB to be automatically discovered and deployed when
>     * OpenEJB boots up.
>     */
> Add an empty ejb-jar.xml to your test sources and you'll be good to go.
> -David

Quintin Beukes

View raw message