You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2006/11/23 02:53:49 UTC

svn commit: r478432 - in /tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal: services/ParameterWorkerTest.java services/PersistentFieldManagerImplTest.java structure/PageImplTest.java

Author: hlship
Date: Wed Nov 22 17:53:48 2006
New Revision: 478432

URL: http://svn.apache.org/viewvc?view=rev&rev=478432
Log:
Make use of the EasyMock expect().andReturn() coding pattern.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/PageImplTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java?view=diff&rev=478432&r1=478431&r2=478432
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java Wed Nov 22 17:53:48 2006
@@ -12,525 +12,518 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.Loader;
-import javassist.LoaderClassPath;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.internal.InternalComponentResources;
-import org.apache.tapestry.internal.test.InternalBaseTestCase;
+package org.apache.tapestry.internal.services;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.Loader;
+import javassist.LoaderClassPath;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.internal.InternalComponentResources;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.ioc.internal.services.PropertyAccessImpl;
-import org.apache.tapestry.ioc.services.PropertyAccess;
-import org.apache.tapestry.model.MutableComponentModel;
-import org.apache.tapestry.runtime.Component;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.Test;
-
-/**
- * There's no point in trying to unit test the code generated by
- * {@link org.apache.tapestry.internal.services.ParameterWorker}. Instead, we excercize
- * ParameterWorker, and test that the generated code works correctly in a number of scenarios.
- * 
- * 
- */
-public class ParameterWorkerTest extends InternalBaseTestCase
-{
-    private final ClassLoader _contextClassLoader = Thread.currentThread().getContextClassLoader();
-
-    private PropertyAccess _access = new PropertyAccessImpl();
-
-    @AfterClass
-    public void cleanup()
-    {
-        _access = null;
-    }
-
-    @Test
-    public void page_load_behavior() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        assertNotNull(setupForIntegrationTest(resources));
-    }
-
-    @Test
-    public void invariant_object_retained_after_detach() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        // On first invocation, the resources are queried.
-
-        String value = "To be in Tapestry in the spring time ...";
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "invariantObject", true);
-        train_readParameter(resources, "invariantObject", String.class, value);
-
-        replay();
-
-        assertSame(_access.get(component, "invariantObject"), value);
-
-        verify();
-
-        // No further training needed here.
-
-        replay();
-
-        // Still cached ...
-
-        assertSame(_access.get(component, "invariantObject"), value);
-
-        component.postRenderCleanup();
-
-        // Still cached ...
-
-        assertSame(_access.get(component, "invariantObject"), value);
-
-        component.containingPageDidDetach();
-
-        // Still cached ...
-
-        assertSame(_access.get(component, "invariantObject"), value);
-
-        verify();
-    }
-
-    @Test
-    public void invariant_primitive_retained_after_detach() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        // On first invocation, the resources are queried.
-
-        long value = 123456;
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "invariantPrimitive", true);
-        train_readParameter(resources, "invariantPrimitive", long.class, value);
-
-        replay();
-
-        assertEquals(_access.get(component, "invariantPrimitive"), value);
-
-        verify();
-
-        // No further training needed here.
-
-        replay();
-
-        // Still cached ...
-
-        assertEquals(_access.get(component, "invariantPrimitive"), value);
-
-        component.postRenderCleanup();
-
-        // Still cached ...
-
-        assertEquals(_access.get(component, "invariantPrimitive"), value);
-
-        verify();
-    }
-
-    /**
-     * This actually checks several things:
-     * <ul>
-     * <li>Changing a parameter property before the page loads doesn't update the binding</li>
-     * <li>Changing a parameter property changes the property AND the default value for the
-     * property</li>
-     * <li>Unbound parameters to do not attempt to read or update their bindings (they'll be
-     * optional)</li>
-     * </ul>
-     * 
-     * @throws Exception
-     */
-    @Test
-    public void changes_before_load_become_defaults_and_dont_update_bindings() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        train_isLoaded(resources, false);
-
-        replay();
-
-        assertNull(_access.get(component, "object"));
-
-        verify();
-
-        train_isLoaded(resources, false);
-
-        replay();
-
-        _access.set(component, "object", "new-default");
-
-        verify();
-
-        train_isLoaded(resources, false);
-
-        replay();
-
-        assertEquals(_access.get(component, "object"), "new-default");
-
-        verify();
-
-        trainForPageDidLoad(resources);
-
-        replay();
-
-        component.containingPageDidLoad();
-
-        verify();
-
-        // For the set ...
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", false);
-        train_isRendering(resources, false);
-
-        // For the first read ...
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", false);
-
-        // For the second read (after postRenderCleanup) ...
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", false);
-
-        replay();
-
-        _access.set(component, "object", "new-value");
-        assertEquals(_access.get(component, "object"), "new-value");
-
-        component.postRenderCleanup();
-
-        assertEquals(_access.get(component, "object"), "new-default");
-
-        verify();
-    }
-
-    @Test
-    public void cached_object_read() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "first");
-        train_isRendering(resources, false);
-
-        replay();
-
-        assertEquals(_access.get(component, "object"), "first");
-
-        verify();
-
-        // Keeps re-reading the parameter when not rendering.
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "second");
-        train_isRendering(resources, false);
-
-        replay();
-
-        assertEquals(_access.get(component, "object"), "second");
-
-        verify();
-
-        // Now, when rendering is active, the value is cached
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "third");
-        train_isRendering(resources, true);
-
-        replay();
-
-        assertEquals(_access.get(component, "object"), "third");
-
-        // Does not cause readParameter() to be invoked:
-
-        assertEquals(_access.get(component, "object"), "third");
-
-        verify();
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "fourth");
-        train_isRendering(resources, false);
-
-        replay();
-
-        component.postRenderCleanup();
-
-        assertEquals(_access.get(component, "object"), "fourth");
-
-        verify();
-    }
-
-    @Test
-    public void cached_object_write() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        resources.writeParameter("object", "first");
-        train_isRendering(resources, false);
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "second");
-        train_isRendering(resources, false);
-
-        replay();
-
-        _access.set(component, "object", "first");
-        assertEquals(_access.get(component, "object"), "second");
-
-        verify();
-
-        // Now try during rendering ...
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        resources.writeParameter("object", "third");
-        train_isRendering(resources, true);
-
-        replay();
-
-        _access.set(component, "object", "third");
-        assertEquals(_access.get(component, "object"), "third");
-
-        verify();
-
-        // And the cached value is lost after rendering is complete.
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "object", true);
-        train_readParameter(resources, "object", String.class, "fourth");
-        train_isRendering(resources, false);
-
-        replay();
-
-        component.postRenderCleanup();
-
-        assertEquals(_access.get(component, "object"), "fourth");
-
-        verify();
-    }
-
-    @Test
-    public void cached_primitive_write() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "primitive", true);
-        resources.writeParameter("primitive", 321);
-
-        train_isRendering(resources, false);
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "primitive", true);
-        train_readParameter(resources, "primitive", int.class, 123);
-        train_isRendering(resources, false);
-
-        replay();
-
-        _access.set(component, "primitive", 321);
-        assertEquals(_access.get(component, "primitive"), 123);
-
-        verify();
-
-        // Now try during rendering ...
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "primitive", true);
-        resources.writeParameter("primitive", 567);
-        train_isRendering(resources, true);
-
-        replay();
-
-        _access.set(component, "primitive", 567);
-        assertEquals(_access.get(component, "primitive"), 567);
-
-        verify();
-
-        // And the cached value is lost after rendering is complete.
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "primitive", true);
-        train_readParameter(resources, "primitive", int.class, 890);
-        train_isRendering(resources, false);
-
-        replay();
-
-        component.postRenderCleanup();
-
-        assertEquals(_access.get(component, "primitive"), 890);
-
-        verify();
-    }
-
-    protected final void train_isLoaded(InternalComponentResources resources, boolean isLoaded)
-    {
-        resources.isLoaded();
-        setReturnValue(isLoaded);
-    }
-
-    @Test
-    public void uncached_object_read() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        // Notice no check for isRendering() since that is irrelevant to uncached parameters.
-        // Also note difference between field name and parameter name, due to Parameter.name() being
-        // specified.
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "uncached", true);
-        train_readParameter(resources, "uncached", String.class, "first");
-        train_isLoaded(resources, true);
-        train_isBound(resources, "uncached", true);
-        train_readParameter(resources, "uncached", String.class, "second");
-
-        replay();
-
-        assertEquals(_access.get(component, "uncachedObject"), "first");
-        assertEquals(_access.get(component, "uncachedObject"), "second");
-
-        verify();
-    }
-
-    protected void train_isBound(InternalComponentResources resources, String parameterName,
-            boolean isBound)
-    {
-        resources.isBound(parameterName);
-        setReturnValue(isBound);
-    }
-
-    @Test
-    public void uncached_object_write() throws Exception
-    {
-        InternalComponentResources resources = newInternalComponentResources();
-
-        Component component = setupForIntegrationTest(resources);
-
-        // Notice no check for isRendering() since that is irrelevant to uncached parameters.
-        // Also note difference between field name and parameter name, due to Parameter.name() being
-        // specified.
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "uncached", true);
-        resources.writeParameter("uncached", "first");
-
-        train_isLoaded(resources, true);
-        train_isBound(resources, "uncached", true);
-        train_readParameter(resources, "uncached", String.class, "second");
-
-        replay();
-
-        _access.set(component, "uncachedObject", "first");
-        assertEquals(_access.get(component, "uncachedObject"), "second");
-
-        verify();
-    }
-
-    protected final void train_isRendering(InternalComponentResources resources, boolean rendering)
-    {
-        resources.isRendering();
-        setReturnValue(rendering);
-    }
-
-    protected final <T> void train_readParameter(InternalComponentResources resources,
-            String parameterName, Class<T> expectedType, T value)
-    {
-        resources.readParameter(parameterName, expectedType);
-        setReturnValue(value);
-    }
-
-    private Component setupForIntegrationTest(InternalComponentResources resources)
-            throws Exception
-    {
-        Log log = newLog();
-        ClassPool pool = new ClassPool();
-        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
-        pool.appendClassPath(new LoaderClassPath(contextLoader));
-
-        Loader loader = new Loader(contextLoader, pool);
-
-        loader.delegateLoadingOf("org.apache.tapestry.");
-
-        CtClass ctClass = pool.get(ParameterComponent.class.getName());
-        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
-                _contextClassLoader, log, null);
-
-        MutableComponentModel model = newMutableComponentModel();
-
-        model.addParameter("invariantObject", false);
-        model.addParameter("invariantPrimitive", false);
-        model.addParameter("object", false);
-        model.addParameter("primitive", true);
-        model.addParameter("uncached", false);
-
-        replay();
-
-        new ParameterWorker().transform(transformation, model);
-
-        verify();
-
-        transformation.finish();
-
-        // System.out.println("Transformation: " + transformation);
-
-        Class transformedClass = pool.toClass(ctClass, loader);
-
-        Instantiator instantiator = transformation.createInstantiator(transformedClass);
-
-        trainForPageDidLoad(resources);
-
-        replay();
-
-        Component component = instantiator.newInstance(resources);
-
-        component.containingPageDidLoad();
-
-        verify();
-
-        return component;
-    }
-
-    private void trainForPageDidLoad(InternalComponentResources resources)
-    {
-        train_isInvariant(resources, "invariantObject", true);
-        train_isInvariant(resources, "invariantPrimitive", true);
-        train_isInvariant(resources, "object", false);
-        train_isInvariant(resources, "primitive", false);
-        train_isInvariant(resources, "uncached", false);
-    }
-
-    protected final void train_isInvariant(InternalComponentResources resources,
-            String parameterName, boolean invariant)
-    {
-        resources.isInvariant(parameterName);
-        setReturnValue(invariant);
-    }
-}
+import org.apache.tapestry.ioc.services.PropertyAccess;
+import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.runtime.Component;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+/**
+ * There's no point in trying to unit test the code generated by
+ * {@link org.apache.tapestry.internal.services.ParameterWorker}. Instead, we excercize
+ * ParameterWorker, and test that the generated code works correctly in a number of scenarios.
+ */
+public class ParameterWorkerTest extends InternalBaseTestCase
+{
+    private final ClassLoader _contextClassLoader = Thread.currentThread().getContextClassLoader();
+
+    private PropertyAccess _access = new PropertyAccessImpl();
+
+    @AfterClass
+    public void cleanup()
+    {
+        _access = null;
+    }
+
+    @Test
+    public void page_load_behavior() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        assertNotNull(setupForIntegrationTest(resources));
+    }
+
+    @Test
+    public void invariant_object_retained_after_detach() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        // On first invocation, the resources are queried.
+
+        String value = "To be in Tapestry in the spring time ...";
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "invariantObject", true);
+        train_readParameter(resources, "invariantObject", String.class, value);
+
+        replay();
+
+        assertSame(_access.get(component, "invariantObject"), value);
+
+        verify();
+
+        // No further training needed here.
+
+        replay();
+
+        // Still cached ...
+
+        assertSame(_access.get(component, "invariantObject"), value);
+
+        component.postRenderCleanup();
+
+        // Still cached ...
+
+        assertSame(_access.get(component, "invariantObject"), value);
+
+        component.containingPageDidDetach();
+
+        // Still cached ...
+
+        assertSame(_access.get(component, "invariantObject"), value);
+
+        verify();
+    }
+
+    @Test
+    public void invariant_primitive_retained_after_detach() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        // On first invocation, the resources are queried.
+
+        long value = 123456;
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "invariantPrimitive", true);
+        train_readParameter(resources, "invariantPrimitive", long.class, value);
+
+        replay();
+
+        assertEquals(_access.get(component, "invariantPrimitive"), value);
+
+        verify();
+
+        // No further training needed here.
+
+        replay();
+
+        // Still cached ...
+
+        assertEquals(_access.get(component, "invariantPrimitive"), value);
+
+        component.postRenderCleanup();
+
+        // Still cached ...
+
+        assertEquals(_access.get(component, "invariantPrimitive"), value);
+
+        verify();
+    }
+
+    /**
+     * This actually checks several things:
+     * <ul>
+     * <li>Changing a parameter property before the page loads doesn't update the binding</li>
+     * <li>Changing a parameter property changes the property AND the default value for the
+     * property</li>
+     * <li>Unbound parameters to do not attempt to read or update their bindings (they'll be
+     * optional)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void changes_before_load_become_defaults_and_dont_update_bindings() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        train_isLoaded(resources, false);
+
+        replay();
+
+        assertNull(_access.get(component, "object"));
+
+        verify();
+
+        train_isLoaded(resources, false);
+
+        replay();
+
+        _access.set(component, "object", "new-default");
+
+        verify();
+
+        train_isLoaded(resources, false);
+
+        replay();
+
+        assertEquals(_access.get(component, "object"), "new-default");
+
+        verify();
+
+        trainForPageDidLoad(resources);
+
+        replay();
+
+        component.containingPageDidLoad();
+
+        verify();
+
+        // For the set ...
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", false);
+        train_isRendering(resources, false);
+
+        // For the first read ...
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", false);
+
+        // For the second read (after postRenderCleanup) ...
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", false);
+
+        replay();
+
+        _access.set(component, "object", "new-value");
+        assertEquals(_access.get(component, "object"), "new-value");
+
+        component.postRenderCleanup();
+
+        assertEquals(_access.get(component, "object"), "new-default");
+
+        verify();
+    }
+
+    @Test
+    public void cached_object_read() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "first");
+        train_isRendering(resources, false);
+
+        replay();
+
+        assertEquals(_access.get(component, "object"), "first");
+
+        verify();
+
+        // Keeps re-reading the parameter when not rendering.
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "second");
+        train_isRendering(resources, false);
+
+        replay();
+
+        assertEquals(_access.get(component, "object"), "second");
+
+        verify();
+
+        // Now, when rendering is active, the value is cached
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "third");
+        train_isRendering(resources, true);
+
+        replay();
+
+        assertEquals(_access.get(component, "object"), "third");
+
+        // Does not cause readParameter() to be invoked:
+
+        assertEquals(_access.get(component, "object"), "third");
+
+        verify();
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "fourth");
+        train_isRendering(resources, false);
+
+        replay();
+
+        component.postRenderCleanup();
+
+        assertEquals(_access.get(component, "object"), "fourth");
+
+        verify();
+    }
+
+    @Test
+    public void cached_object_write() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        resources.writeParameter("object", "first");
+        train_isRendering(resources, false);
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "second");
+        train_isRendering(resources, false);
+
+        replay();
+
+        _access.set(component, "object", "first");
+        assertEquals(_access.get(component, "object"), "second");
+
+        verify();
+
+        // Now try during rendering ...
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        resources.writeParameter("object", "third");
+        train_isRendering(resources, true);
+
+        replay();
+
+        _access.set(component, "object", "third");
+        assertEquals(_access.get(component, "object"), "third");
+
+        verify();
+
+        // And the cached value is lost after rendering is complete.
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "object", true);
+        train_readParameter(resources, "object", String.class, "fourth");
+        train_isRendering(resources, false);
+
+        replay();
+
+        component.postRenderCleanup();
+
+        assertEquals(_access.get(component, "object"), "fourth");
+
+        verify();
+    }
+
+    @Test
+    public void cached_primitive_write() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "primitive", true);
+        resources.writeParameter("primitive", 321);
+
+        train_isRendering(resources, false);
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "primitive", true);
+        train_readParameter(resources, "primitive", int.class, 123);
+        train_isRendering(resources, false);
+
+        replay();
+
+        _access.set(component, "primitive", 321);
+        assertEquals(_access.get(component, "primitive"), 123);
+
+        verify();
+
+        // Now try during rendering ...
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "primitive", true);
+        resources.writeParameter("primitive", 567);
+        train_isRendering(resources, true);
+
+        replay();
+
+        _access.set(component, "primitive", 567);
+        assertEquals(_access.get(component, "primitive"), 567);
+
+        verify();
+
+        // And the cached value is lost after rendering is complete.
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "primitive", true);
+        train_readParameter(resources, "primitive", int.class, 890);
+        train_isRendering(resources, false);
+
+        replay();
+
+        component.postRenderCleanup();
+
+        assertEquals(_access.get(component, "primitive"), 890);
+
+        verify();
+    }
+
+    protected final void train_isLoaded(InternalComponentResources resources, boolean isLoaded)
+    {
+        expect(resources.isLoaded()).andReturn(isLoaded);
+    }
+
+    @Test
+    public void uncached_object_read() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        // Notice no check for isRendering() since that is irrelevant to uncached parameters.
+        // Also note difference between field name and parameter name, due to Parameter.name() being
+        // specified.
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "uncached", true);
+        train_readParameter(resources, "uncached", String.class, "first");
+        train_isLoaded(resources, true);
+        train_isBound(resources, "uncached", true);
+        train_readParameter(resources, "uncached", String.class, "second");
+
+        replay();
+
+        assertEquals(_access.get(component, "uncachedObject"), "first");
+        assertEquals(_access.get(component, "uncachedObject"), "second");
+
+        verify();
+    }
+
+    protected void train_isBound(InternalComponentResources resources, String parameterName,
+            boolean isBound)
+    {
+        expect(resources.isBound(parameterName)).andReturn(isBound);
+    }
+
+    @Test
+    public void uncached_object_write() throws Exception
+    {
+        InternalComponentResources resources = newInternalComponentResources();
+
+        Component component = setupForIntegrationTest(resources);
+
+        // Notice no check for isRendering() since that is irrelevant to uncached parameters.
+        // Also note difference between field name and parameter name, due to Parameter.name() being
+        // specified.
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "uncached", true);
+        resources.writeParameter("uncached", "first");
+
+        train_isLoaded(resources, true);
+        train_isBound(resources, "uncached", true);
+        train_readParameter(resources, "uncached", String.class, "second");
+
+        replay();
+
+        _access.set(component, "uncachedObject", "first");
+        assertEquals(_access.get(component, "uncachedObject"), "second");
+
+        verify();
+    }
+
+    protected final void train_isRendering(InternalComponentResources resources, boolean rendering)
+    {
+        expect(resources.isRendering()).andReturn(rendering);
+    }
+
+    protected final <T> void train_readParameter(InternalComponentResources resources,
+            String parameterName, Class<T> expectedType, T value)
+    {
+        expect(resources.readParameter(parameterName, expectedType)).andReturn(value);
+    }
+
+    private Component setupForIntegrationTest(InternalComponentResources resources)
+            throws Exception
+    {
+        Log log = newLog();
+        ClassPool pool = new ClassPool();
+        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
+        pool.appendClassPath(new LoaderClassPath(contextLoader));
+
+        Loader loader = new Loader(contextLoader, pool);
+
+        loader.delegateLoadingOf("org.apache.tapestry.");
+
+        CtClass ctClass = pool.get(ParameterComponent.class.getName());
+        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
+                _contextClassLoader, log, null);
+
+        MutableComponentModel model = newMutableComponentModel();
+
+        model.addParameter("invariantObject", false);
+        model.addParameter("invariantPrimitive", false);
+        model.addParameter("object", false);
+        model.addParameter("primitive", true);
+        model.addParameter("uncached", false);
+
+        replay();
+
+        new ParameterWorker().transform(transformation, model);
+
+        verify();
+
+        transformation.finish();
+
+        // System.out.println("Transformation: " + transformation);
+
+        Class transformedClass = pool.toClass(ctClass, loader);
+
+        Instantiator instantiator = transformation.createInstantiator(transformedClass);
+
+        trainForPageDidLoad(resources);
+
+        replay();
+
+        Component component = instantiator.newInstance(resources);
+
+        component.containingPageDidLoad();
+
+        verify();
+
+        return component;
+    }
+
+    private void trainForPageDidLoad(InternalComponentResources resources)
+    {
+        train_isInvariant(resources, "invariantObject", true);
+        train_isInvariant(resources, "invariantPrimitive", true);
+        train_isInvariant(resources, "object", false);
+        train_isInvariant(resources, "primitive", false);
+        train_isInvariant(resources, "uncached", false);
+    }
+
+    protected final void train_isInvariant(InternalComponentResources resources,
+            String parameterName, boolean invariant)
+    {
+        expect(resources.isInvariant(parameterName)).andReturn(invariant);
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java?view=diff&rev=478432&r1=478431&r2=478432
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java Wed Nov 22 17:53:48 2006
@@ -12,120 +12,118 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
-
+package org.apache.tapestry.internal.services;
+
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.tapestry.internal.test.InternalBaseTestCase;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry.services.PersistentFieldBundle;
-import org.apache.tapestry.services.PersistentFieldChange;
-import org.apache.tapestry.services.PersistentFieldManager;
-import org.apache.tapestry.services.PersistentFieldStrategy;
-import org.testng.annotations.Test;
-
-public class PersistentFieldManagerImplTest extends InternalBaseTestCase
-{
-    @Test
-    public void post_change_with_unknown_strategy()
-    {
-        PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
-        PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
-
-        Map<String, PersistentFieldStrategy> strategies = CollectionFactory.newMap();
-        strategies.put("foo", strat1);
-        strategies.put("bar", strat2);
-
-        replay();
-
-        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
-
-        try
-        {
-            manager.postChange("foo.Bar", null, "field", "braveheart", null);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(
-                    ex.getMessage(),
-                    "\'braveheart\' is not a defined persistent strategy.  Defined stategies: bar, foo.");
-        }
-
-        verify();
-    }
-
-    @Test
-    public void post_change()
-    {
-        PersistentFieldStrategy strat = newPersistentFieldStrategy();
-
-        Map<String, PersistentFieldStrategy> strategies = CollectionFactory.newMap();
-        strategies.put("foo", strat);
-
-        Object value = new Object();
-
-        strat.postChange("foo.Bar", "nested", "field", value);
-
-        replay();
-
-        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
-
-        manager.postChange("foo.Bar", "nested", "field", "foo", value);
-
-        verify();
-    }
-
-    private PersistentFieldStrategy newPersistentFieldStrategy()
-    {
-        return newMock(PersistentFieldStrategy.class);
-    }
-
-    @Test
-    public void gather_changes()
-    {
-        Object value1 = new Object();
-        Object value2 = new Object();
-
-        PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
-
-        Collection<PersistentFieldChange> changes1 = newList();
-        changes1.add(new PersistentFieldChangeImpl("component", "field1", value1));
-
-        PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
-
-        Collection<PersistentFieldChange> changes2 = newList();
-        changes2.add(new PersistentFieldChangeImpl("component", "field2", value2));
-
-        // We don't know the exact order the strategies will be ordered in the map,
-        // so we can't guarantee the order the strategies will be invoked.
-
-        getMocksControl().checkOrder(false);
-
-        strat1.gatherFieldChanges("foo.Bar");
-        setReturnValue(changes1);
-
-        strat2.gatherFieldChanges("foo.Bar");
-        setReturnValue(changes2);
-
-        replay();
-
-        Map<String, PersistentFieldStrategy> strategies = newMap();
-
-        strategies.put("alpha", strat1);
-        strategies.put("beta", strat2);
-
-        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
-
-        PersistentFieldBundle bundle = manager.gatherChanges("foo.Bar");
-
-        assertSame(bundle.getValue("component", "field1"), value1);
-        assertSame(bundle.getValue("component", "field2"), value2);
-
-        verify();
-    }
-}
+import org.apache.tapestry.services.PersistentFieldBundle;
+import org.apache.tapestry.services.PersistentFieldChange;
+import org.apache.tapestry.services.PersistentFieldManager;
+import org.apache.tapestry.services.PersistentFieldStrategy;
+import org.testng.annotations.Test;
+
+public class PersistentFieldManagerImplTest extends InternalBaseTestCase
+{
+    @Test
+    public void post_change_with_unknown_strategy()
+    {
+        PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
+        PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
+
+        Map<String, PersistentFieldStrategy> strategies = CollectionFactory.newMap();
+        strategies.put("foo", strat1);
+        strategies.put("bar", strat2);
+
+        replay();
+
+        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
+
+        try
+        {
+            manager.postChange("foo.Bar", null, "field", "braveheart", null);
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertEquals(
+                    ex.getMessage(),
+                    "\'braveheart\' is not a defined persistent strategy.  Defined stategies: bar, foo.");
+        }
+
+        verify();
+    }
+
+    @Test
+    public void post_change()
+    {
+        PersistentFieldStrategy strat = newPersistentFieldStrategy();
+
+        Map<String, PersistentFieldStrategy> strategies = CollectionFactory.newMap();
+        strategies.put("foo", strat);
+
+        Object value = new Object();
+
+        strat.postChange("foo.Bar", "nested", "field", value);
+
+        replay();
+
+        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
+
+        manager.postChange("foo.Bar", "nested", "field", "foo", value);
+
+        verify();
+    }
+
+    private PersistentFieldStrategy newPersistentFieldStrategy()
+    {
+        return newMock(PersistentFieldStrategy.class);
+    }
+
+    @Test
+    public void gather_changes()
+    {
+        Object value1 = new Object();
+        Object value2 = new Object();
+
+        PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
+
+        Collection<PersistentFieldChange> changes1 = newList();
+        changes1.add(new PersistentFieldChangeImpl("component", "field1", value1));
+
+        PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
+
+        Collection<PersistentFieldChange> changes2 = newList();
+        changes2.add(new PersistentFieldChangeImpl("component", "field2", value2));
+
+        // We don't know the exact order the strategies will be ordered in the map,
+        // so we can't guarantee the order the strategies will be invoked.
+
+        getMocksControl().checkOrder(false);
+
+        expect(strat1.gatherFieldChanges("foo.Bar")).andReturn(changes1);
+
+        expect(strat2.gatherFieldChanges("foo.Bar")).andReturn(changes2);
+
+        replay();
+
+        Map<String, PersistentFieldStrategy> strategies = newMap();
+
+        strategies.put("alpha", strat1);
+        strategies.put("beta", strat2);
+
+        PersistentFieldManager manager = new PersistentFieldManagerImpl(strategies);
+
+        PersistentFieldBundle bundle = manager.gatherChanges("foo.Bar");
+
+        assertSame(bundle.getValue("component", "field1"), value1);
+        assertSame(bundle.getValue("component", "field2"), value2);
+
+        verify();
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/PageImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/PageImplTest.java?view=diff&rev=478432&r1=478431&r2=478432
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/PageImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/PageImplTest.java Wed Nov 22 17:53:48 2006
@@ -12,172 +12,171 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.structure;
-
-import static org.easymock.EasyMock.contains;
-import static org.easymock.EasyMock.same;
-
-import java.util.Locale;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.runtime.PageLifecycleListener;
-import org.testng.annotations.Test;
-
-public class PageImplTest extends InternalBaseTestCase
-{
-    private final Locale _locale = Locale.ENGLISH;
-
-    private static final String PAGE_NAME = "org.foo.pages.MyPage";
-
-    @Test
-    public void accessor_methods()
-    {
-        ComponentPageElement root = newMock(ComponentPageElement.class);
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-
-        assertNull(page.getRootElement());
-
-        page.setRootElement(root);
-
-        assertEquals(page.getName(), PAGE_NAME);
-        assertSame(page.getLocale(), _locale);
-        assertSame(page.getRootElement(), root);
-
-        verify();
-    }
-
-    @Test
-    public void detach_notification()
-    {
-        PageLifecycleListener listener1 = newPageLifecycle();
-        PageLifecycleListener listener2 = newPageLifecycle();
-
-        listener1.containingPageDidDetach();
-        listener2.containingPageDidDetach();
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-
-        page.addLifecycleListener(listener1);
-        page.addLifecycleListener(listener2);
-
-        assertFalse(page.detached());
-
-        verify();
-    }
-
-    /** Also checks that listeners are invoked, even if the page is dirty. */
-    @Test
-    public void detach_dirty_if_dirty_count_non_zero()
-    {
-        PageLifecycleListener listener = newPageLifecycle();
-
-        listener.containingPageDidDetach();
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-
-        page.addLifecycleListener(listener);
-
-        page.incrementDirtyCount();
-
-        assertTrue(page.detached());
-
-        verify();
-    }
-
-    /**
-     * Also checks that all listeners are invoked, even if one of them throws an exception.
-     */
-    @Test
-    public void detach_dirty_if_listener_throws_exception()
-    {
-        ComponentPageElement element = newComponentPageElement();
-        Log log = newLog();
-        PageLifecycleListener listener1 = newPageLifecycle();
-        PageLifecycleListener listener2 = newPageLifecycle();
-        RuntimeException t = new RuntimeException("Listener detach exception.");
-
-        train_getLog(element, log);
-
-        listener1.containingPageDidDetach();
-        setThrowable(t);
-
-        log.error(contains("failed during page detach"), same(t));
-
-        listener2.containingPageDidDetach();
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-        page.setRootElement(element);
-
-        page.addLifecycleListener(listener1);
-        page.addLifecycleListener(listener2);
-
-        assertTrue(page.detached());
-
-        verify();
-
-    }
-
-    protected final void train_getLog(ComponentPageElement element, Log log)
-    {
-        element.getLog();
-        setReturnValue(log);
-    }
-
-    @Test
-    public void attach_notification()
-    {
-
-        PageLifecycleListener listener1 = newPageLifecycle();
-        PageLifecycleListener listener2 = newPageLifecycle();
-
-        listener1.containingPageDidAttach();
-        listener2.containingPageDidAttach();
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-
-        page.addLifecycleListener(listener1);
-        page.addLifecycleListener(listener2);
-
-        page.attached();
-
-        verify();
-    }
-
-    private PageLifecycleListener newPageLifecycle()
-    {
-        return newMock(PageLifecycleListener.class);
-    }
-
-    @Test
-    public void load_notification()
-    {
-        PageLifecycleListener listener1 = newPageLifecycle();
-        PageLifecycleListener listener2 = newPageLifecycle();
-
-        listener1.containingPageDidLoad();
-        listener2.containingPageDidLoad();
-
-        replay();
-
-        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
-
-        page.addLifecycleListener(listener1);
-        page.addLifecycleListener(listener2);
-
-        page.loaded();
-
-        verify();
-    }
-}
+package org.apache.tapestry.internal.structure;
+
+import static org.easymock.EasyMock.contains;
+import static org.easymock.EasyMock.same;
+
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.runtime.PageLifecycleListener;
+import org.testng.annotations.Test;
+
+public class PageImplTest extends InternalBaseTestCase
+{
+    private final Locale _locale = Locale.ENGLISH;
+
+    private static final String PAGE_NAME = "org.foo.pages.MyPage";
+
+    @Test
+    public void accessor_methods()
+    {
+        ComponentPageElement root = newMock(ComponentPageElement.class);
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+
+        assertNull(page.getRootElement());
+
+        page.setRootElement(root);
+
+        assertEquals(page.getName(), PAGE_NAME);
+        assertSame(page.getLocale(), _locale);
+        assertSame(page.getRootElement(), root);
+
+        verify();
+    }
+
+    @Test
+    public void detach_notification()
+    {
+        PageLifecycleListener listener1 = newPageLifecycle();
+        PageLifecycleListener listener2 = newPageLifecycle();
+
+        listener1.containingPageDidDetach();
+        listener2.containingPageDidDetach();
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+
+        page.addLifecycleListener(listener1);
+        page.addLifecycleListener(listener2);
+
+        assertFalse(page.detached());
+
+        verify();
+    }
+
+    /** Also checks that listeners are invoked, even if the page is dirty. */
+    @Test
+    public void detach_dirty_if_dirty_count_non_zero()
+    {
+        PageLifecycleListener listener = newPageLifecycle();
+
+        listener.containingPageDidDetach();
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+
+        page.addLifecycleListener(listener);
+
+        page.incrementDirtyCount();
+
+        assertTrue(page.detached());
+
+        verify();
+    }
+
+    /**
+     * Also checks that all listeners are invoked, even if one of them throws an exception.
+     */
+    @Test
+    public void detach_dirty_if_listener_throws_exception()
+    {
+        ComponentPageElement element = newComponentPageElement();
+        Log log = newLog();
+        PageLifecycleListener listener1 = newPageLifecycle();
+        PageLifecycleListener listener2 = newPageLifecycle();
+        RuntimeException t = new RuntimeException("Listener detach exception.");
+
+        train_getLog(element, log);
+
+        listener1.containingPageDidDetach();
+        setThrowable(t);
+
+        log.error(contains("failed during page detach"), same(t));
+
+        listener2.containingPageDidDetach();
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+        page.setRootElement(element);
+
+        page.addLifecycleListener(listener1);
+        page.addLifecycleListener(listener2);
+
+        assertTrue(page.detached());
+
+        verify();
+
+    }
+
+    protected final void train_getLog(ComponentPageElement element, Log log)
+    {
+        expect(element.getLog()).andReturn(log);
+    }
+
+    @Test
+    public void attach_notification()
+    {
+
+        PageLifecycleListener listener1 = newPageLifecycle();
+        PageLifecycleListener listener2 = newPageLifecycle();
+
+        listener1.containingPageDidAttach();
+        listener2.containingPageDidAttach();
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+
+        page.addLifecycleListener(listener1);
+        page.addLifecycleListener(listener2);
+
+        page.attached();
+
+        verify();
+    }
+
+    private PageLifecycleListener newPageLifecycle()
+    {
+        return newMock(PageLifecycleListener.class);
+    }
+
+    @Test
+    public void load_notification()
+    {
+        PageLifecycleListener listener1 = newPageLifecycle();
+        PageLifecycleListener listener2 = newPageLifecycle();
+
+        listener1.containingPageDidLoad();
+        listener2.containingPageDidLoad();
+
+        replay();
+
+        Page page = new PageImpl(PAGE_NAME, _locale, null, null);
+
+        page.addLifecycleListener(listener1);
+        page.addLifecycleListener(listener2);
+
+        page.loaded();
+
+        verify();
+    }
+}