views:

2953

answers:

3

I am trying to get RPC testing using GWT. I am using the default StockWatcher project that is mentioned here, I download the project, I import it, everything works fine.

I then run junitcreator in the StockWatcher project:

/Users/stephen/Work/gwt/gwt-mac-1.6.4/junitCreator -junit   /Users/stephen/Applications/eclipse/plugins/org.junit_3.8.2.v20080602-1318/junit.jar -module stockwatcher -eclipse StockWatcher com.google.gwt.sample.stockwatcher.StockWatcherTest

this creates the StockWatcherTest.java in the appropriate test directory, and gives me some hosted and web mode launch files.

I then also added junit.jar to the classpath for this project.

I then modify StockWatcherTest.java to test whether I am capable of making a asynchronous request to the server. Everything looks fine, but when I try to run StockWatcherTest.java in hosted mode, I get the following error:

Starting HTTP on port 0 HTTP

listening on port 49569

The development shell servlet received a request for 'greet' in module 'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml' [WARN] Resource not found: greet; (could a file be missing from the public path or a tag misconfigured in module com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml ?) com.google.gwt.user.client.rpc.StatusCodeException: Cannot find resource 'greet' in the public path of module 'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit'

Here is my StockWatcherTest.java class

package com.google.gwt.sample.stockwatcher.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * GWT JUnit tests must extend GWTTestCase.
 */
public class StockWatcherTest extends GWTTestCase {

  /**
   * Must refer to a valid module that sources this class.
   */
  public String getModuleName() {
    return "com.google.gwt.sample.stockwatcher.StockWatcher";
  }

  /**
   * Add as many tests as you like.
   */
  public void testSimple() {
      GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
      greetingService.greetServer("Bob",
       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);
        }
       });
      delayTestFinish(1000);
  }

}

Here is com/google/gwt/sample/stockwatcher/StockWatcher.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.2//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/src/gwt-module.dtd"&gt;
<module rename-to='stockwatcher'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.standard.Standard'/>
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

  <!-- Other module inherits                                      -->

  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.google.gwt.sample.stockwatcher.client.StockWatcher'/>
</module>

and here is web.xml in my generated war

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd"&gt;

<web-app>

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>StockWatcher.html</welcome-file>
  </welcome-file-list>

  <!-- Servlets -->
  <servlet>
    <servlet-name>greetServlet</servlet-name>
    <servlet-class>com.google.gwt.sample.stockwatcher.server.GreetingServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/stockwatcher/greet</url-pattern>
  </servlet-mapping>

</web-app>

So what am I doing wrong? Any help is appreciated. Thank you.

+1  A: 

hello,

1-you need to add "finishTest();" at the end of the "onSuccess" method.

2-And to resolve the exeption you got : add in your StockWatcher.gwt.xml the path to your servlet greet.

servlet path='/greet' class='com.google.gwt.sample.stockwatcher.server.GreetingServiceImpl'/

A: 

Another solution is using GWT SyncProxy (support both sync & async) to test GWT RPC services in JRE

See the post at http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/ for details

Trung
A: 

i made some simple tests for the stock watcher. you can see them at: http://tayek.com/StockWatcher.zip

Ray Tayek