2013-09-01 28 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如果您认为它可以得到增强,请随时发表评论。 –