GWT: Getting 404 when submitting AJAX request in my GWTTestCase

764 views Asked by At

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

1

There are 1 answers

0
Thomas Broyer On BEST ANSWER

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