mclev wrote:
>
> 4. Can I test that the response page is what I expect when when I first
> render and when i submit my form
>
> So, call me crazy, but it occurs to me that it would be nice if I could
> "unit test" just my page, verifying that when the code in my page finishes
> executing everything is what I expect. I don't really care if the response
> page renders properly (I'll test that in a unit test for that page), I
> just want to know that the logic in my page in sending off to the new
> page.
>
>
So I figured out a way to do this by extending the
WebRequestCycleProcessor.respond methods. :
public class TestingWebRequestCycleProcessor extends
WebRequestCycleProcessor {
private boolean respondingSuspended = false;
public TestingWebRequestCycleProcessor(){
super();
}
public boolean isRespondingSuspended() {
return respondingSuspended;
}
public void setRespondingSuspended(boolean respondingSuspended) {
this.respondingSuspended = respondingSuspended;
}
@Override
public void respond(RequestCycle requestCycle)
{
if (isRespondingSuspended()){
return;
}
super.respond(requestCycle);
}
@Override
public void respond(RuntimeException e, RequestCycle requestCycle)
{
if (isRespondingSuspended()){
return;
}
super.respond(e, requestCycle);
}
}
then overriding the WicketTester.DummyApplication:
public class TestingWebApplication extends
WicketTester.DummyWebApplication{
private TestingWebRequestCycleProcessor requestProcessor;
@Override
protected IRequestCycleProcessor newRequestCycleProcessor()
{
requestProcessor = new TestingWebRequestCycleProcessor();
return requestProcessor;
}
public void suspendResponding(){
requestProcessor.setRespondingSuspended(true);
}
public void unsuspendResponding(){
requestProcessor.setRespondingSuspended(false);
}
}
now my test looks like this:
@Test
public void testSubmitExistingPart(){
// setup for modifying a part (part has an id -- found by dao)
setUp();
final Part part = new MockPart(10);
final PartDAO mockDAO = module.getmock();
mockery.checking(new Expectations(){{
one(mockDAO).findPart(part.getId());
will(returnValue(part));
one(mockDAO).save(with(same(part)));
}});
PageParameters params = new PageParameters("id="+ part.getId());
Page page = new PartDetailPage(params);
tester.startPage(page);
// simulate entry of part data
FormTester formTester = tester.newFormTester("inputForm");
String barcode = "123";
String name = "ABC";
String description = "XYZ";
enterFormData(formTester, barcode, name, description);
testApp.suspendResponding(); // so response won't be rendered
formTester.submit();
// verify values set properly in model;
assertModelUpdated(part, barcode, name, description);
// verify that response page is correct
// this now works -- even though the page isn't really
renderd
tester.assertRenderedPage(PartListPage.class);
}
I'm still new to wicket so if anybody thinks this is this is crazy please
let me know.
--
View this message in context:
http://www.nabble.com/Using-the-WicketTester-WITHOUT-rendering-a-response-on-submit-tf4801394.html#a13757593
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]