Reputation: 20591
I cant understand how to test GWT's asynchronous RPC calls. On google site i found example code, but it not comprehensive:
public void testTimer() {
Timer timer = new Timer() {
public void run() {
finishTest();
}
};
delayTestFinish(500);
timer.schedule(100);
}
Where i must to put call to remote RPC service? Why we need schedule timer (instead of using run()
method)?
Thanks in advice.
Upvotes: 0
Views: 1328
Reputation: 14883
You have to put the finishTest into the your onSucess method and delay the test for about 500ms (or however you think it takes)
here is an example how it should work.
private void refreshWatchList() {
StockPriceService stockPriceSvc = GWT.create(StockPriceService.class);
AsyncCallback<StockPrice[]> callback = new AsyncCallback<StockPrice[]>() {
public void onFailure(Throwable caught) {
assert(false) : "The test failed because the RPC service returned an error
}
public void onSuccess(StockPrice[] result) {
//the test was a sucess so we tell the Unittest case to finish (with success)
finishTest();
}
};
// Make the call to the stock price service.
stockPriceSvc.getPrices(stocks.toArray(new String[0]), callback);
//delay the finish of the test by 500ms
//if finishTest() isn't call before 500ms passed, the test will fail
delayTestFinish(500);
}
PS: you don't need a timer to test the RPC calls
Upvotes: 3