GWT SyncProxy-0.1.1New!           Bean Properties Editor for JDeveloper 11gNew!. -->
  gwtXPDownloadsBlog

Testing GWT RPC services

Posted in GWT on January 10th, 2010 7 Comments

You may know that testing with GWTTestCase are very slow. And there are many posts about testing GWT applications without using GWTTestCase.

However, it is still hard to test our RPC remote services. That is the reason I decided to develop SyncProxy which can run directly from pure Java (non JSNI) code.

Simple Test case

For example, we have an helloApp application and we want to test our GreetingService

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
  String greetServer(String name);
}

Assume the server side of application is running (whether in DevMode or deployed to an web server) and the servlet URL is configured at http://localhost/helloApp/greet

The test case

public class GreetingServiceTest extends TestCase{
  private static GreetingService rpcService =
    SyncProxy.newProxyInstance(GreetingService.class,
          "http://localhost/helloApp", "greet");

  public void testGreeting() {
    String result = rpcService.greetServer("SyncProxy");
    assertTrue((result != null) && (result.startsWith("Hello, SyncProxy")))
  }
}

Explanation

SyncProxy.newProxyInstance() method requires a service interface class, a base URL and a relative servlet path.

SyncProxy will search for RPC policy files (*.gwt.rpc files) to determine appropriate policy name for the service interface. Thus, we copy gwt.rpc files from war/helloApp directory to our test case classpath.

SyncProxy.newProxyInstance() will return a new proxy instance which implements our GreetingService interface.

Simulating Async

By design SyncProxy is synchronous, e.g it invoke the remote service and wait for the result. However, our GWT logic code invokes the remote service asynchronously. SyncProxy can simulate the ‘Async’ mode too.

GreetingServiceAsync rpcServiceAsync =
SyncProxy.newProxyInstance(GreetingServiceAsync.class,
          "http://localhost/helloApp", "greet");

The code is almost the same as section above, except we use the Async version of the remote service interface.

rpcService.greetServer("SyncProxy", new AsyncCallback<String>(){
  public void onFailure(Throwable caught) {
    ...
  }
  public void onSuccess(String result) {
    ...
  }
});

Download SyncProxy

Get SyncProxy (with source code) at our Downloads page

SyncProxy includes test suite (see the Java source file com.gdevelop.gwt.syncrpc.test.RPCSyncSuite) to test against the standard GTW RPC test.

Updated on 2010/03/03: Version 0.1.1 is released with cookie supports

Share and Enjoy:

  • Google Bookmarks
  • Twitter
  • Facebook
  • Digg
  • Technorati
  • Live
  • DZone
  • Reddit
  • del.icio.us
  • Mixx
  • Netvibes
  • StumbleUpon
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • email

Bean Properties Editor for JDeveloper 11g

Posted in JDeveloper on December 2nd, 2009 2 Comments

I developed beans with setter and getter methods frequently. And of course it is tedious to write code repeatedly for every bean’s properties.

How many key strokes for a single bean property? Too many as you guest.

In JDeveloper 10g, there is extension called Simple Java Bean Editor to allow developers to edit bean’s properties easily.

However, there is no one for JDeveloper 11g. That is one of reasons I decided to develop a new one.

Another reason is our projects require property change supports, the bean should fire property change event when setting new value to a property. Specially, gwtXP’s data binding rely on JFace data binding which in turn requires property change supports for model – UI widget synchronization.

The new Bean properties Editor (beanped) has following features:

  • Functionality to edit  bean properties
  • Property change supports

Installation

  • Download it in the Downloads page
  • In JDeveloper 11g select menu Help -> Check for Updates
  • In the step 2 of “Check for Updates” wizard select “Install from Local File”
  • Click Browse button and select the downloaded file.
  • Review the license and click button “I Agree”
  • Click button “Next” and then “Finish”

Note: After installed, for your convenience, the Bean Properties Editor will create a new Update Source in the JDeveloper. When a new version is released, your JDeveloper will notify you to perform the update.

Using Bean Properties Editor

Bean Properties Editor
Figure 1. Bean Properties Editor screen shot – Bean Editor tab

Bean Properties Editor
Figure 2. Bean Properties Editor screen shot – Bean Editor screen

Add Property dialog
Figure 3. Add Property dialog

  • Open the bean Java source file. See the figure 1 above.
  • Click on “Bean Editor” tab. You will see the screen as in the figure 2 above. Just a simple user interface, there are two buttons and a table for list of properties at the bottom.
  • To add a new property: Click “Add” button, input the property name and the property type. You can select/deselect check boxes “Generate Read Method” and “Generate Write Method”. Click OK button when done
  • To remove a property: Select the property you want to remove and Click “Delete” button
  • To add/remove the property’s Read method: Select/deselect the check box in the Read column in the properties list
  • To add/remove the property’s Write method: Select/deselect the check box in the Write column in the properties list

Generated code

With few key strokes and mouse click, the Bean Properties Editor generates following code

package com.gdevelop.samples.bean;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class Student {
  private String name;
  private transient PropertyChangeSupport changeSupport =
      new PropertyChangeSupport(this);

  public Student() {
  }

  public String getName() {
    return this.name;
  }
  public void setName(String name) {
    String oldName = this.name;
    this.name = name;
    changeSupport.firePropertyChange("name", oldName, name);
  }

  public void addPropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(listener);
  }
  public void addPropertyChangeListener(String propName,
                                        PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(propName, listener);
  }

  public void removePropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(listener);
  }
  public void removePropertyChangeListener(String propName,
                                           PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(propName, listener);
  }
}

Feedback and new feature requests

I hope this JDeveloper’s extension is helpful and appreciated for you feedback and/or features requests.

Share and Enjoy:

  • Google Bookmarks
  • Twitter
  • Facebook
  • Digg
  • Technorati
  • Live
  • DZone
  • Reddit
  • del.icio.us
  • Mixx
  • Netvibes
  • StumbleUpon
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • email