• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic