Bryan,
I know this isn't directly answering your question, but how we do
testing is by integrating with the Spring Framework. With Spring, you
get various DAO and service layer support classes which are easily testable.
Essentially, if you make your Restlets as "dumb" as possible by
transferring all the business logic code into a Spring managed bean,
then you can isolate and test these beans and not need to generate mock
Request/Response objects.
From there, if you want to test the whole stack, you can do so by using
the Jakarta Commons Http Client or other types of web testing frameworks.
All of these tests can run as JUnit tests, so you can leverage its
testing support.
I'm sure others will have more ideas about how to mock a Request or
Response object like you're looking to do. So, the above is just one
of, I'm sure, dozens of ideas.
Hope this helps,
Adam
Bryan Loofbourrow wrote:
I'm interested in adding a unit test for certain aspects of the behavior of my
REST service, one that can execute outside the confines of a Web server. It
would be sufficient if there were merely a way for me to call the Restlet
classes directly, then examine the response.
What's not obvious to me is how one would go about this. I'd need to create
Request and Response objects, obviously, but what's the best way to do that, and
what would I need to put in there? Is there a Factory somewhere I should be
using for this? Or is this the wrong approach; is there some other way to
accomplish this (short of decoupling the code underlying the Restlet and testing
that by itself)?
Thanks,
-- Bryan