Dalla schrieb:
> So we´ve all learnt that MVP is *for the win* when working with GWT,
> since we can easily switch our GUI widgets to mock widgets, enabling
> us to use
> regular jUnit tests for our code.
>
> But how do you handle the async calls made to a server when testing?
> Can we use jUnit at all?
Do you want to test the client-side if the result of an async-call is
correctly processed or do you want to test the server-side, i.e.
the methods of the RemoteServiceServlet.
Nathan already told you about the first case, the servlet itself
is quite easily tested if the methods don't access parts of the
servlet container (i.e. getThreadLocalRequest().something), because
you can simply instantiate the servlet and call the methods to be
tested directly. If you need the servlet containter you can use
httpunit to do that kind of thing. Here is a (non-GWT)-example of
a test of my AS2-Connector:
ServletRunner servletrunner = new ServletRunner();
servletrunner.registerServlet("as2servlet",
AS2MessageReceiveServlet.class.getName());
ServletUnitClient sclient = servletrunner.newClient();
Properties props = new Properties();
Session javamailsession = Session.getDefaultInstance(props, null);
MimeMessage mm = getAs2MessageAsMimeMessage(javamailsession);
WebRequest wr = new MimeMessageWebRequest("http://localhost/as2servlet", mm);
InvocationContext ic = sclient.newInvocation(wr);
assertEquals("check isFilterActive", false, ic.isFilterActive());
AS2MessageReceiveServlet servlet = (AS2MessageReceiveServlet) ic.getServlet();
servlet.setCallback(this);
ic.service();
WebResponse resp = ic.getServletResponse();
[check response-values]
The answer of the request is rfc-specific but with an inner class
you can intercept the result of the method-call itself:
private class TestServlet extends MyRFCServlet{
private String methodCalled = null;
private Object methodResult = null;
public String getSomethingAsString(){
methodCalled = "getSomethingAsString";
methodResult = super.getSomethingAsString();
return (String) methodResult;
}
}
So ignoring the HTTP-response you can check the result by accessing
the members of the inner class:
assertEquals("check method being called", "getSomethingAsString",
servlet.methodCalled);
assertNotNull("check existance of result", servlet.methodResult);
assertEquals("check result", "someResult", servlet.methodResult);
A more general way of the above inner class is using a Java Proxy.
Regards, Lothar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---