File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB Testing using JUnit

 
Balachandar Nayak
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written code to test EJB using JUnit.
It contains
1. RemoteInterface
2. Home Interface
3. Implementation Class()

Now I have written a Test program which cover all the above 3 programs
Since the concept of EJB is, we can't call a Session Bean Directly
So I wrote a testProgram which calls a remote interface through home interface to call the
session bean. So for the 3 programs I have written only 1 testProgram

:roll: My Question is whether we can test a session bean directly and can i able to test a interface using Junit?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible to test SessionBeans directly. Just say "new MySessionBeanImpl()" and off you go. Have you tried that? I'm pretty sure you'll run into problems soon, but rest assured there's a way through (and around) those problems.

Also, other than treating your EJB components as plain old Java objects, you can also leverage tools like MockEJB.
 
Balachandar Nayak
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Thanks for ur mail. Im a new to JUnit and MockEJB
Now Im testing EJB Programs using JUnit with MockEJB.

This is the program



On compiling the program, Im getting the following errors

java.lang.NoClassDefFoundError: net/sf/cglib/proxy/MethodInterceptor
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at org.mockejb.jndi.MockContextFactory.getInitialContext(MockContextFactory.java:47)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:175)
at com.ejbpro.DriverStatelessTest.setUp(DriverStatelessTest.java:61)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Whatz the problem and how to solve it?
Plz do it for me.
bala
 
Balachandar Nayak
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to know anyother properties file or xml files to be modified or to be created in order to run this program.

Thanks in Advance

Bala
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the javadocs for NoClassDefFoundError tell us, the exception you're getting ("java.lang.NoClassDefFoundError: net/sf/cglib/proxy/MethodInterceptor") means that the JVM doesn't have CGLIB in its classpath. When you downloaded MockEJB, you probably only added the MockEJB "core" .jar file into your classpath--you need all the dependencies as well (which should come with the distribution).
 
Balachandar Nayak
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I can run the program
Thanks a lot Lassee



Thanks once again
Bala
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic