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/19 18:58:02 UTC

svn commit: r476861 [2/2] - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/annotations/ main/java/org/apache/tapestry/dom/ main/java/org/apache/tapestry/internal/services/ main/java/org/apac...

Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java (from r476234, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectionProvider.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java?view=diff&rev=476861&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectionProvider.java&r1=476234&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectionProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java Sun Nov 19 09:58:01 2006
@@ -12,11 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
+package org.apache.tapestry.services;
 
 import org.apache.tapestry.ioc.ServiceLocator;
 import org.apache.tapestry.model.MutableComponentModel;
-import org.apache.tapestry.services.ClassTransformation;
 
 /**
  * Provides some form of injection when the value for an

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java Sun Nov 19 09:58:01 2006
@@ -26,6 +26,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.logging.Log;
+import org.apache.tapestry.ComponentEventHandler;
 import org.apache.tapestry.MarkupWriter;
 import org.apache.tapestry.annotations.AfterRender;
 import org.apache.tapestry.annotations.AfterRenderBody;
@@ -45,6 +46,7 @@
 import org.apache.tapestry.internal.services.ComponentClassFactoryImpl;
 import org.apache.tapestry.internal.services.ComponentClassResolverImpl;
 import org.apache.tapestry.internal.services.ComponentEventDispatcher;
+import org.apache.tapestry.internal.services.ComponentInstanceEventHandler;
 import org.apache.tapestry.internal.services.ComponentInstantiatorSource;
 import org.apache.tapestry.internal.services.ComponentLifecycleMethodWorker;
 import org.apache.tapestry.internal.services.ComponentResourcesInjectionProvider;
@@ -57,7 +59,6 @@
 import org.apache.tapestry.internal.services.InfrastructureImpl;
 import org.apache.tapestry.internal.services.InfrastructureManagerImpl;
 import org.apache.tapestry.internal.services.InjectWorker;
-import org.apache.tapestry.internal.services.InjectionProvider;
 import org.apache.tapestry.internal.services.InternalModule;
 import org.apache.tapestry.internal.services.LinkFactory;
 import org.apache.tapestry.internal.services.MarkupWriterImpl;
@@ -96,7 +97,10 @@
 import org.apache.tapestry.ioc.services.ClassFactory;
 import org.apache.tapestry.ioc.services.PipelineBuilder;
 import org.apache.tapestry.ioc.services.PropertyShadowBuilder;
+import org.apache.tapestry.ioc.services.StrategyBuilder;
 import org.apache.tapestry.ioc.services.TypeCoercer;
+import org.apache.tapestry.runtime.Component;
+import org.apache.tapestry.util.StrategyRegistry;
 
 /**
  * The root module for Tapestry.
@@ -124,6 +128,8 @@
 
     private final Environment _environment;
 
+    private final StrategyBuilder _strategyBuilder;
+
     // Yes, you can inject services defined by this module into this module. The service proxy is
     // created without instantiating the module itself. We're careful about making as many
     // service builder and contributor methods static as possible to avoid recursive build
@@ -138,7 +144,8 @@
     RequestPageCache requestPageCache, @InjectService("tapestry.internal.PageResponseRenderer")
     PageResponseRenderer pageResponseRenderer, @Inject("infrastructure:request")
     WebRequest request, @InjectService("Environment")
-    Environment environment)
+    Environment environment, @InjectService("tapestry.ioc.StrategyBuilder")
+    StrategyBuilder strategyBuilder)
     {
         _pipelineBuilder = pipelineBuilder;
         _shadowBuilder = shadowBuilder;
@@ -149,6 +156,7 @@
         _pageResponseRenderer = pageResponseRenderer;
         _request = request;
         _environment = environment;
+        _strategyBuilder = strategyBuilder;
     }
 
     private static <T> void add(Configuration<InfrastructureContribution> configuration,
@@ -407,7 +415,8 @@
 
     public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
             @InjectService("tapestry.internal.LinkFactory")
-            LinkFactory linkFactory)
+            LinkFactory linkFactory, @InjectService("ComponentEventHandler")
+            ComponentEventHandler componentEventHandler)
     {
         configuration.add(
                 "HTML",
@@ -415,8 +424,8 @@
 
         // This goes after the HTML one so that the "." in ".html" doesn't confuse it.
 
-        configuration.add("ComponentEvent", new ComponentEventDispatcher(_requestPageCache,
-                linkFactory), "after:HTML");
+        configuration.add("ComponentEvent", new ComponentEventDispatcher(componentEventHandler,
+                _requestPageCache, linkFactory), "after:HTML");
     }
 
     public static ComponentClassResolver buildComponentClassResolver(
@@ -679,5 +688,28 @@
             RequestPageCache pageCache)
     {
         return new ComponentSourceImpl(pageCache);
+    }
+
+    public ComponentEventHandler buildComponentEventHandler(
+            Map<Class, ComponentEventHandler> configuration)
+    {
+        StrategyRegistry<ComponentEventHandler> registry = StrategyRegistry.newInstance(
+                ComponentEventHandler.class,
+                configuration);
+
+        return _strategyBuilder.build(registry);
+    }
+
+    public void contributeComponentEventHandler(
+            MappedConfiguration<Class, ComponentEventHandler> configuration,
+            @InjectService("ComponentInstanceEventHandler")
+            ComponentEventHandler componentInstanceEventHandler)
+    {
+        configuration.add(Component.class, componentInstanceEventHandler);
+    }
+
+    public ComponentEventHandler buildComponentInstanceEventHandler(Log log)
+    {
+        return new ComponentInstanceEventHandler(_requestPageCache, log);
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/BaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/BaseTestCase.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/BaseTestCase.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/BaseTestCase.java Sun Nov 19 09:58:01 2006
@@ -12,588 +12,615 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.test;
-
-import static java.lang.Thread.sleep;
-import static org.apache.tapestry.internal.test.CodeEq.codeEq;
-import static org.easymock.EasyMock.eq;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.Binding;
-import org.apache.tapestry.ComponentResources;
-import org.apache.tapestry.Location;
-import org.apache.tapestry.MarkupWriter;
-import org.apache.tapestry.Resource;
-import org.apache.tapestry.annotations.Parameter;
-import org.apache.tapestry.internal.services.InjectionProvider;
-import org.apache.tapestry.ioc.Configuration;
-import org.apache.tapestry.ioc.LogSource;
-import org.apache.tapestry.ioc.MappedConfiguration;
-import org.apache.tapestry.ioc.ObjectCreator;
-import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.ServiceBuilderResources;
-import org.apache.tapestry.ioc.ServiceDecorator;
-import org.apache.tapestry.ioc.ServiceLocator;
-import org.apache.tapestry.ioc.ServiceResources;
-import org.apache.tapestry.ioc.def.ContributionDef;
-import org.apache.tapestry.ioc.def.DecoratorDef;
-import org.apache.tapestry.ioc.def.ModuleDef;
-import org.apache.tapestry.ioc.def.ServiceDef;
-import org.apache.tapestry.ioc.services.TypeCoercer;
-import org.apache.tapestry.model.ComponentModel;
-import org.apache.tapestry.model.MutableComponentModel;
-import org.apache.tapestry.model.ParameterModel;
-import org.apache.tapestry.services.BindingFactory;
-import org.apache.tapestry.services.ClassTransformation;
-import org.apache.tapestry.services.ComponentClassResolver;
-import org.apache.tapestry.services.MethodSignature;
-import org.apache.tapestry.services.WebRequest;
-import org.apache.tapestry.services.WebResponse;
-import org.apache.tapestry.services.WebSession;
-
-/**
- * Base test case that adds a number of convienience factory and training methods to
- * {@link org.apache.tapestry.test.TestBase}.
- */
-
-public abstract class BaseTestCase extends TestBase
-{
-    protected final void train_findFieldsWithAnnotation(ClassTransformation transformation,
-            Class<? extends Annotation> annotationClass, String... fieldNames)
-    {
-        train_findFieldsWithAnnotation(transformation, annotationClass, Arrays.asList(fieldNames));
-    }
-
-    protected final void train_findFieldsWithAnnotation(ClassTransformation transformation,
-            Class<? extends Annotation> annotationClass, List<String> fieldNames)
-    {
-        transformation.findFieldsWithAnnotation(annotationClass);
-        setReturnValue(fieldNames);
-    }
-
-    protected final <T extends Annotation> void train_getFieldAnnotation(
-            ClassTransformation transformation, String fieldName, Class<T> annotationClass,
-            T annotation)
-    {
-        transformation.getFieldAnnotation(fieldName, annotationClass);
-        setReturnValue(annotation);
-    }
-
-    protected final MutableComponentModel newMutableComponentModel()
-    {
-        return newMock(MutableComponentModel.class);
-    }
-
-    protected final ClassTransformation newClassTransformation()
-    {
-        return newMock(ClassTransformation.class);
-    }
-
-    protected final void train_addInjectedField(ClassTransformation ct, Class type,
-            String suggestedName, Object value, String fieldName)
-    {
-        ct.addInjectedField(type, suggestedName, value);
-        setReturnValue(fieldName);
-    }
-
-    protected final void train_findUnclaimedFields(ClassTransformation transformation,
-            String... fieldNames)
-    {
-        transformation.findUnclaimedFields();
-        setReturnValue(fieldNames);
-    }
-
-    /** Writes a change to a file. */
-    protected final void touch(File f) throws Exception
-    {
-        long startModified = f.lastModified();
-
-        while (true)
-        {
-            OutputStream o = new FileOutputStream(f);
-            o.write(0);
-            o.close();
-
-            long newModified = f.lastModified();
-
-            if (newModified != startModified)
-                return;
-
-            // Sleep 1/20 second and try again
-
-            sleep(50);
-        }
-    }
-
-    /**
-     * Creates a new class loader, whose parent is the thread's context class loader, but adds a
-     * single classpath root from the filesystem.
-     * 
-     * @see #createClasspathRoot()
-     */
-    protected final URLClassLoader newLoaderWithClasspathRoot(File rootDir)
-            throws MalformedURLException
-    {
-        String urlPath = rootDir.toURL().toString();
-        // URLs for folders must end with a slash to make URLClassLoader happy.
-        URL url = new URL(urlPath + "/");
-
-        return new URLClassLoader(new URL[]
-        { url }, Thread.currentThread().getContextClassLoader());
-    }
-
-    /**
-     * Creates a new temporary directory which can act as a classpath root.
-     * 
-     * @see #newLoaderWithClasspathRoot(File)
-     */
-    protected final File createClasspathRoot()
-    {
-        String temp = System.getProperty("java.io.tmpdir");
-        String rootDirPath = temp + "/" + UUID.randomUUID().toString();
-
-        return new File(rootDirPath);
-    }
-
-    protected final Resource newResource()
-    {
-        return newMock(Resource.class);
-    }
-
-    protected final void train_getServiceInterface(ServiceDef def, Class serviceInterface)
-    {
-        def.getServiceInterface();
-        setReturnValue(serviceInterface);
-    }
-
-    protected final void train_getServiceId(ServiceDef def, String serviceId)
-    {
-        def.getServiceId();
-        setReturnValue(serviceId);
-    }
-
-    protected final ServiceResources newServiceResources()
-    {
-        return newMock(ServiceResources.class);
-    }
-
-    protected final ServiceDef newServiceDef()
-    {
-        return newMock(ServiceDef.class);
-    }
-
-    protected final void train_getServiceLog(ServiceResources resources, Log log)
-    {
-        resources.getServiceLog();
-        setReturnValue(log);
-
-    }
-
-    protected final <T> void train_getService(ServiceLocator locator, String serviceId,
-            Class<T> serviceInterface, T service)
-    {
-        locator.getService(serviceId, serviceInterface);
-        setReturnValue(service);
-    }
-
-    protected final <T> void train_getService(ServiceLocator locator, Class<T> serviceInterface,
-            T service)
-    {
-        locator.getService(serviceInterface);
-        setReturnValue(service);
-    }
-
-    protected final void train_greateService(ObjectCreator creator, Object service)
-    {
-        creator.createObject();
-        setReturnValue(service);
-    }
-
-    protected final ObjectCreator newServiceCreator()
-    {
-        return newMock(ObjectCreator.class);
-    }
-
-    protected final void train_getServiceInterface(ServiceResources resources,
-            Class serviceInterface)
-    {
-        resources.getServiceInterface();
-        setReturnValue(serviceInterface);
-    }
-
-    protected final void train_getServiceId(ServiceResources resources, String serviceId)
-    {
-        resources.getServiceId();
-        setReturnValue(serviceId);
-    }
-
-    protected final void train_createInterceptor(ServiceDecorator decorator, Object coreObject,
-            Object interceptor)
-    {
-        decorator.createInterceptor(coreObject);
-        setReturnValue(interceptor);
-    }
-
-    protected final ServiceDecorator newServiceDecorator()
-    {
-        return newMock(ServiceDecorator.class);
-    }
-
-    protected final void train_getLog(LogSource source, String serviceId, Log log)
-    {
-        source.getLog(serviceId);
-        setReturnValue(log);
-    }
-
-    protected final Method findMethod(Class clazz, String methodName)
-    {
-        for (Method method : clazz.getMethods())
-        {
-            if (method.getName().equals(methodName))
-                return method;
-        }
-
-        throw new IllegalArgumentException(String.format(
-                "Class %s does not provide a method named '%s'.",
-                clazz.getName(),
-                methodName));
-    }
-
-    protected final Method findMethod(Object subject, String methodName)
-    {
-        return findMethod(subject.getClass(), methodName);
-    }
-
-    protected final Method findMethod(String methodName)
-    {
-        return findMethod(this, methodName);
-    }
-
-    protected final Configuration newConfiguration()
-    {
-        return newMock(Configuration.class);
-    }
-
-    protected final ServiceLocator newServiceLocator()
-    {
-        return newMock(ServiceLocator.class);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected final <T> OrderedConfiguration<T> newOrderedConfiguration()
-    {
-        return newMock(OrderedConfiguration.class);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected final <K, V> MappedConfiguration<K, V> newMappedConfiguration()
-    {
-        return newMock(MappedConfiguration.class);
-    }
-
-    protected final ContributionDef newContributionDef()
-    {
-        return newMock(ContributionDef.class);
-    }
-
-    protected final ServiceBuilderResources newServiceCreatorResources()
-    {
-        return newMock(ServiceBuilderResources.class);
-    }
-
-    protected final void train_getModuleId(ModuleDef def, String moduleId)
-    {
-        def.getModuleId();
-        setReturnValue(moduleId);
-    }
-
-    protected final ModuleDef newModuleDef()
-    {
-        return newMock(ModuleDef.class);
-    }
-
-    protected final void train_matches(DecoratorDef decoratorDef, ServiceDef serviceDef,
-            boolean matches)
-    {
-        decoratorDef.matches(serviceDef);
-        setReturnValue(matches);
-    }
-
-    protected final DecoratorDef newDecoratorDef()
-    {
-        return newMock(DecoratorDef.class);
-    }
-
-    /** Frequently used as a placeholder for an arbitrary service (but its nice and simple). */
-    protected final Runnable newRunnable()
-    {
-        return newMock(Runnable.class);
-    }
-
-    protected final Location newLocation()
-    {
-        return newMock(Location.class);
-    }
-
-    /** Combines a series of lines by forming a string with a line separator after each line. */
-    protected final String join(String... lines)
-    {
-        StringBuilder result = new StringBuilder();
-
-        for (String line : lines)
-        {
-            result.append(line);
-            result.append("\n");
-        }
-
-        return result.toString();
-    }
-
-    protected final ComponentClassResolver newComponentClassResolver()
-    {
-        return newMock(ComponentClassResolver.class);
-    }
-
-    protected final void train_newBinding(BindingFactory factory, String description,
-            ComponentResources component, String expression, Location l, Binding b)
-    {
-        factory.newBinding(description, component, expression, l);
-        setReturnValue(b);
-    }
-
-    protected final ComponentResources newComponentResources()
-    {
-        return newMock(ComponentResources.class);
-    }
-
-    protected final Binding newBinding()
-    {
-        return newMock(Binding.class);
-    }
-
-    protected final BindingFactory newBindingFactory()
-    {
-        return newMock(BindingFactory.class);
-    }
-
-    protected final ComponentModel newComponentModel()
-    {
-        return newMock(ComponentModel.class);
-    }
-
-    protected final void train_addMethod(ClassTransformation transformation,
-            MethodSignature signature, String... body)
-    {
-        transformation.addMethod(eq(signature), codeEq(join(body)));
-    }
-
-    protected final void train_newMemberName(ClassTransformation transformation, String suggested,
-            String name)
-    {
-        transformation.newMemberName(suggested);
-        setReturnValue(name);
-    }
-
-    protected final void train_extendMethod(ClassTransformation transformation,
-            MethodSignature signature, String... body)
-    {
-        transformation.extendMethod(eq(signature), codeEq(join(body)));
-    }
-
-    protected final void train_getResourcesFieldName(ClassTransformation transformation, String name)
-    {
-        transformation.getResourcesFieldName();
-        setReturnValue(name);
-    }
-
-    protected final void train_addField(ClassTransformation transformation, int modifiers,
-            String type, String suggestedName, String actualName)
-    {
-        transformation.addField(modifiers, type, suggestedName);
-        setReturnValue(actualName);
-    }
-
-    protected final void train_getFieldType(ClassTransformation transformation, String fieldName,
-            String type)
-    {
-        transformation.getFieldType(fieldName);
-        setReturnValue(type);
-
-    }
-
-    protected final void train_name(Parameter parameter, String name)
-    {
-        parameter.name();
-        setReturnValue(name);
-    }
-
-    protected final void train_findMethodsWithAnnotation(ClassTransformation tf,
-            Class<? extends Annotation> annotationType, List<MethodSignature> sigs)
-    {
-        tf.findMethodsWithAnnotation(annotationType);
-        setReturnValue(sigs);
-    }
-
-    protected final WebRequest newWebRequest()
-    {
-        return newMock(WebRequest.class);
-    }
-
-    protected final void train_provideInjection(InjectionProvider provider, String fieldName,
-            String fieldType, ServiceLocator locator, ClassTransformation transformation,
-            MutableComponentModel model, boolean result)
-    {
-        provider.provideInjection(fieldName, fieldType, locator, transformation, model);
-        setReturnValue(result);
-    }
-
-    protected final void train_toClass(ClassTransformation transformation, String type,
-            Class classForType)
-    {
-        transformation.toClass(type);
-        setReturnValue(classForType);
-    }
-
-    protected final ParameterModel newParameterModel()
-    {
-        return newMock(ParameterModel.class);
-    }
-
-    protected final void train_getComponentClassName(ComponentModel model, String className)
-    {
-        model.getComponentClassName();
-        setReturnValue(className).anyTimes();
-    }
-
-    protected final void train_isRequired(ParameterModel model, boolean isRequired)
-    {
-        model.isRequired();
-        setReturnValue(isRequired);
-    }
-
-    protected final void train_getParameterModel(ComponentModel model, String parameterName,
-            ParameterModel parameterModel)
-    {
-        model.getParameterModel(parameterName);
-        setReturnValue(parameterModel);
-    }
-
-    protected final void train_getParameterNames(ComponentModel model, String... names)
-    {
-        model.getParameterNames();
-        setReturnValue(Arrays.asList(names));
-    }
-
-    protected <S, T> void train_coerce(TypeCoercer coercer, S input, Class<T> expectedType,
-            T coercedValue)
-    {
-        coercer.coerce(input, expectedType);
-        setReturnValue(coercedValue);
-    }
-
-    protected final TypeCoercer newTypeCoercer()
-    {
-        return newMock(TypeCoercer.class);
-    }
-
-    protected final void train_isInvariant(Binding binding, boolean isInvariant)
-    {
-        binding.isInvariant();
-        setReturnValue(isInvariant);
-    }
-
-    protected final MarkupWriter newMarkupWriter()
-    {
-        return newMock(MarkupWriter.class);
-    }
-
-    protected final void train_get(Binding binding, Object value)
-    {
-        binding.get();
-        setReturnValue(value);
-    }
-
-    protected final void train_encodeURL(WebResponse response, String inputURL, String outputURL)
-    {
-        response.encodeURL(inputURL);
-        setReturnValue(outputURL);
-    }
-
-    protected final WebResponse newWebResponse()
-    {
-        return newMock(WebResponse.class);
-    }
-
-    protected void train_getAttribute(HttpSession session, String attributeName, Object value)
-    {
-        session.getAttribute(attributeName);
-        setReturnValue(value);
-    }
-
-    protected final HttpServletRequest newHttpServletRequest()
-    {
-        return newMock(HttpServletRequest.class);
-    }
-
-    protected final void train_getSession(HttpServletRequest request, boolean create,
-            HttpSession session)
-    {
-        request.getSession(create);
-        setReturnValue(session);
-    }
-
-    protected final HttpSession newHttpSession()
-    {
-        return newMock(HttpSession.class);
-    }
-
-    protected final void train_getAttributeNames(WebSession session, String prefix, String... names)
-    {
-        session.getAttributeNames(prefix);
-        setReturnValue(Arrays.asList(names));
-    }
-
-    protected final void train_getAttribute(WebSession session, String name, Object attribute)
-    {
-        session.getAttribute(name);
-        setReturnValue(attribute);
-    }
-
-    protected final WebSession newWebSession()
-    {
-        return newMock(WebSession.class);
-    }
-
-    protected final void train_getSession(WebRequest request, boolean create, WebSession session)
-    {
-        request.getSession(create);
-        setReturnValue(session);
-    }
-
-    protected final void train_encodeRedirectURL(WebResponse response, String URI, String encoded)
-    {
-        response.encodeRedirectURL(URI);
-        setReturnValue(encoded);
-    }
-
-    protected final <T extends Annotation> void train_getAnnotation(ClassTransformation transformation, Class<T> annotationClass, T annotation)
-    {
-        transformation.getAnnotation(annotationClass);
-        setReturnValue(annotation);
-    }
-}
+package org.apache.tapestry.test;
+
+import static java.lang.Thread.sleep;
+import static org.apache.tapestry.internal.test.CodeEq.codeEq;
+import static org.easymock.EasyMock.eq;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.Binding;
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.Location;
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.Resource;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.ioc.Configuration;
+import org.apache.tapestry.ioc.LogSource;
+import org.apache.tapestry.ioc.MappedConfiguration;
+import org.apache.tapestry.ioc.ObjectCreator;
+import org.apache.tapestry.ioc.OrderedConfiguration;
+import org.apache.tapestry.ioc.ServiceBuilderResources;
+import org.apache.tapestry.ioc.ServiceDecorator;
+import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ServiceResources;
+import org.apache.tapestry.ioc.def.ContributionDef;
+import org.apache.tapestry.ioc.def.DecoratorDef;
+import org.apache.tapestry.ioc.def.ModuleDef;
+import org.apache.tapestry.ioc.def.ServiceDef;
+import org.apache.tapestry.ioc.services.TypeCoercer;
+import org.apache.tapestry.model.ComponentModel;
+import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.model.ParameterModel;
+import org.apache.tapestry.runtime.Component;
+import org.apache.tapestry.services.BindingFactory;
+import org.apache.tapestry.services.ClassTransformation;
+import org.apache.tapestry.services.ComponentClassResolver;
+import org.apache.tapestry.services.InjectionProvider;
+import org.apache.tapestry.services.MethodSignature;
+import org.apache.tapestry.services.WebRequest;
+import org.apache.tapestry.services.WebResponse;
+import org.apache.tapestry.services.WebSession;
+
+/**
+ * Base test case that adds a number of convienience factory and training methods to
+ * {@link org.apache.tapestry.test.TestBase}.
+ */
+
+public abstract class BaseTestCase extends TestBase
+{
+    protected final void train_findFieldsWithAnnotation(ClassTransformation transformation,
+            Class<? extends Annotation> annotationClass, String... fieldNames)
+    {
+        train_findFieldsWithAnnotation(transformation, annotationClass, Arrays.asList(fieldNames));
+    }
+
+    protected final void train_findFieldsWithAnnotation(ClassTransformation transformation,
+            Class<? extends Annotation> annotationClass, List<String> fieldNames)
+    {
+        transformation.findFieldsWithAnnotation(annotationClass);
+        setReturnValue(fieldNames);
+    }
+
+    protected final <T extends Annotation> void train_getFieldAnnotation(
+            ClassTransformation transformation, String fieldName, Class<T> annotationClass,
+            T annotation)
+    {
+        transformation.getFieldAnnotation(fieldName, annotationClass);
+        setReturnValue(annotation);
+    }
+
+    protected final MutableComponentModel newMutableComponentModel()
+    {
+        return newMock(MutableComponentModel.class);
+    }
+
+    protected final ClassTransformation newClassTransformation()
+    {
+        return newMock(ClassTransformation.class);
+    }
+
+    protected final void train_addInjectedField(ClassTransformation ct, Class type,
+            String suggestedName, Object value, String fieldName)
+    {
+        ct.addInjectedField(type, suggestedName, value);
+        setReturnValue(fieldName);
+    }
+
+    protected final void train_findUnclaimedFields(ClassTransformation transformation,
+            String... fieldNames)
+    {
+        transformation.findUnclaimedFields();
+        setReturnValue(fieldNames);
+    }
+
+    /** Writes a change to a file. */
+    protected final void touch(File f) throws Exception
+    {
+        long startModified = f.lastModified();
+
+        while (true)
+        {
+            OutputStream o = new FileOutputStream(f);
+            o.write(0);
+            o.close();
+
+            long newModified = f.lastModified();
+
+            if (newModified != startModified)
+                return;
+
+            // Sleep 1/20 second and try again
+
+            sleep(50);
+        }
+    }
+
+    /**
+     * Creates a new class loader, whose parent is the thread's context class loader, but adds a
+     * single classpath root from the filesystem.
+     * 
+     * @see #createClasspathRoot()
+     */
+    protected final URLClassLoader newLoaderWithClasspathRoot(File rootDir)
+            throws MalformedURLException
+    {
+        String urlPath = rootDir.toURL().toString();
+        // URLs for folders must end with a slash to make URLClassLoader happy.
+        URL url = new URL(urlPath + "/");
+
+        return new URLClassLoader(new URL[]
+        { url }, Thread.currentThread().getContextClassLoader());
+    }
+
+    /**
+     * Creates a new temporary directory which can act as a classpath root.
+     * 
+     * @see #newLoaderWithClasspathRoot(File)
+     */
+    protected final File createClasspathRoot()
+    {
+        String temp = System.getProperty("java.io.tmpdir");
+        String rootDirPath = temp + "/" + UUID.randomUUID().toString();
+
+        return new File(rootDirPath);
+    }
+
+    protected final Resource newResource()
+    {
+        return newMock(Resource.class);
+    }
+
+    protected final void train_getServiceInterface(ServiceDef def, Class serviceInterface)
+    {
+        def.getServiceInterface();
+        setReturnValue(serviceInterface).atLeastOnce();
+    }
+
+    protected final void train_getServiceId(ServiceDef def, String serviceId)
+    {
+        def.getServiceId();
+        setReturnValue(serviceId).atLeastOnce();
+    }
+
+    protected final ServiceResources newServiceResources()
+    {
+        return newMock(ServiceResources.class);
+    }
+
+    protected final ServiceDef newServiceDef()
+    {
+        return newMock(ServiceDef.class);
+    }
+
+    protected final void train_getServiceLog(ServiceResources resources, Log log)
+    {
+        resources.getServiceLog();
+        setReturnValue(log).atLeastOnce();
+
+    }
+
+    protected final <T> void train_getService(ServiceLocator locator, String serviceId,
+            Class<T> serviceInterface, T service)
+    {
+        locator.getService(serviceId, serviceInterface);
+        setReturnValue(service);
+    }
+
+    protected final <T> void train_getService(ServiceLocator locator, Class<T> serviceInterface,
+            T service)
+    {
+        locator.getService(serviceInterface);
+        setReturnValue(service);
+    }
+
+    protected final void train_createObject(ObjectCreator creator, Object service)
+    {
+        creator.createObject();
+        setReturnValue(service);
+    }
+
+    protected final ObjectCreator newObjectCreator()
+    {
+        return newMock(ObjectCreator.class);
+    }
+
+    protected final void train_getServiceInterface(ServiceResources resources,
+            Class serviceInterface)
+    {
+        resources.getServiceInterface();
+        setReturnValue(serviceInterface).atLeastOnce();
+    }
+
+    protected final void train_getServiceId(ServiceResources resources, String serviceId)
+    {
+        resources.getServiceId();
+        setReturnValue(serviceId).atLeastOnce();
+    }
+
+    protected final void train_createInterceptor(ServiceDecorator decorator, Object coreObject,
+            Object interceptor)
+    {
+        decorator.createInterceptor(coreObject);
+        setReturnValue(interceptor);
+    }
+
+    protected final ServiceDecorator newServiceDecorator()
+    {
+        return newMock(ServiceDecorator.class);
+    }
+
+    protected final void train_getLog(LogSource source, String serviceId, Log log)
+    {
+        source.getLog(serviceId);
+        setReturnValue(log).atLeastOnce();
+    }
+
+    protected final Method findMethod(Class clazz, String methodName)
+    {
+        for (Method method : clazz.getMethods())
+        {
+            if (method.getName().equals(methodName))
+                return method;
+        }
+
+        throw new IllegalArgumentException(String.format(
+                "Class %s does not provide a method named '%s'.",
+                clazz.getName(),
+                methodName));
+    }
+
+    protected final Method findMethod(Object subject, String methodName)
+    {
+        return findMethod(subject.getClass(), methodName);
+    }
+
+    protected final Method findMethod(String methodName)
+    {
+        return findMethod(this, methodName);
+    }
+
+    protected final Configuration newConfiguration()
+    {
+        return newMock(Configuration.class);
+    }
+
+    protected final ServiceLocator newServiceLocator()
+    {
+        return newMock(ServiceLocator.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final <T> OrderedConfiguration<T> newOrderedConfiguration()
+    {
+        return newMock(OrderedConfiguration.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final <K, V> MappedConfiguration<K, V> newMappedConfiguration()
+    {
+        return newMock(MappedConfiguration.class);
+    }
+
+    protected final ContributionDef newContributionDef()
+    {
+        return newMock(ContributionDef.class);
+    }
+
+    protected final ServiceBuilderResources newServiceCreatorResources()
+    {
+        return newMock(ServiceBuilderResources.class);
+    }
+
+    protected final void train_getModuleId(ModuleDef def, String moduleId)
+    {
+        def.getModuleId();
+        setReturnValue(moduleId).atLeastOnce();
+    }
+
+    protected final ModuleDef newModuleDef()
+    {
+        return newMock(ModuleDef.class);
+    }
+
+    protected final void train_matches(DecoratorDef decoratorDef, ServiceDef serviceDef,
+            boolean matches)
+    {
+        decoratorDef.matches(serviceDef);
+        setReturnValue(matches);
+    }
+
+    protected final DecoratorDef newDecoratorDef()
+    {
+        return newMock(DecoratorDef.class);
+    }
+
+    /** Frequently used as a placeholder for an arbitrary service (but its nice and simple). */
+    protected final Runnable newRunnable()
+    {
+        return newMock(Runnable.class);
+    }
+
+    protected final Location newLocation()
+    {
+        return newMock(Location.class);
+    }
+
+    /** Combines a series of lines by forming a string with a line separator after each line. */
+    protected final String join(String... lines)
+    {
+        StringBuilder result = new StringBuilder();
+
+        for (String line : lines)
+        {
+            result.append(line);
+            result.append("\n");
+        }
+
+        return result.toString();
+    }
+
+    protected final ComponentClassResolver newComponentClassResolver()
+    {
+        return newMock(ComponentClassResolver.class);
+    }
+
+    protected final void train_newBinding(BindingFactory factory, String description,
+            ComponentResources component, String expression, Location l, Binding b)
+    {
+        factory.newBinding(description, component, expression, l);
+        setReturnValue(b);
+    }
+
+    protected final ComponentResources newComponentResources()
+    {
+        return newMock(ComponentResources.class);
+    }
+
+    protected final Binding newBinding()
+    {
+        return newMock(Binding.class);
+    }
+
+    protected final BindingFactory newBindingFactory()
+    {
+        return newMock(BindingFactory.class);
+    }
+
+    protected final ComponentModel newComponentModel()
+    {
+        return newMock(ComponentModel.class);
+    }
+
+    protected final void train_addMethod(ClassTransformation transformation,
+            MethodSignature signature, String... body)
+    {
+        transformation.addMethod(eq(signature), codeEq(join(body)));
+    }
+
+    protected final void train_newMemberName(ClassTransformation transformation, String suggested,
+            String name)
+    {
+        transformation.newMemberName(suggested);
+        setReturnValue(name);
+    }
+
+    protected final void train_extendMethod(ClassTransformation transformation,
+            MethodSignature signature, String... body)
+    {
+        transformation.extendMethod(eq(signature), codeEq(join(body)));
+    }
+
+    protected final void train_getResourcesFieldName(ClassTransformation transformation, String name)
+    {
+        transformation.getResourcesFieldName();
+        setReturnValue(name).atLeastOnce();
+    }
+
+    protected final void train_addField(ClassTransformation transformation, int modifiers,
+            String type, String suggestedName, String actualName)
+    {
+        transformation.addField(modifiers, type, suggestedName);
+        setReturnValue(actualName);
+    }
+
+    protected final void train_getFieldType(ClassTransformation transformation, String fieldName,
+            String type)
+    {
+        transformation.getFieldType(fieldName);
+        setReturnValue(type).atLeastOnce();
+
+    }
+
+    protected final void train_name(Parameter parameter, String name)
+    {
+        parameter.name();
+        setReturnValue(name).atLeastOnce();
+    }
+
+    protected final void train_findMethodsWithAnnotation(ClassTransformation tf,
+            Class<? extends Annotation> annotationType, List<MethodSignature> sigs)
+    {
+        tf.findMethodsWithAnnotation(annotationType);
+        setReturnValue(sigs);
+    }
+
+    protected final WebRequest newWebRequest()
+    {
+        return newMock(WebRequest.class);
+    }
+
+    protected final void train_provideInjection(InjectionProvider provider, String fieldName,
+            String fieldType, ServiceLocator locator, ClassTransformation transformation,
+            MutableComponentModel model, boolean result)
+    {
+        provider.provideInjection(fieldName, fieldType, locator, transformation, model);
+        setReturnValue(result);
+    }
+
+    protected final void train_toClass(ClassTransformation transformation, String type,
+            Class classForType)
+    {
+        transformation.toClass(type);
+        setReturnValue(classForType);
+    }
+
+    protected final ParameterModel newParameterModel()
+    {
+        return newMock(ParameterModel.class);
+    }
+
+    protected final void train_getComponentClassName(ComponentModel model, String className)
+    {
+        model.getComponentClassName();
+        setReturnValue(className).atLeastOnce();
+    }
+
+    protected final void train_isRequired(ParameterModel model, boolean isRequired)
+    {
+        model.isRequired();
+        setReturnValue(isRequired);
+    }
+
+    protected final void train_getParameterModel(ComponentModel model, String parameterName,
+            ParameterModel parameterModel)
+    {
+        model.getParameterModel(parameterName);
+        setReturnValue(parameterModel);
+    }
+
+    protected final void train_getParameterNames(ComponentModel model, String... names)
+    {
+        model.getParameterNames();
+        setReturnValue(Arrays.asList(names));
+    }
+
+    protected <S, T> void train_coerce(TypeCoercer coercer, S input, Class<T> expectedType,
+            T coercedValue)
+    {
+        coercer.coerce(input, expectedType);
+        setReturnValue(coercedValue);
+    }
+
+    protected final TypeCoercer newTypeCoercer()
+    {
+        return newMock(TypeCoercer.class);
+    }
+
+    protected final void train_isInvariant(Binding binding, boolean isInvariant)
+    {
+        binding.isInvariant();
+        setReturnValue(isInvariant);
+    }
+
+    protected final MarkupWriter newMarkupWriter()
+    {
+        return newMock(MarkupWriter.class);
+    }
+
+    protected final void train_get(Binding binding, Object value)
+    {
+        binding.get();
+        setReturnValue(value);
+    }
+
+    protected final void train_encodeURL(WebResponse response, String inputURL, String outputURL)
+    {
+        response.encodeURL(inputURL);
+        setReturnValue(outputURL);
+    }
+
+    protected final WebResponse newWebResponse()
+    {
+        return newMock(WebResponse.class);
+    }
+
+    protected void train_getAttribute(HttpSession session, String attributeName, Object value)
+    {
+        session.getAttribute(attributeName);
+        setReturnValue(value);
+    }
+
+    protected final HttpServletRequest newHttpServletRequest()
+    {
+        return newMock(HttpServletRequest.class);
+    }
+
+    protected final void train_getSession(HttpServletRequest request, boolean create,
+            HttpSession session)
+    {
+        request.getSession(create);
+        setReturnValue(session);
+    }
+
+    protected final HttpSession newHttpSession()
+    {
+        return newMock(HttpSession.class);
+    }
+
+    protected final void train_getAttributeNames(WebSession session, String prefix, String... names)
+    {
+        session.getAttributeNames(prefix);
+        setReturnValue(Arrays.asList(names));
+    }
+
+    protected final void train_getAttribute(WebSession session, String name, Object attribute)
+    {
+        session.getAttribute(name);
+        setReturnValue(attribute);
+    }
+
+    protected final WebSession newWebSession()
+    {
+        return newMock(WebSession.class);
+    }
+
+    protected final void train_getSession(WebRequest request, boolean create, WebSession session)
+    {
+        request.getSession(create);
+        setReturnValue(session);
+    }
+
+    protected final void train_encodeRedirectURL(WebResponse response, String URI, String encoded)
+    {
+        response.encodeRedirectURL(URI);
+        setReturnValue(encoded);
+    }
+
+    protected final <T extends Annotation> void train_getAnnotation(
+            ClassTransformation transformation, Class<T> annotationClass, T annotation)
+    {
+        transformation.getAnnotation(annotationClass);
+        setReturnValue(annotation);
+    }
+
+    protected final void train_getPage(ComponentResources resources, Component page)
+    {
+        resources.getPage();
+        setReturnValue(page).atLeastOnce();
+    }
+
+    protected final void train_getCompleteId(ComponentResources resources, String completeId)
+    {
+        resources.getCompleteId();
+        setReturnValue(completeId).atLeastOnce();
+    }
+
+    protected final void train_getComponentResources(Component component,
+            ComponentResources resources)
+    {
+        component.getComponentResources();
+        setReturnValue(resources).atLeastOnce();
+    }
+
+    protected final void train_getContainer(ComponentResources resources, Component container)
+    {
+        resources.getContainer();
+        setReturnValue(container).atLeastOnce();
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Sun Nov 19 09:58:01 2006
@@ -57,4 +57,5 @@
 could-not-resolve-component-type=Unable to resolve component type '%s' to a component class name.
 could-not-resolve-mixin-type=Unable to resolve mixin type '%s' to a component class name.
 parameter-name-must-be-unique=Parameter names are required to be unique.  Parameter '%s' already has the value '%s'.
-page-is-dirty=Page %s is dirty, and will be discarded (rather than returned to the page pool).
\ No newline at end of file
+page-is-dirty=Page %s is dirty, and will be discarded (rather than returned to the page pool).
+component-instance-is-not-a-page=Method %s (for component %s) returned component %s, which is not a page component. The page containing the component will render the client response.
\ No newline at end of file

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java Sun Nov 19 09:58:01 2006
@@ -57,12 +57,6 @@
         return resources;
     }
 
-    protected void train_getCompleteId(ComponentResources resources, String completeId)
-    {
-        resources.getCompleteId();
-        setReturnValue(completeId);
-    }
-
     private void train_getComponent(ComponentResources resources, Component component)
     {
         resources.getComponent();

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java Sun Nov 19 09:58:01 2006
@@ -31,12 +31,12 @@
     @Test
     public void no_decorators()
     {
-        ObjectCreator core = newServiceCreator();
+        ObjectCreator core = newObjectCreator();
         Module module = newModule();
         Object coreObject = new Object();
         List<ServiceDecorator> decorators = newList();
 
-        train_greateService(core, coreObject);
+        train_createObject(core, coreObject);
 
         train_findDecoratorsForService(module, SERVICE_ID, decorators);
 
@@ -54,14 +54,14 @@
     @Test
     public void decorator_returns_null_interceptor()
     {
-        ObjectCreator core = newServiceCreator();
+        ObjectCreator core = newObjectCreator();
         Module module = newModule();
         Object coreObject = new Object();
         ServiceDecorator decorator = newServiceDecorator();
 
         List<ServiceDecorator> decorators = asList(decorator);
 
-        train_greateService(core, coreObject);
+        train_createObject(core, coreObject);
 
         train_findDecoratorsForService(module, SERVICE_ID, decorators);
 
@@ -81,7 +81,7 @@
     @Test
     public void decorator_orderering()
     {
-        ObjectCreator core = newServiceCreator();
+        ObjectCreator core = newObjectCreator();
         Module module = newModule();
         Object coreObject = new Object();
         Object interceptor1 = new Object();
@@ -91,7 +91,7 @@
 
         List<ServiceDecorator> decorators = asList(decorator1, decorator2);
 
-        train_greateService(core, coreObject);
+        train_createObject(core, coreObject);
 
         train_findDecoratorsForService(module, SERVICE_ID, decorators);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/OneShortServiceCreatorTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/OneShortServiceCreatorTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/OneShortServiceCreatorTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/OneShortServiceCreatorTest.java Sun Nov 19 09:58:01 2006
@@ -31,12 +31,12 @@
     {
         Method method = getClass().getMethod("buildMyService");
 
-        ObjectCreator delegate = newServiceCreator();
+        ObjectCreator delegate = newObjectCreator();
         Object service = new Object();
 
         ServiceDef def = new ServiceDefImpl("foo.Bar", "singleton", method, false, false);
 
-        train_greateService(delegate, service);
+        train_createObject(delegate, service);
 
         replay();
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SingletonServiceLifecycleTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SingletonServiceLifecycleTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SingletonServiceLifecycleTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SingletonServiceLifecycleTest.java Sun Nov 19 09:58:01 2006
@@ -29,10 +29,10 @@
     public void test()
     {
         ServiceResources resources = newServiceResources();
-        ObjectCreator creator = newServiceCreator();
+        ObjectCreator creator = newObjectCreator();
         Object expected = new Object();
 
-        train_greateService(creator, expected);
+        train_createObject(creator, expected);
 
         replay();
 

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentInstanceEventHandlerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentInstanceEventHandlerTest.java?view=auto&rev=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentInstanceEventHandlerTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentInstanceEventHandlerTest.java Sun Nov 19 09:58:01 2006
@@ -0,0 +1,86 @@
+package org.apache.tapestry.internal.services;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.ComponentEventHandler;
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.runtime.Component;
+import org.testng.annotations.Test;
+
+public class ComponentInstanceEventHandlerTest extends InternalBaseTestCase
+{
+    private static final String PAGE_NAME = "foo.bar.Zoop";
+
+    private static final String METHOD_DESCRIPTION = "foo.bar.Baz.biff()";
+
+    @Test
+    public void result_is_root_component()
+    {
+        Component result = newComponent();
+        Component source = newComponent();
+        ComponentResources resources = newComponentResources();
+        Log log = newLog();
+        RequestPageCache cache = newRequestPageCache();
+        Page page = newPage();
+
+        train_getComponentResources(result, resources);
+        train_getContainer(resources, null);
+
+        train_getCompleteId(resources, PAGE_NAME);
+        train_getByClassName(cache, PAGE_NAME, page);
+
+        cache.setActive(page);
+
+        replay();
+
+        ComponentEventHandler<Component> handler = new ComponentInstanceEventHandler(cache, log);
+
+        handler.handleResult(result, source, METHOD_DESCRIPTION);
+
+        verify();
+    }
+
+    @Test
+    public void warning_for_component_is_not_root_component()
+    {
+        Component child = newComponent();
+        Component source = newComponent();
+        Component root = newComponent();
+        Component container = newComponent();
+        ComponentResources rootResources = newComponentResources();
+        ComponentResources childResources = newComponentResources();
+        ComponentResources sourceResources = newComponentResources();
+        Log log = newLog();
+        RequestPageCache cache = newRequestPageCache();
+        Page page = newPage();
+
+        train_getComponentResources(child, childResources);
+
+        train_getContainer(childResources, container);
+
+        train_getComponentResources(source, sourceResources);
+
+        train_getCompleteId(sourceResources, PAGE_NAME + ":source");
+        train_getCompleteId(childResources, PAGE_NAME + ":child");
+
+        train_getPage(childResources, root);
+        train_getComponentResources(root, rootResources);
+
+        train_getCompleteId(rootResources, PAGE_NAME);
+        train_getByClassName(cache, PAGE_NAME, page);
+
+        cache.setActive(page);
+
+        log
+                .warn("Method foo.bar.Baz.biff() (for component foo.bar.Zoop:source) returned component foo.bar.Zoop:child, which is not a page component. The page containing the component will render the client response.");
+
+        replay();
+
+        ComponentEventHandler<Component> handler = new ComponentInstanceEventHandler(cache, log);
+
+        handler.handleResult(child, source, METHOD_DESCRIPTION);
+
+        verify();
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentSourceImplTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentSourceImplTest.java Sun Nov 19 09:58:01 2006
@@ -12,90 +12,65 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
-
-import org.apache.tapestry.internal.structure.ComponentPageElement;
-import org.apache.tapestry.internal.structure.Page;
-import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.runtime.Component;
-import org.apache.tapestry.services.ComponentSource;
-import org.testng.annotations.Test;
-
-public class ComponentSourceImplTest extends InternalBaseTestCase
-{
-    private static final String PAGE_NAME = "foo.pages.Bar";
-
-    private static final String NESTED_ELEMENT_ID = "zip.zoom";
-
-    @Test
-    public void root_element_of_page()
-    {
-        RequestPageCache cache = newPageRequestCache();
-        Page page = newPage();
-        ComponentPageElement element = newComponentPageElement();
-        Component component = newComponent();
-
-        train_getByClassName(cache, PAGE_NAME, page);
-
-        train_getRootElement(page, element);
-
-        train_getComponent(element, component);
-
-        replay();
-
-        ComponentSource source = new ComponentSourceImpl(cache);
-
-        assertSame(source.getComponent(PAGE_NAME), component);
-
-        verify();
-    }
-
-    @Test
-    public void nested_element_within_page()
-    {
-        RequestPageCache cache = newPageRequestCache();
-        Page page = newPage();
-        ComponentPageElement element = newComponentPageElement();
-        Component component = newComponent();
-
-        train_getByClassName(cache, PAGE_NAME, page);
-
-        train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
-
-        train_getComponent(element, component);
-
-        replay();
-
-        ComponentSource source = new ComponentSourceImpl(cache);
-
-        assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
-
-        verify();
-
-    }
-
-    protected final void train_getComponentElementByNestedId(Page page, String nestedId,
-            ComponentPageElement element)
-    {
-        page.getComponentElementByNestedId(nestedId);
-        setReturnValue(element);
-    }
-
-    protected final void train_getRootElement(Page page, ComponentPageElement element)
-    {
-        page.getRootElement();
-        setReturnValue(element);
-    }
-
-    protected final void train_getByClassName(RequestPageCache cache, String pageClassName,
-            Page page)
-    {
-        cache.getByClassName(pageClassName);
-        setReturnValue(page);
-    }
-
-    protected final RequestPageCache newPageRequestCache()
-    {
-        return newMock(RequestPageCache.class);
-    }
-}
+package org.apache.tapestry.internal.services;
+
+import org.apache.tapestry.internal.structure.ComponentPageElement;
+import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.runtime.Component;
+import org.apache.tapestry.services.ComponentSource;
+import org.testng.annotations.Test;
+
+public class ComponentSourceImplTest extends InternalBaseTestCase
+{
+    private static final String PAGE_NAME = "foo.pages.Bar";
+
+    private static final String NESTED_ELEMENT_ID = "zip.zoom";
+
+    @Test
+    public void root_element_of_page()
+    {
+        RequestPageCache cache = newRequestPageCache();
+        Page page = newPage();
+        ComponentPageElement element = newComponentPageElement();
+        Component component = newComponent();
+
+        train_getByClassName(cache, PAGE_NAME, page);
+
+        train_getRootElement(page, element);
+
+        train_getComponent(element, component);
+
+        replay();
+
+        ComponentSource source = new ComponentSourceImpl(cache);
+
+        assertSame(source.getComponent(PAGE_NAME), component);
+
+        verify();
+    }
+
+    @Test
+    public void nested_element_within_page()
+    {
+        RequestPageCache cache = newRequestPageCache();
+        Page page = newPage();
+        ComponentPageElement element = newComponentPageElement();
+        Component component = newComponent();
+
+        train_getByClassName(cache, PAGE_NAME, page);
+
+        train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
+
+        train_getComponent(element, component);
+
+        replay();
+
+        ComponentSource source = new ComponentSourceImpl(cache);
+
+        assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
+
+        verify();
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java?view=diff&rev=476861&r1=476860&r2=476861
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java Sun Nov 19 09:58:01 2006
@@ -20,6 +20,7 @@
 import org.apache.tapestry.ioc.ServiceLocator;
 import org.apache.tapestry.model.MutableComponentModel;
 import org.apache.tapestry.services.ClassTransformation;
+import org.apache.tapestry.services.InjectionProvider;
 import org.apache.tapestry.services.WebRequest;
 import org.testng.annotations.Test;