GWT:在我的 GWTTestCase 中提交 AJAX 请求时收到 404

发布于 2024-12-12 13:21:36 字数 2580 浏览 5 评论 0 原文

我在 win XP 上使用 Eclipse Indigo 并尝试为我的 GWT 2.4 应用程序编写 GWT 测试用例。具体来说,我正在尝试测试 AJAX 请求,但收到 404。我认为 GWT 会在托管模式下启动自己的服务器吗?我的代码是

public class GetHtmlTest extends GWTTestCase {

    public void gwtSetUp() {
        ...
        submitButton = new Button();
        DOM.setElementAttribute(submitButton.getElement(), "id", Productplus_gwt.SUBMIT_BUTTON_ID);
        ...
    }

    @Test
    public void testSuccessEvent() {    
        nameField.setText(VALID_ID);
        submitButton.click();

        Timer timer = new Timer() {
            public void run() {
                final Element contentDiv = DOM.getElementById(Productplus_gwt.CONTENT_DIV_ID);
                final String divText = contentDiv.getInnerText();
                assertNotNull(divText);
                assertEquals(-1, divText.toLowerCase().indexOf("error") );

                finishTest();
            }
        };
        timer.schedule(100);

        delayTestFinish(2000);
    } // testSuccessEvent

最终,单击按钮会导致此 AJAX 调用...

        productPlusService.getHtml(docId, new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                submitButtonElement.setAttribute("enabled", Boolean.TRUE.toString());
                contentDiv.setInnerHTML("<span>Error: " + caught.getMessage() + "</span>");
            }

            public void onSuccess(String result) {
                submitButtonElement.setAttribute("enabled", Boolean.TRUE.toString());

                contentDiv.setInnerHTML(result);

                // Format tabs
                postHtmlProcessing();
            }
        });

我通过右键单击它,选择“运行方式”和“GWT 测试用例”来运行测试。控制台中的错误是

[WARN] 404 - POST /com.myco.clearing.productplus.Productplus_gwt.JUnit/getHtml (10.40.70.197) 1444 bytes
   Request headers
      Host: 10.40.70.197:2084
      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: http://10.40.70.197:2084/com.myco.clearing.productplus.Productplus_gwt.JUnit/junit-standards.html?gwt.codesvr=10.40.70.197:2080
      X-GWT-Permutation: HostedMode
      X-GWT-Module-Base: http://10.40.70.197:2084/com.myco.clearing.productplus.Productplus_gwt.JUnit/
      Content-Type: text/x-gwt-rpc; charset=utf-8
      Content-Length: 217
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1444

“知道出了什么问题吗?”谢谢,-戴夫

I'm using Eclipse Indigo on win XP and trying to write a GWT test case for my GWT 2.4 application. Specifically, I'm trying to test an AJAX request, but I'm getting a 404. I thought GWT will spin up its own server in hosted mode? My code is

public class GetHtmlTest extends GWTTestCase {

    public void gwtSetUp() {
        ...
        submitButton = new Button();
        DOM.setElementAttribute(submitButton.getElement(), "id", Productplus_gwt.SUBMIT_BUTTON_ID);
        ...
    }

    @Test
    public void testSuccessEvent() {    
        nameField.setText(VALID_ID);
        submitButton.click();

        Timer timer = new Timer() {
            public void run() {
                final Element contentDiv = DOM.getElementById(Productplus_gwt.CONTENT_DIV_ID);
                final String divText = contentDiv.getInnerText();
                assertNotNull(divText);
                assertEquals(-1, divText.toLowerCase().indexOf("error") );

                finishTest();
            }
        };
        timer.schedule(100);

        delayTestFinish(2000);
    } // testSuccessEvent

Ultimately, clicking the button causes this AJAX call ...

        productPlusService.getHtml(docId, new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                submitButtonElement.setAttribute("enabled", Boolean.TRUE.toString());
                contentDiv.setInnerHTML("<span>Error: " + caught.getMessage() + "</span>");
            }

            public void onSuccess(String result) {
                submitButtonElement.setAttribute("enabled", Boolean.TRUE.toString());

                contentDiv.setInnerHTML(result);

                // Format tabs
                postHtmlProcessing();
            }
        });

I run the test by right clicking on it, selecting "Run As" and "GWT Test Case". The error in the console was

[WARN] 404 - POST /com.myco.clearing.productplus.Productplus_gwt.JUnit/getHtml (10.40.70.197) 1444 bytes
   Request headers
      Host: 10.40.70.197:2084
      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: http://10.40.70.197:2084/com.myco.clearing.productplus.Productplus_gwt.JUnit/junit-standards.html?gwt.codesvr=10.40.70.197:2080
      X-GWT-Permutation: HostedMode
      X-GWT-Module-Base: http://10.40.70.197:2084/com.myco.clearing.productplus.Productplus_gwt.JUnit/
      Content-Type: text/x-gwt-rpc; charset=utf-8
      Content-Length: 217
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1444

Any ideas what's going wrong? Thanks, - Dave

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

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

发布评论

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

评论(1

玉环 2024-12-19 13:21:36

对于 JUnit 测试,您必须使用 gwt.xml 中声明您的 servlet rel="nofollow"> 元素

For JUnit tests, you have to declare your servlets in your module's gwt.xml using the <servlet path="..." class="..." /> element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文