2009-06-09 22 views
0

我正在嘗試使用GWT來獲取RPC測試。我正在使用默認的StockWatcher項目here,我下載了項目,我導入它,一切工作正常。無法獲取單元測試GWT上的RPC

然後我在的StockWatcher項目運行junitcreator:

/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 

此創建StockWatcherTest.java在適當的test目錄,並給我一些託管和Web模式啓動文件。

然後,我還將junit.jar添加到此項目的類路徑中。

然後我修改StockWatcherTest.java來測試我是否有能力向服務器發出異步請求。一切看起來很好,但是當我嘗試在託管模式下運行StockWatcherTest.java,我得到以下錯誤:

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'

這裏是我StockWatcherTest.java類

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); 
    } 

} 

這裏是COM /谷歌/ GWT /樣品/的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"> 
<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> 

,這裏是在web.xml中產生我的戰爭

<?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"> 

<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> 

那麼我做錯了什麼?任何幫助表示讚賞。謝謝。

回答

3

1-您需要添加「finishTest();」在「onSuccess」方法的末尾。

2 - 爲了解決您所得到的問題:在您的StockWatcher.gwt.xml中添加您的servlet問候語的路徑。

servlet路徑= '/迎接' 類= 'com.google.gwt.sample.stockwatcher.server.GreetingServiceImpl'/