I'm in the midst of upgrading Equinox (http://equinox.dev.java.net)
from Tapestry 3.3 to 4.0.  With the 3.3 version, I had a
tapestry-mock.jar that I created from Tapestry's CVS, as well as an
AbstractInstantiator class that I found on Howard's site.

For the most part, the new Creator class is sufficient for testing my
pages.  However, I haven't found a way to add pages to Tapestry so
when I call cycle.getPage('name'), things don't fail.

Here's my listener method:

    public void save(IRequestCycle cycle) {
        if (log.isDebugEnabled()) {
            log.debug("entered 'save' method");
        }

        if (getValidationDelegate().getHasErrors()) {
            return;
        }

        getUserManager().saveUser(getUser());

        UserList nextPage = (UserList) cycle.getPage("users");
        nextPage.setMessage(getMessages().format("user.saved",
getUser().getFullName()));
        throw new PageRedirectException(nextPage);
    }

Here's my test - first of all, my UserFormTest.java extends
BasePageTestCase.java:

BasePageTestCase.java:

public class BasePageTestCase extends
AbstractDependencyInjectionSpringContextTests {
    protected final Log log = LogFactory.getLog(getClass());

    protected String[] getConfigLocations() {
        return new String[] {"/WEB-INF/applicationContext*.xml"};
    }

    protected IPage getPage(Class clazz) {
        return getPage(clazz, null);
    }

    protected IPage getPage(Class clazz, Map properties) {
        Creator creator = new Creator();
        if (properties == null) {
            properties = new HashMap();
        }

        return (IPage) creator.newInstance(clazz, properties);
    }
}

public class UserFormTest extends BasePageTestCase {
    private UserForm page;
    private Long userId;
    private UserManager userManager;

    public void setUserManager(UserManager userManager) {
        this.userManager = userManager;
    }

    protected void onSetUp() throws Exception {
        Map map = new HashMap();
        map.put("userManager", userManager);
        page = (UserForm) getPage(UserForm.class, map);

        // create a new user
        User user = new User();
        user.setFirstName("Jack");
        user.setLastName("Raible");

        // persist to database
        userManager.saveUser(user);
        userId = user.getId();
    }

    protected void onTearDown() throws Exception {
        page = null;
    }

    public void testSave() throws Exception {
        RequestCycle cycle = new RequestCycle();
        cycle.setServiceParameters(new Object[] {userId});

        page.edit(cycle);
        assertNotNull(page.getUser());
        try {
            page.save(cycle);
            fail("Redirect didn't occur");
        } catch (PageRedirectException pe) {
            assertNotNull("redirect failed", pe);
        }
    }

}

There error I'm getting is below.  I'm able to test just about
everything - it's just the loading of pages that's failing (so far).

java.lang.NullPointerException
        at 
org.apache.tapestry.engine.RequestCycle.loadPage(RequestCycle.java:290)
        at 
org.apache.tapestry.engine.RequestCycle.getPage(RequestCycle.java:251)
        at org.appfuse.web.UserForm.save(UserForm.java:70)
        at org.appfuse.web.UserFormTest.testSave(UserFormTest.java:55)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Thanks,

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to