Hi Russell, ----- Original Message ----- From: "Russell Gold" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 26, 2001 6:07 PM Subject: Re: Unit testing EJBs with Cactus
> At 04:47 PM 7/26/2001 +0100, Vincent Massol wrote: > >Hi Phil, > > > >I don't understand the issue ... If you put your lookup call to the EJB home > >method in your testXXX() method, it will be executed on the server side (not > >that it matters as far as I know - you would also be able to put it in > >beginXXX() if you wanted - or am I missing someething?). What is the JNDI > >ref. problem that you mention ? You'll just need to get an InitialContext > >from you app .server and then do a lookup from the JNDI service of your app > >server ... If you're doing it on the client side (i.e. in beginXXX()) you'll > >just have to make sure you have your app server client jars on your client > >classpath. > > > >It seems there is something obvious that I must be missing ? > > Yes. The initial context is created by a managed container (EJB, servlet, > or application client) and populated with the data defined in the > deployment descriptor appropriate to the context. In this case, the context > would be the servlet, and is established when the servlet is invoked by the > servlet engine. There are two potential problems here: > > 1. If you try to invoke JNDI from beginXXX, you will not have the mappings, > and the available names for the beans will be server-dependant if they are > available at all (this is not defined by the EJB spec). > > 2. If you invoke it from textXXX, you will have the context of the > redirectory servlet, not the servlet being tested. In either case, you > will not be able to get the desired beans, nor will you be able to test a > servlet which looks for them. > We're now diving into unit testing EJBs in Cactus. I'm not sure I understood completely what you described in point 1 and 2 above. We have written a simple tutorial on http://jakarta.apache.org/cactus/howto_ejb_j2eeri.html. I would very much appreciate if you could have a look at it and tell me if there is anything wrong with it (it uses the approach number 2. above). We are also considering doing approach 1. with a dedicated EJBTestCase and EJBRedirector which would be a session bean. Do you see any problem with that ? The only issue that I see, be it with 1. or 2. is to initialize JNDI. This is server dependent but that's not too much an issue because : - our goal is not to create EJB unit tests that can be run on any EJB server (although it will be possible to automatically support several EJB servers later on and the JNDI setup might be done by Cactus). - usually the default values are enough (see below). For WAS 3.5, for example, this involves : javax.naming.Context.PROVIDER_URL = iiop://hostname:port, where hostname [However, if not specified, it defaults to localhost and port 900] javax.naming.Context.INITIAL_CONTEXT_FACTORY = com.ibm.ejs.ns.jndi.CNInitialContextFactory However, most of the time, the default values will be fine and writting : "InitialContext context = new InitialContext();" is enough (instead of "InitialContext context = new InitialContext(properties);") The EJB name itself is defined by the EJB deployer and is independent of the client. For example: "java:comp/ejb/Converter" Anything I am missing ? Thanks -Vincent
