« Getting Rid of Flakiness in GWT RPC Tests | Main | Regular vs Underground Party »
Tuesday
Jan272009

Populating Test Data for GWT Tests

Sometimes you need to test GWT code that expects to find data in the data store. This approach might work:

In gwtSetUp() create the data (someData) you want to persist and call persist(someData) which would look like the following:

/** Helper method to put data into data store prior to test run. */
private void persist(SomeThing someData) {
SomeServiceAsync someSvc = GWT.create(SomeService.class);
AsyncCallback callback = new AsyncCallback() {
public void onFailure(Throwable caught) {
fail("unable to store test data");
}
public void onSuccess(Boolean success) {
if (success.equals(false)) {
fail("unable to store test data");
}
}
};

// Make the call to the test service impl, passing in the callback object.
// This is the same method you defined in the SomethingService interface
// that extends RemoteService and this method needs to be implemented in
// SomethingServiceImpl
someSvc.saveSomething(someData, callback);

// Wait for it to persist.
// Using Thread.sleep(200) would give compile errors.
// Use gwt.user.client.Timer instead.
Timer timer = new Timer() {
public void run() {
}
};
timer.schedule(200);
}

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>