Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Unit Test Secured EJBs in Production : Page 4

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.


advertisement

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:
  1. Create a jar file (say, sample.jar) out of the custom servlet you created.
  2. Create a Web Project (Dynamic Web Project) named SampleWeb.
  3. Put the following jars under the WEB-INF/lib folder of the SampleWeb project: junit.jar, junitee.jar, and sample.jar.
  4. Create a JUnit class under SampleWeb named SampleTest. All JUnit classes need to be here.
  5. 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.
  6. Open the testCase.txt file and add the name of the JUnit classes to be tested, such as SampleTest. Save the file.
  7. Edit web.xml so it looks as follows:

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app id="WebApp_ID"> <display-name>SampleWeb</display-name> <servlet> <servlet-name>SampleServlet</servlet-name> <display-name> SampleServlet</display-name> <description> test runner</description> <servlet-class>SampleServlet</servlet-class> <init-param> <param-name>PROVIDER_URL</param-name> <Param-value>iiop: //localhost:4084/</param-value> </init-param> <init-param> <param-name>USER_ID</param-name> <param-value>userid</param-value> </init-param> <init-param> <param-name>PASSWORD</param-name> <param-value>password</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>SampleServlet</servlet-name> <url-pattern>/TestServlet/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>

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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap