Posts tagged ‘synchronous’

June 22, 2011

Running integration tests against a GWT RequestFactory based back-end

by Stefan

Update 20.07.2011: Added post.releaseConnection() class to HttpPostTransport

If your app uses GWT’s RequestFactory capabilities, a well-defined external interface to your back-end is automatically exposed. The definition is provided using the RequestContext interfaces that are mapped to a service running in the back-end. Example:

Back-end service:

package cleancodematters.server;

import cleancodematters.server.domain.Pizza;

public interface PizzaDao {
  void save( Pizza pizza );
  Pizza findById( Long id );
}

RequestFactory with RequestContext (see the first tutorial for the full code):

package cleancodematters.client;

import cleancodematters.server.DaoLocator;
import cleancodematters.server.PizzaDao;

import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.Service;

public interface PizzaRequestFactory extends RequestFactory {

  @Service(value = PizzaDao.class, locator = DaoLocator.class)
  public interface PizzaRequestContext extends RequestContext {
    Request findById( Long id );
    Request save( PizzaProxy pizza );
  }

  PizzaRequestContext context();
}

With this infrastructure, not only the JS-based client running in the browser but, in fact, any Java client can communicate with your back-end. Although this might not be the full fledged interface for integration with other systems, it is perfectly suitable for running any kind of headless tests against your back-end. This can be functional tests as well as load and performance tests.

All we need to do is to replace the default XHR-based transport layer with a pure JRE compatible implementation. In this example, we use the Apache HttpClient lib. Similar to the tutorial on unit testing a helper class provides a factory method to create RequestFactory instances:

read more »

Advertisements