• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory  RSS feed

shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

We are developing an web application (jsp/some controller)(JPA+GlassfishV2).
This is an existing project, in this we have an existing light weighted mvc framework.

we have DispatcherServlet entry in web.xml,We have write controller by extending an abstract classes.

Now i need to write testcase(ServletTestCase) for controller but i'm not able to get entity manger instance when i'm running test cases.

Controller code is like following
- an request processing method
- inside this method getting parameter from request.
- now getting or saving data with the help of another project (DataLayer)
- we pass 'entity manager factory' instance and 'transaction instance' to DataLayer that work as Dao.

We are instantiating entity manager factory and usertransaction in DispatcherServlet.

sample test controller :-

public class AbcControllerTest extends ServletTestCase {

public void beginProcessRequest(WebRequest request) {

request.addParameter("userid", "13499");
request.addParameter("password", "robinson");

public void testProcessRequest() throws Exception {
System.out.println("request processing");
AbcController instance = new AbcController();
ModelAndView expResult = new ModelAndView("/login.jsp");
ModelAndView result = instance.processRequest(request, response);
assertEquals(expResult.getPage(), result.getPage());

Please suggest me how i get the emf or if any other way i write the case to achive the same.

I'm new to servlet testing but i have some experience of junit testing.

Thanks in adavance
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!