2013-09-01 27 views
2

我使用GWT RequestBuilder,爲了測試目的,我想在服務器中加載json文件。 它與DevMode完美協作,但在GWTTestCase中拋出404錯誤。GWT:單元測試時出現404錯誤RequestBuilder

隨着RPC,有一個修補程序添加<servlet path=".." class="..."/>,但我可以做什麼與靜態內容?

,我可以很容易地使用@TextResource,但它不是我的單元測試(這實際上是一個functionnal測試)

回答

1

我用過(再次)托馬斯的答案來解決問題。我的模塊是io.robusta.fora.comments.Comment.gwt.xml,我已將我的user.json文件放在io.robsuta.fora.comments.resources包中。

我有這麼在Comment.gwt.xml文件中加入:<public path="resources"/>

然後GWTTestCase很簡單:

public class GwtRestClientTest extends GWTTestCase{ 

    @Override 
    public String getModuleName() { 
     return "io.robusta.fora.comments.Comments"; 
    } 


    public void testGET(){ 

     String base = GWT.getModuleBaseURL(); 
     System.out.println(base); //-> http://192.168.0.10:53551/io.robusta.fora.comments.Comments.JUnit/ 

     GwtRestClient client = new GwtRestClient(base); //base url 
     AsyncCallback<String> cb = new AsyncCallback<String>() { 

      @Override 
      public void onSuccess(String result) { 
       System.out.println(result);//->{id:1,email:"[email protected]"} 
       finishTest(); 

      } 

      @Override 
      public void onFailure(Throwable caught) { 
       caught.printStackTrace(); 
      } 
     }; 

     client.GET("user.json", null, cb);//fetch my json file with no params 
     delayTestFinish(3000); 
    } 

} 
+0

注:如果你想從中超開發模式來源加載JSON文件,那麼你可以用'GWT.getModuleBaseForStaticFiles()'替換'GWT.getModuleBaseURL()'。我會更新文檔(如果我在忘記它之前找到時間)。 –

+0

https://gwt-review.googlesource.com/4340如果您認爲它可以得到增強,請隨時發表評論。 –