Monday, November 29, 2010

GWTTestCase: Unable to access objects returned from a successful RPC call

I've got a project I'm working on where I make an RPC call to the
server which calls a webservice on a different domain, gets some XML,
parses it, and then returns to me a Java object.

Now I'm trying to unit test this and I'm running into a problem where
my Java object is "not accessible" after it's been returned by the
server. That is, in my onSuccess(MyJavaObject result) method in my
GWTTestCase, I cannot say: result.getSomeData(). Doing this results
in something kinda funny...the test just finishes. It doesn't execute
any lines of code after that line, and it does not cause the test to
fail.

Here's a snippet of my code:

TestGetSomething.java:
public void testGetSomeData() {
MyServiceAsync svc = MyService.Util.getInstance();
AsyncCallback<MyJavaObject > callback = new
AsyncCallback<MyJavaObject >() {
@Override
public void onFailure(Throwable caught) {
System.out.println(caught.getMessage());
finishTest();
}
@Override
public void onSuccess(MyJavaObject result) {
assertNotNull(result);
System.out.println(result.getSomeData()); // <option 1>

System.out.println("Foo"); // <option 2>
finishTest();
}

};
svc.getSomeData("parameter", callback);
}


Now if I run this as it's written above, "Foo" does NOT get printed.
However, if I run this without the line marked <option 1>, then "Foo"
DOES get printed.

Is this a limitation to the GWTTestCase, or something that I'm
missing? Also, something to note, if MyJavaObject happens to be of
type String, I can say System.out.println(result); and it will print
the string returned from the server call.

Thanks,
Jeff

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment