Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2014
    Posts
    7
    Rep Power
    0

    Default Jersey Test Framework - How to obtain instance of servlet/webresources and mock DAO?

    Hello! I'm looking to unit test a restful service that exposes CRUD operations to an underlying database.
    I read online that the best way to unit test is to separate the restful api and the database interaction and test them separately.
    I would like to therefore mock my DAO and confirm that 'insert' is called on it.
    My idea was that I would append setter methods that may override the injected DAO beans in the web resource class. When running my test, I would change the DAOs with mocks.
    I do not want to manually add in stubs as I would then have two different sets of restful web service classes.
    The <a href="https://jersey.java.net/documentation/1.18/test-framework.html">jersey test framework</a> gives something of a lead in 'creating your own module' but I'm unsure of how to implement it. My current build process is a button on eclipse. I haven't any 'main method' or direct control of starting and stopping the server.
    I'm using WAS Liberty Profile V8.5.

    I'm new to java EE and web development so please let me know if I incorrectly understood some concept.

    Thank you!

  2. #2
    Join Date
    Aug 2014
    Posts
    7
    Rep Power
    0

    Default Re: Jersey Test Framework - How to obtain instance of servlet/webresources and mock D

    I changed from attempting to test the DAO to the actual Restful service because it was unacceptable to have tests that require a live running environment. The DAOS will come later.

    I ended up learning about openEJB as a container which automatically loads beans and assigns them JNDI name and injecting them (instead of having the server do it). I am using mockito as a mocking/stubbing framework. The issue I'm facing now is that i want to replace the implementation with a mock object at the jndi name that the injector uses. I tried a variety of names.

    Please see: ejb 3.0 - What JNDI name does @EJB use to inject Enterprise Java Beans? - Stack Overflow

    I don't know when and if the injector creates new instances of the class at 'x' or if it returns the object already there as a singleton. I would greatly appreciate help!

Similar Threads

  1. Injecting EJB and PersistenceContext in Jersey Servlet Container?
    By 012anonymousxyz in forum Enterprise JavaBeans (EJB)
    Replies: 5
    Last Post: 08-19-2014, 10:50 PM
  2. Servlet Test Problem
    By allayahassine in forum Java Servlet
    Replies: 5
    Last Post: 07-17-2014, 05:11 PM
  3. Instance Variable In Servlet
    By javarishi in forum Java Servlet
    Replies: 3
    Last Post: 06-14-2008, 08:28 AM
  4. Replies: 4
    Last Post: 11-05-2007, 05:14 PM
  5. DepUnit test framework
    By brianhks in forum Reviews / Advertising
    Replies: 0
    Last Post: 07-27-2007, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •