The class under test:

public class ManageBook extends WebPage {
    public ManageBook() {
        Form form = new Form("form") {
            protected void onSubmit() {
                //use Page "class"
                setResponsePage(CreateBook.class);
            }
        };
        add(form);
    }
}

Test Case:

    public void testManageBook_createBook() throws Exception {
        mockWebApp.getPages().setHomePage(ManageBook.class);
        mockWebApp.setupRequestAndResponse();
        mockWebApp.processRequestCycle();
        ManageBook manageBook = (ManageBook) mockWebApp.getLastRenderedPage();;

        Form form = (Form) manageBook.get("form");
        mockWebApp.setupRequestAndResponse();

        MockHttpServletRequest mockRequest = mockWebApp.getServletRequest();
        mockRequest.setRequestToComponent(form);
        mockWebApp.processRequestCycle();      
       
        //assertion failed,  getLastRenderedPage() return null.
        assertTrue( mockWebApp.getLastRenderedPage() instanceof CreateBook);

    }


If I change to setResponsePage( new CreateBook() ); in Form, the test will pass.
After doing some debug... I found that:

setResponsePage( CreateBook.class)  --> requestCycle.getResponsePage()  return null
setResponsePage( new CreateBook() ) --> requestCycle.getResponsePage()  return createBook

Is this behavior desirable ? If so, one should fix implementation of
MockWebApplication.processRequestCycle()

--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to