GWT:在我的GWTTestCase提交AJAX请求时获得404我的、GWT、GWTTestCase、AJAX

由网友(自我救赎)分享简介:我使用的Eclipse靛蓝在Win XP和尝试写一个GWT测试用例我的GWT 2.4应用程序。具体而言,我想测试一个AJAX请求,但我得到一个404。我认为GWT会旋转起来了自己的服务器托管模式?我的code是I'm using Eclipse Indigo on win XP and trying to write...

我使用的Eclipse靛蓝在Win XP和尝试写一个GWT测试用例我的GWT 2.4应用程序。具体而言,我想测试一个AJAX请求,但我得到一个404。我认为GWT会旋转起来了自己的服务器托管模式?我的code是

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

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

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

运行测试通过右键单击它,选择运行方式和GWT测试案例。在控制台中的误差

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

推荐答案

有关JUnit测试,你必须声明你的servlet在模块的 gwt.xml 使用 &LT; servlet路径=...级= .../&GT; 元素

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

阅读全文

相关推荐

最新文章