1

I'm using mockejb framework to mock entity beans in memory, I make a lookup, mockejb brings me a proxy for the real entity. That's working.

But I needed to get a Session Bean from the container JNDI to "understand" that. I mean, when the Session Bean make a lookup to the Entity Bean, I want it to receive the bean I've mocked, not a bean from the database.

I can't mock this Session Bean because inside the method I'm trying to mock, there's a lookup to the entity bean so, I need this method to execute normally but to receive the mocked bean when lookup.

[UPDATE] Informations about my development environment: I'm using IBM RSA 7.5, IBM Websphere 6.1, I have a Web Test Project that runs in-container with Cactus, the last libs on my classpath are:

  • cactus-1.7.2.jar
  • cglib-nodep-2.1_3.jar
  • commons-httpclient-2.0.2.jar
  • commons-logging-1.0.4.jar
  • powermock-easymock-1.3.9-full.jar
  • junit-3.8.1.jar
  • mockejb.jar

Obs.: I've already changed to the latest powermock version with jUnit4, and tried to use EasyMock 3.0 only, and also tried EasyMock 2.x with its class extensions. None of these worked. What really intrigues me is this DefaultInstantiator configuration mentioned on EasyMock docs: http://easymock.org/EasyMock2_4_ClassExtension_Documentation.html. I wondered if that's my case (not supported JVM) and I couldn't make it work.

Thanks for helping.

Jon Cardoso-Silva
  • 991
  • 11
  • 25

1 Answers1

1

"I can't mock this Session Bean because inside the method I'm trying to mock, there's a lookup to the entity bean so,"

Can't you use something like PowerMock to 'fake' the lookup? Like with a replace of methods etc.

Here is something i came across lately: http://dave00ster.blogspot.com/2011/07/powermock-static-method-replace.html

Hope this helps, dave00

dbalakirev
  • 1,918
  • 3
  • 20
  • 31
  • Thanks, I'm trying to. But the problem now is that the class that makes the lookup is a singleton =S. So, I tried to follow instructions to mock specifically static methods (http://redchilliplus.wordpress.com/2010/06/08/unit-testing-in-java-with-easymock-and-powermock/ and http://code.google.com/p/powermock/source/browse/trunk/modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/singleton/MockStaticTest.java) but none of them worked =/ – Jon Cardoso-Silva Jul 14 '11 at 20:23
  • I forgot to mention but It seems the mock doesn't work correctly with the JVM I'm using. It gives me an error: " is not an interface." even when using EasyMock 3 or EasyMock 2.x with class extensions or PowerMock =S – Jon Cardoso-Silva Jul 14 '11 at 20:33
  • If you post how you spefically setup your test class, and classpath (or pom.xml) maybe we can help. – dbalakirev Jul 16 '11 at 08:37
  • Thanks for the answer, I updated the question, if there's any other information that's important to mention, tells me... – Jon Cardoso-Silva Jul 18 '11 at 16:39