Reputation: 1559
There is a scenario which I'm currently facing where I have to manually create an instance of the spark.Request
& spark.Response
object. Can anyone help me with this?
Upvotes: 1
Views: 2482
Reputation: 29
In your derived classes you can override body() body(String text), status(), status(int stat) etc - all the methods you need. Like this for the Request body say...
class RequestStub extends Request
{
private String _body;
RequestStub(String body)
{
_body = body;
}
public String body()
{
return _body;
}
}
So you get to do something like this...
Request rq = new RequestStub(readFile("./src/test/resources/nested-test.txt"));
Response rp = new ResponseStub();
String result = (String)Controller.Post.handle(rq,rp);
Upvotes: 0
Reputation: 4343
I am creating both request and response objects for testing purposes.
My implementation looks like this
package spark;
public class RequestStub extends Request {
// Implement the methods needed
// I fake my return values
}
This works well for testing.
If this isn't what you need, then please share more details and perhaps a code sample to describe your problem.
Upvotes: 2