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() {


Regular vs Underground Party

I was invited to go to a party in Oakland last Saturday. It is called "People's party" and my friends were raving about the great vibe you find at this place. So we went. Brad driving, me giving directions (thanks to my Google phone).

We got there at 11pm (which is fairly early for clubbin) and the place was packed. It definitely exceeded the maximum allowed occupancy as it took us about 10 minutes to squeeze through people to get to the back room and to the patio. People were friendly, dancing to African music, eating African food and drinking tea (which I loved) in addition to the standard bar drinks. You could smell some weed in the air, and everyone was taking it easy. So my friends were right, it does feel like a best friend's house party, but with 10 times more people than is healthy.
There were only two things wrong with this party:

  • there was a line outside (Why do American clubs try to keep a visible line of people freezing their tails outside on the street? Is this a marketing strategy? Can someone explain why you do not see any lines in clubs outside of the US?)
  • everybody knew about it and everybody went there => there was absolutely no space to dance
Second Chance
It was 12:30 and we bailed out. Our Google phone came to the rescue again... we looked up another party that night... at the underground venue (you need to call a hotline to get the address). Q Burns (our favorite DJ) was playing and it was only few blocks from our loft in San Francisco! So we headed back through the Bay Bridge into the industrial neighborhood at the very south of SOMA.

Finding underground parties requires a bit of patience. First drive to the place Google Maps arrow points to. Then get out of the car and start walking around carefully listening to warehouses. You will get to a door on the side of a dark warehouse. There is no line, no bouncers, no lights, no visible signs of anything happening. You know that you are at the right place because there is definitely a loud house music playing behind that door. You go in, and there is a handful of people who check your ID, take the cover, and let you in. The dancefloor is mostly dark. Few lights point at the bare walls of the warehouse, cars and machinery is moved to one side of the hall, and makeshift bar serves a limited selection of drinks. There is plenty of space for dancing and few dozen people are practicing their house dance routines. There is not stage, no go-go dancers, no posers, no skimpy dressed girls. Just you, them, great music, and great vibe.


Testing RPC in GWT

There is very little information about sticking with GWTTestCase (instead of TestCase) and using fake server-side service implementation.


You do not want to make any database-calls when your client-side tests run (when client-side tests make RPC calls to the service impl). You already have to live with crappy test speeds due to GWT test framework starting up an invisible hosted-mode browser to be able to execute JavaScript (that many widgets natively use) and you am too lazy to refactor your code to follow the GWT using MVC model example (to be able to stop using GWTTestCase).


Define a separate fake service implementation (TestServiceImpl) and a module for testing (TestModule.gwt.xml). Simply make a copy of the production module, and change the contents of the servlet path tag to point to your TestSeviceImpl. Then make sure your GWTTestCase specifies this module in its getModuleName().

Voila! Tests run, they return expected values (either baked into TestServiceImpl or if you get fancy, your TestServiceImpl can implement a nice in-memory data store).
You can now be confident that your asynchronous RPC mechanism works as intended and you can test the production ServiceImpl separately (using JUnit).


Are you scared yet?

Gerald Celente predicts a major economic depression, tax rebellions, food riots, and by 2012 people will worry about food for Christmas rather than gifts. He predicts that local governments will keep raising taxes to get as much money from public as possible.
Soon, people will have food-producing gardens, and the only thing that can save us must be comparable to an invention of the wheel. He predicts revolutionary advances in renewable energy technologies, medical science, and a shift towards holistic healing practices and a crash of the overpriced college education system.

So buy some gold and then dust off your gardening gear and plant some food!


Guice 1.0 vs 2.0

The Guice 2.0 contains lots of neat improvements. It removes lots of unnecessary boilerplate and allows to write more compact Guice modules. Here is an example of how a confusing binding can be refactored into a simple provider method.

Example using Guice 1.0:
protected void configure() {
bind(new TypeLiteral<List<string>>(){})

The same example using Guice 2.0:
@Provides @TagsToProcess
public List<string> provideTags(@Named("tags") String tags) {
  return ImmutableList.of(StringUtil.splitAndTrim(tags, ","));