0

フロントエンドにGWT、バックエンドにGUICEを使用してGoogle App Engineで提供されるアプリを作成しようとしています。

サンプルセットアップを使用して非常に単純なアプリを作成しました

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

アプリは正常に動作しますが、GWT RPC 呼び出しの単体テストをいくつか追加したいと考えていました。

以下のように GWTTestCase を使用しようとしています: `public void testContactMessageService() {

    ContactMessage message = new ContactMessage();
    message.setName("Jeff");
    message.setMessage("Just wanted to say I'm a fan.");
    message.setEmail("man.nick.utd@gmail.com");

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

`/**

ただし、テストを実行すると失敗し、コンソールに出力されます

[警告] 404 - POST /com.resume.Contacthandler.JUnit/GWT.rpc (192.168.0.11) 1425 バイト リクエスト ヘッダー ホスト: 192.168.0.11:4016 ユーザー エージェント: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19 Accept-Language: en-us Accept: / 接続: キープアライブ リファラー: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/junit.html?gwt.codesvr=192.168.0.11:4012 X-GWT-順列: HostedMode X-GWT-Module-Base: 192.168 .0.11:4016/com.resume.Contacthandler.JUnit/コンテンツ タイプ: テキスト/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 サーブレットをどのようにセットアップしますか?

4

1 に答える 1

1

ブログで取り上げられている方法以外にも、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
}
于 2011-08-01T16:13:33.517 に答える