Correction, I said "EJBs" where I meant "test cases" in the first paragraph. it should've read "This way the user doesn't have to @LocalClient his test cases".
Giving such a hint allows a person to both use properties to specify them in combination with annotations, one or the other or both. Quintin Beukes On Wed, Sep 23, 2009 at 3:12 PM, Quintin Beukes <[email protected]> wrote: > That's a good one. Thanks a lot. > > It would work great if you could "hint" to OpenEJB a "LocalClient". > This way the user doesn't have to @LocalClient his EJBs, and the > Runner can hint to OpenEJB which objects to do it for. > > To modify the existing runner into using @LocalClient instead, VERY > easy. Just do the following: > 1. In the OpenEjbRunner.java file, replace the configureTest(Class > testObj) method with the following: > protected void configureTest(Object testObj) throws Exception > { > initialContext.bind("inject", testObj); > } > 2. Annotate your test class with @LocalClient. > > For interest sake, did the attachment go through? > > Quintin Beukes > > On Wed, Sep 23, 2009 at 2:35 PM, Laird Nelson <[email protected]> wrote: >> Neat stuff. >> >> Incidentally, OpenEJB will handle the injection for you: >> http://openejb.apache.org/3.0/local-client-injection.html >> >> Cheers, >> Laird >> >> On Wed, Sep 23, 2009 at 8:29 AM, Quintin Beukes <[email protected]> wrote: >> >>> Hey, >>> >>> I know this was mentioned the other day, though I can't find the >>> e-mail, so I'm making a new thread. I attached a simple runner which I >>> made as a personal PoC. It basically allows you to define a test as >>> follows: >>> >>> @RunWith(OpenEjbRunner.class) >>> @TestContext >>> public class BasicStatelessBeanTest >>> { >>> �...@ejb >>> public BasicStatelessBeanLocal basicStatelessBean; >>> >>> �...@resource >>> public InitialContext initialContext; >>> >>> �...@test >>> public void testSomeMethod() {} >>> } >>> >>> It then runs the test and injects any @EJB annotated fields, and any >>> InitialContext type fields when they're annotated with @Resource. >>> >>> It's very very basic though. Took me probably about 30 minutes to put >>> it together. The injection is a JNDI brute force method, where it >>> tries different combinations of names, depending on the annotation >>> arguments and field type. Further you can supply a properties resource >>> filename to @TestContext for customized InitialContext initialization. >>> It also only supports Local initial context (UNLESS you specify >>> mappedName in each @EJB annotation). >>> >>> Note that the test runner should initialize the InitialContext for >>> JUnit 3 tests (tests extending "TestCase"), though it won't do any >>> injection, so it's pretty useless. I have yet to figure out how the >>> Runner works for JUnit 3 tests. Once I'm able to intercept the test >>> class instance the rest should be easy. >>> >>> None of the above limitations is hard to fix, and I'm definitely going >>> to do them. Like I said, this is my result after playing with it for >>> about half an hour. >>> >>> Further, I'm using reflection to do the injection, so the fields need >>> to be public. >>> >>> Well, I'm using this way from now on. Our tests are already strapped >>> with a small framework I made, which wraps OpenEJB and is configured >>> through Spring, so it allows you to customize your lookups nicely, >>> even overriding certain EJB lookups with spring beans. If anyone wants >>> some more of this, just let me know and I'll send it along. I'll be >>> evolving the for our own purposes, and if there's any interest I'm >>> willing to send updates. >>> >>> Note that whatever I send is licensed under Apache 2.0, so you're free >>> to use it in whichever way the license allows. >>> >>> Attached is the maven project for the runner. It contains tests to >>> demonstrate it's use. If the attachment was rejected by the mailing >>> list, just reply and I'll find another way to distribute it. >>> >>> Quintin Beukes >>> >> >
