Unit testing EJBs that are secured through permissions is complex. Learn how to unit test secured EJBs and EJB-based applications in the same production environment without needing to switch off the permission settings.
by Gopal Sharma
Jun 19, 2006
Page 4 of 5
The Environment for Unit Testing Secured EJBs
The following steps will help you set up and configure the environment for unit testing secured EJBs using IBM's Rational Application Developer (RAD) or Rational Software Architect (RSA) IDEs. Since the steps are generic in nature, you should be able to apply them for use with Eclipse as well. In any case, you won't be able to run the JUnitEE-based JUnit test cases without first doing the following:
Create a jar file (say, sample.jar) out of the custom servlet you created.
Create a Web Project (Dynamic Web Project) named SampleWeb.
Put the following jars under the WEB-INF/lib folder of the SampleWeb project: junit.jar, junitee.jar, and sample.jar.
Create a JUnit class under SampleWeb named SampleTest. All JUnit classes need to be here.
Add to the SampleWeb project under WEB-INF a text file that lists the JUnit classes. The JUnitEE servlet reads this file to determine which JUnit classes to load for testing. Name the text file testCase.txt.
Open the testCase.txt file and add the name of the JUnit classes to be tested, such as SampleTest. Save the file.
Initialization parameters (like provider URL, user ID, password, etc.) can also be read from a property file or other resources on the classpath. In fact, you don't need to pass a provider URL as an initialization parameter to the Context. Since you will deploy the Web application under unit test in the same server (i.e., the WebSphere environment) as the EJBs, if you don't pass the provider URL, the initial context factory in the application will use the server ORB instance.