Nicholas Staples
Nicholas Staples

Reputation: 1

GWT RPC GWTTestCase + GUICE 2.0

Im trying to create an app with the GWT on the front end and GUICE on the backend served on the Google App Engine.

I have created a very simple app using the example setup

http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/#comment-49355

The app works fine, however I wanted to add some unit tests for the GWT RPC calls.

I am trying to use the GWTTestCase as below: `public void testContactMessageService() {

    ContactMessage message = new ContactMessage();
    message.setName("Jeff");
    message.setMessage("Just wanted to say I'm a fan.");
    message.setEmail("[email protected]");

    ContactMessageServiceAsync contactMessageService = GWT.create(ContactMessageService.class);

    contactMessageService.sendMessage(message, 
                new AsyncCallback<String>() {
                    public void onFailure(Throwable caught) {
                        // Show the RPC error message to the user
                        System.out.println(caught);
                        fail("big time failure");
                        finishTest();
                    }

                    public void onSuccess(String result) {
                        System.out.println("success, biatch");
                        assertTrue(true);
                        finishTest();
                    }
                });
      delayTestFinish(1000);
  }

`/**

However when I run the test it fails and on the console it prints

[WARN] 404 - POST /com.resume.Contacthandler.JUnit/GWT.rpc (192.168.0.11) 1425 bytes Request headers Host: 192.168.0.11:4016 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19 Accept-Language: en-us Accept: / Connection: Keep-Alive Referer: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/junit.html?gwt.codesvr=192.168.0.11:4012 X-GWT-Permutation: HostedMode X-GWT-Module-Base: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/ Content-Type: text/x-gwt-rpc; charset=utf-8 Content-Length: 285 Response headers Content-Type: text/html; charset=iso-8859-1 Content-Length: 1425 com.google.gwt.user.client.rpc.StatusCodeException: 404 HTTP ERROR: 404 NOT_FOUND RequestURI=/com.resume.Contacthandler.JUnit/GWT.rpc

From this output I am assuming something on the server side with Guice is not getting setup.

How do you setup the server side Guice servlets when running GWTTestCases ?

Upvotes: 0

Views: 836

Answers (1)

Will
Will

Reputation: 915

There are much simpler ways to get Guice and GWT working other than the approach in the stuffthathappens blog. For instance, the following code is most of what you'd need to do to get a servlet up and running. This doesn't touch any GWT code so it's easy to test with pure JRE tests - you'd just need to set up a test injector and get an instance of the Service Impl.

serve("/myapp/importservice").with(SourceImportServiceImpl.class);


@Singleton
public class SourceImportServiceImpl extends RemoteServiceServlet {

  private Provider<SimpleDao> daoProvider;

  @Inject
  public SourceImportServiceImpl(Provider<SimpleDao> daoProvider) {
    this.daoProvider = daoProvider;
  }

 ... RPC method implementations
}

Upvotes: 1

Related Questions