How can I trap for a 404 in my GWTTestCase?

43 views
Skip to first unread message

laredotornado

unread,
Nov 30, 2011, 3:45:12 PM11/30/11
to Google Web Toolkit
Hi,

I'm using GWT 2.4. I'm trying to write a GwtTestCase that tests
clicking the submit button on my FormPanel. Currently, clicking on
the submit button results in a 404, but my test isn't failing. Here's
how I have my test set up ...

public void testClickSave() {
final FlowPanel flowPanel = new FlowPanel();
final ProductDetailsView productDetailsView = new
ProductDetailsView();
flowPanel.add( productDetailsView );
RootPanel.get().add(flowPanel);

xmlHelperService.getNode("weather.txt", new AsyncCallback<Node>() {

@Override
public void onSuccess(final Node node) {
// Pre-conditions for this test are that they are children and all
the
// children are of type="section".
assertTrue(!node.getChildren().isEmpty());
for (final Node child : node.getChildren()) {
assertEquals(NodeType.SECTION.toString(),
child.getAttributes().get(XmlToHtmlServiceImpl.TYPE_ATTR).getValue());
} // for

productDetailsView.add(node);
// Click the "Save" button.
final Button saveButton = getSaveButton(productDetailsView);
saveButton.click();

finishTest();
}

@Override
public void onFailure(Throwable caught) {
caught.printStackTrace(System.err);
fail(caught.getMessage());
finishTest();
}
});

delayTestFinish(delayFinishTime);
} // testClickSave


The call to "saveButton.click();" is where the 404 is happening. What
can I do to trap for the 404 and cause my test to fail? Thanks, -
Dave

Thomas Broyer

unread,
Dec 1, 2011, 3:54:42 AM12/1/11
to google-we...@googlegroups.com
You can't. Or rather, you only have access to the response page's body, so if you can identify a 404 from that, you're done.

BTW, your test actually isn't even seeing the 404, because you finishTest() just after you saveButton.click(), so the form is submitted (actually probably just after the code yields to the browser, so *after* the finishTest()) but you don't wait for the FormPanel.SubmitCompleteEvent; so it's expected that your test pass.

laredotornado

unread,
Dec 1, 2011, 9:50:22 AM12/1/11
to Google Web Toolkit
Hi,

I know, I'm not waiting for result of submitting the form. How would
I change or add to

saveButton.click();

that submits the form, that would wait for the
FormPanel.SubmitCompleteEvent? Thanks, - Dave

Thomas Broyer

unread,
Dec 1, 2011, 10:47:16 AM12/1/11
to google-we...@googlegroups.com
Just like you're "waiting" for getNode to get back, but here using events: add a FormPanel.SubmitCompleteHandler to your FormPanel and only call finishTest from there. The handler will be called when the server responds to the form submission, so either it works and you can have asserts and then finishTest() (in the normal case), or it somehow breaks (there's little to no reason, but who knows) and your test will fail in timeout (because finishTest will never be called before the timeout expires).

laredotornado

unread,
Dec 1, 2011, 11:04:15 AM12/1/11
to Google Web Toolkit
Thanks, the trouble I'd have is that the FormPanel exists within my
Composite component

final ProductDetailsView productDetailsView = new
ProductDetailsView();

which is client code. That is, I can't put JUnit directives in
there. Does that make sense? The form panel within there already has
a submit complete handler associated with it, so I'm not sure if I can
override that from my test case. Ultimately, I just want to see if
the form submission resulted in a non-200 response.

Thanks, - Dave

Reply all
Reply to author
Forward
0 new messages