GWT RPC GWTTestCase +图形界面2.0

发布于 2024-11-19 15:39:31 字数 2347 浏览 2 评论 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("[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 bytes 请求标头 主机: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 接受语言:en-us 接受:/ 连接:保持活动状态 参考:192.168.0.11:4016/com.resume.Contacthandler.JUnit/junit.html?gwt.codesvr=192.168.0.11:4012 X-GWT-排列:托管模式 X-GWT-模块-基础:192.168.0.11:4016/com.resume.Contacthandler.JUnit/ 内容类型:text/x-gwt-rpc;字符集=utf-8 内容长度:285 响应标头 内容类型:text/html;字符集=iso-8859-1 内容长度:1425 com.google.gwt.user.client.rpc.StatusCodeException:404 HTTP 错误:404 NOT_FOUND RequestURI=/com.resume.Contacthandler.JUnit/GWT.rpc

从这个输出中,我假设服务器端的 Guice 没有进行设置。

运行 GWTTestCases 时如何设置服务器端 Guice servlet?

Im trying to create an app with the GWT on the front end and GUICE on the backend served on the Google App Engine.

I have created a very simple app using the example setup

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

The app works fine, however I wanted to add some unit tests for the GWT RPC calls.

I am trying to use the GWTTestCase as below:
`public void 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);
  }

`/**

However when I run the test it fails and on the console it prints

[WARN] 404 - POST /com.resume.Contacthandler.JUnit/GWT.rpc (192.168.0.11) 1425 bytes
Request headers
Host: 192.168.0.11:4016
User-Agent: 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: /
Connection: Keep-Alive
Referer: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/junit.html?gwt.codesvr=192.168.0.11:4012
X-GWT-Permutation: HostedMode
X-GWT-Module-Base: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/
Content-Type: text/x-gwt-rpc; charset=utf-8
Content-Length: 285
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1425
com.google.gwt.user.client.rpc.StatusCodeException: 404
HTTP ERROR: 404 NOT_FOUND
RequestURI=/com.resume.Contacthandler.JUnit/GWT.rpc

From this output I am assuming something on the server side with Guice is not getting setup.

How do you setup the server side Guice servlets when running GWTTestCases ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原野 2024-11-26 15:39:31

除了 stuffthathappens 博客中的方法之外,还有更简单的方法可以让 Guice 和 GWT 工作。例如,以下代码是启动并运行 servlet 所需执行的大部分操作。这不会触及任何 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
}

There are much simpler ways to get Guice and GWT working other than the approach in the stuffthathappens blog. For instance, the following code is most of what you'd need to do to get a servlet up and running. This doesn't touch any GWT code so it's easy to test with pure JRE tests - you'd just need to set up a test injector and get an instance of the 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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文