2011-07-13 12 views
0

フロントエンドにはGWTを、Google App EngineにはバックエンドのGUICEを使用してアプリケーションを作成しようとしています。私はGWT RPC GWTTestCase + GUICE 2.0

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

アプリが正常に動作設定例を使用して非常にシンプルなアプリを作成しました

は、しかし、私はGWT RPC呼び出しのためにいくつかのユニットテストを追加したいです。

私は以下のようにGWTTestCaseを使用しようとしています:私は、テストを実行すると、{)( `公共ボイド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); 
    } 

`/**

をしかし、それはそれを失敗し、コンソール上プリント

[WARN] 404 - POST /com.resume.Contacthandler.JUnit/GWT.rpc(192.168.0.11)1425のバイト 要求ヘッダー ホスト:192.168.0.11:4016 ユーザーのAg ent:Mozilla/5.0(Windows; U; Windows NT 5.1; en-US; RV:1.9.0.19)のGecko/2010031422 Firefoxの/ 3.0.19 は受け入れ-言語:EN-US 受け入れ:/ 接続:キープアライブ リファラー:192.168.0.11:4016/com.resume.Contacthandler.JUnitを/junit.html?gwt.codesvr=192.168.0.11:4012 X-GWT-Permutation:HostedMode X-GWTモジュールベース:192.168.0.11:4016/com.resume.Contacthandler.JUnit/ コンテンツタイプ: text/x-gwt-rpc; charset = utf-8 Content-Length:285 レスポンスヘッダー Content-Type:text/html; charset = iso-8859-1 Content-Length:1425 com.google.gwt.user.client.rpc.StatusCodeException:404 HTTPエラー:404 NOT_FOUND RequestURI =/com.resume.Contacthandler.JUnit/GWT.rpc

私はGuiceがセットアップを取得していないサーバー側で何かを想定しています。

GWTTestCasesの実行時にサーバーサイドのGuiceサーブレットを設定するにはどうすればよいですか?

答えて

1

stuffthathappensブログのアプローチ以外に、GuiceとGWTを動作させる方法はずっと簡単です。たとえば、次のコードは、サーブレットを起動して実行するために必要なもののほとんどです。これはGWTコードには触れませんので、純粋なJREテストでテストするのは簡単です。テストインジェクタをセットアップして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 
} 
+0

恐ろしい本当にありがとうございました、私はチュートリアルの多くを経て、私は(「...」)サーブがありませんでした見たことがない部分にはweb.xmlに実装されますが、私のインジェクターは何も注入していなかったとして、 –