Hi Jens, > -----Original Message----- > From: Rauen, Jens Martin [mailto:[EMAIL PROTECTED]] > Sent: 19 February 2002 09:13 > To: 'Cactus Users List' > Subject: How to test stateless session beans which access entity beans > > Is there an approach how to test stateless session beans which access > entity > beans? > (e.g. for this reference example > http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Ebank.html) > > My idea was to write a JNDILookup method, (e.g. "object JNDILookup(String > jndiname)") to get the home interface of the entity bean inside a session > bean. > If I want to test this, I have to exchange this method, so it offers > me a mockobject which give me back a mocked entity home interface. (Good > idea, isn't it;)) > But how to realize this for a stateless session bean? It could not be the > way to pass the JNDILookup Interface for every method call! It is not > possible to add another "ejbCreate" in stateless session beans... > > Are there some other suggestions?
There are several options : 1/ Write a protected getMyEntityBean() method in your SLSB. Then create a class that extends your SLSB and that overrides your SLSB (it is also a SLSB). This is the session bean that you'll call from your test case. 2/ Write a factory helper class that returns EJB instances. Write a setFactory(MyFactory) method in you SLSB. Then write a mock factory implementation and call setFactory(mockFactory) in your test case. 3/ Use AspectJ to intercept calls to your entity beans method and replace them with mock implementations. > > jens martin > -Vincent -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
