Copied: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/PageSpecificationResolverTest.java (from r349803, jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestPageSpecificationResolver.java) URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/PageSpecificationResolverTest.java?p2=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/PageSpecificationResolverTest.java&p1=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestPageSpecificationResolver.java&r1=349803&r2=351507&rev=351507&view=diff ============================================================================== --- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestPageSpecificationResolver.java (original) +++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/PageSpecificationResolverTest.java Thu Dec 1 14:29:33 2005 @@ -17,6 +17,7 @@ import java.util.List; import org.apache.commons.logging.Log; +import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.Location; import org.apache.hivemind.Resource; import org.apache.tapestry.INamespace; @@ -28,7 +29,6 @@ import org.apache.tapestry.spec.ComponentSpecification; import org.apache.tapestry.spec.IComponentSpecification; import org.apache.tapestry.spec.ILibrarySpecification; -import org.easymock.MockControl; /** * Tests for [EMAIL PROTECTED] org.apache.tapestry.resolver.PageSpecificationResolverImpl}. @@ -36,59 +36,69 @@ * @author Howard M. Lewis Ship * @since 4.0 */ -public class TestPageSpecificationResolver extends AbstractSpecificationResolverTestCase +public class PageSpecificationResolverTest extends AbstractSpecificationResolverTestCase { private static class MockApplicationNamespace implements INamespace { - private Resource _specificationLocation; - String _pageName; IComponentSpecification _specification; + private Resource _specificationLocation; + MockApplicationNamespace(Resource specificationLocation) { _specificationLocation = specificationLocation; } - public String getId() + public String constructQualifiedName(String pageName) { return null; } - public String getExtendedId() + public boolean containsComponentType(String type) + { + return false; + } + + public boolean containsPage(String name) + { + return false; + } + + public List getChildIds() { return null; } - public String getNamespaceId() + public INamespace getChildNamespace(String id) { return null; } - public INamespace getParentNamespace() + public IComponentSpecification getComponentSpecification(String type) { return null; } - public INamespace getChildNamespace(String id) + public String getExtendedId() { return null; } - public List getChildIds() + public String getId() { return null; } - public IComponentSpecification getPageSpecification(String name) + public Location getLocation() { return null; } - public boolean containsPage(String name) + public String getNamespaceId() { - return false; + return null; } public List getPageNames() @@ -96,22 +106,22 @@ return null; } - public IComponentSpecification getComponentSpecification(String type) + public IComponentSpecification getPageSpecification(String name) { return null; } - public boolean containsComponentType(String type) + public INamespace getParentNamespace() { - return false; + return null; } - public ILibrarySpecification getSpecification() + public String getPropertyValue(String propertyName) { return null; } - public String constructQualifiedName(String pageName) + public ILibrarySpecification getSpecification() { return null; } @@ -121,9 +131,8 @@ return _specificationLocation; } - public boolean isApplicationNamespace() + public void installComponentSpecification(String type, IComponentSpecification specification) { - return true; } public void installPageSpecification(String pageName, IComponentSpecification specification) @@ -132,108 +141,81 @@ _specification = specification; } - public void installComponentSpecification(String type, IComponentSpecification specification) - { - } - - public Location getLocation() + public boolean isApplicationNamespace() { - return null; + return true; } - public String getPropertyValue(String propertyName) - { - return null; - } + } + private ISpecificationResolverDelegate newDelegate() + { + return (ISpecificationResolverDelegate) newMock(ISpecificationResolverDelegate.class); } - private ISpecificationSource newSource(INamespace application, INamespace framework) + private INamespace newNamespace(String pageName, IComponentSpecification spec) { - MockControl control = newControl(ISpecificationSource.class); - ISpecificationSource source = (ISpecificationSource) control.getMock(); + INamespace namespace = newNamespace(); - trainGetApplicationNamespace(control, source, application); + trainContainsPage(namespace, pageName, spec != null); - trainGetFrameworkNamespace(control, source, framework); + if (spec != null) + trainGetPageSpecification(namespace, pageName, spec); - return source; + return namespace; } - private void trainGetFrameworkNamespace(MockControl control, ISpecificationSource source, - INamespace framework) + private ComponentPropertySource newPropertySource(INamespace namespace) { - source.getFrameworkNamespace(); - control.setReturnValue(framework); - } + ComponentPropertySource source = (ComponentPropertySource) newMock(ComponentPropertySource.class); - private void trainGetApplicationNamespace(MockControl control, ISpecificationSource source, - INamespace application) - { - source.getApplicationNamespace(); - control.setReturnValue(application); + source.getNamespaceProperty(namespace, Tapestry.TEMPLATE_EXTENSION_PROPERTY); + setReturnValue(source, "html"); + + return source; } - private ISpecificationSource newSource(INamespace application, INamespace framework, - Resource resource, IComponentSpecification pageSpec) + private ISpecificationSource newSource(INamespace application, INamespace framework) { - MockControl control = newControl(ISpecificationSource.class); - ISpecificationSource source = (ISpecificationSource) control.getMock(); - - source.getApplicationNamespace(); - control.setReturnValue(application); + ISpecificationSource source = newSource(); - source.getFrameworkNamespace(); - control.setReturnValue(framework); + trainGetApplicationNamespace(source, application); - source.getPageSpecification(resource); - control.setReturnValue(pageSpec); + trainGetFrameworkNamespace(source, framework); return source; } - private INamespace newNamespace() - { - return (INamespace) newMock(INamespace.class); - } - - private INamespace newNamespace(String pageName, IComponentSpecification spec) + private ISpecificationSource newSource(INamespace application, INamespace framework, + Resource resource, IComponentSpecification pageSpec) { - MockControl control = newControl(INamespace.class); - INamespace namespace = (INamespace) control.getMock(); + ISpecificationSource source = newSource(); - namespace.containsPage(pageName); - control.setReturnValue(spec != null); + trainGetApplicationNamespace(source, application); - if (spec != null) - { - namespace.getPageSpecification(pageName); - control.setReturnValue(spec); - } - - return namespace; - } - - private ComponentPropertySource newPropertySource(INamespace namespace) - { - MockControl control = newControl(ComponentPropertySource.class); - ComponentPropertySource source = (ComponentPropertySource) control.getMock(); + trainGetFrameworkNamespace(source, framework); - source.getNamespaceProperty(namespace, Tapestry.TEMPLATE_EXTENSION_PROPERTY); - control.setReturnValue("html"); + trainGetPageSpecification(source, resource, pageSpec); return source; } - public void testFoundInApplicationNamespace() + public void testExplicitlyInApplicationNamespace() { Resource contextRoot = newResource("context/"); IComponentSpecification spec = newSpecification(); INamespace application = newNamespace("ExistingPage", spec); INamespace framework = newNamespace(); - ISpecificationSource source = newSource(application, framework); + + ISpecificationSource source = newSource(); + + trainGetApplicationNamespace(source, application); + trainGetFrameworkNamespace(source, framework); + IRequestCycle cycle = newCycle(); + trainGetApplicationNamespace(source, application); + replayControls(); PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); @@ -241,13 +223,14 @@ resolver.setSpecificationSource(source); resolver.initializeService(); - resolver.resolve(cycle, "ExistingPage"); + resolver.resolve(cycle, "application:ExistingPage"); assertEquals("ExistingPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); + } public void testExplicitlyInFrameworkNamespace() @@ -257,15 +240,14 @@ INamespace application = newNamespace(); INamespace framework = newNamespace("ExistingPage", spec); - MockControl sourcec = newControl(ISpecificationSource.class); - ISpecificationSource source = (ISpecificationSource) sourcec.getMock(); + ISpecificationSource source = newSource(); - trainGetApplicationNamespace(sourcec, source, application); - trainGetFrameworkNamespace(sourcec, source, framework); + trainGetApplicationNamespace(source, application); + trainGetFrameworkNamespace(source, framework); IRequestCycle cycle = newCycle(); - trainGetFrameworkNamespace(sourcec, source, framework); + trainGetFrameworkNamespace(source, framework); replayControls(); @@ -283,38 +265,107 @@ verifyControls(); } - public void testExplicitlyInApplicationNamespace() + public void testFoundAsTemplate() { + Log log = newLog(); + Resource contextRoot = newResource("context/"); - IComponentSpecification spec = newSpecification(); - INamespace application = newNamespace("ExistingPage", spec); - INamespace framework = newNamespace(); - MockControl sourcec = newControl(ISpecificationSource.class); - ISpecificationSource source = (ISpecificationSource) sourcec.getMock(); + Resource resource = contextRoot.getRelativeResource("TemplatePage.html"); - trainGetApplicationNamespace(sourcec, source, application); - trainGetFrameworkNamespace(sourcec, source, framework); + MockApplicationNamespace application = new MockApplicationNamespace(contextRoot + .getRelativeResource("WEB-INF/")); + INamespace framework = newNamespace(); + ISpecificationSource source = newSource(application, framework); IRequestCycle cycle = newCycle(); - trainGetApplicationNamespace(sourcec, source, application); + ComponentPropertySource propertySource = newPropertySource(application); + + train(log, ResolverMessages.resolvingPage("TemplatePage", application)); + + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/TemplatePage.page"))); + + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/myapp/TemplatePage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/TemplatePage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("TemplatePage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("TemplatePage.html"))); + + train(log, ResolverMessages.foundHTMLTemplate(resource)); + + IComponentSpecification expectedSpec = new ComponentSpecification(); + expectedSpec.setPageSpecification(true); + expectedSpec.setSpecificationLocation(resource); + + // The toString() on ComponentSpecification means we can't predict + // what the string would be. + + trainIsDebugEnabled(log, false); replayControls(); PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); resolver.setContextRoot(contextRoot); resolver.setSpecificationSource(source); + resolver.setLog(log); + resolver.setApplicationId("myapp"); + resolver.setComponentPropertySource(propertySource); + resolver.initializeService(); - resolver.resolve(cycle, "application:ExistingPage"); + resolver.resolve(cycle, "TemplatePage"); + + IComponentSpecification spec = application._specification; + + assertEquals(true, spec.isPageSpecification()); + + // The specification location is used to find relative assets and the like, and is baesd + // on the page name and the namespace location. + + assertEquals(contextRoot.getRelativeResource("WEB-INF/TemplatePage.page"), spec + .getSpecificationLocation()); + + // The Location is used for any error reporting, and should be the actual file + // located, the template. + + assertEquals(resource, spec.getLocation().getResource()); + assertEquals("TemplatePage", resolver.getSimplePageName()); + assertEquals("TemplatePage", application._pageName); - assertEquals("ExistingPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); + } + + public void testFoundInApplicationNamespace() + { + Resource contextRoot = newResource("context/"); + IComponentSpecification spec = newSpecification(); + INamespace application = newNamespace("ExistingPage", spec); + INamespace framework = newNamespace(); + ISpecificationSource source = newSource(application, framework); + IRequestCycle cycle = newCycle(); + + replayControls(); + + PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); + resolver.setContextRoot(contextRoot); + resolver.setSpecificationSource(source); + resolver.initializeService(); + + resolver.resolve(cycle, "ExistingPage"); + assertEquals("ExistingPage", resolver.getSimplePageName()); + assertSame(spec, resolver.getSpecification()); + assertSame(application, resolver.getNamespace()); + + verifyControls(); } public void testFoundInChildNamespace() @@ -323,12 +374,9 @@ IComponentSpecification spec = newSpecification(); INamespace child = newNamespace("ChildPage", spec); + INamespace application = newNamespace(); - MockControl control = newControl(INamespace.class); - INamespace application = (INamespace) control.getMock(); - - application.getChildNamespace("foo.bar"); - control.setReturnValue(child); + trainGetChildNamespace(child, "foo.bar", application); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework); @@ -350,96 +398,100 @@ verifyControls(); } - public void testFoundInNamespaceFolder() + public void testFoundInContextRootFolder() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); Resource contextRoot = newResource("context/"); IComponentSpecification spec = newSpecification(); - Resource resource = contextRoot.getRelativeResource("WEB-INF/NamespacePage.page"); + Resource resource = contextRoot.getRelativeResource("ContextRootPage.page"); - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); + INamespace application = newNamespace(); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework, resource, spec); IRequestCycle cycle = newCycle(); - trainContainsPage(applicationc, application, "NamespacePage", false); + trainContainsPage(application, "ContextRootPage", false); - train(log, logc, ResolverMessages.resolvingPage("NamespacePage", application)); + train(log, ResolverMessages.resolvingPage("ContextRootPage", application)); // Pretend the app spec is in the WEB-INF folder - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(resource)); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/ContextRootPage.page"))); - train(log, logc, ResolverMessages.installingPage("NamespacePage", application, spec)); + trainIsApplicationNamespace(application, true); - application.installPageSpecification("NamespacePage", spec); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/myapp/ContextRootPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/ContextRootPage.page"))); + train(log, ResolverMessages.checkingResource(resource)); + + train(log, ResolverMessages.installingPage("ContextRootPage", application, spec)); + + application.installPageSpecification("ContextRootPage", spec); replayControls(); PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); resolver.setContextRoot(contextRoot); resolver.setSpecificationSource(source); - resolver.initializeService(); resolver.setLog(log); + resolver.setApplicationId("myapp"); - resolver.resolve(cycle, "NamespacePage"); + resolver.initializeService(); - assertEquals("NamespacePage", resolver.getSimplePageName()); + resolver.resolve(cycle, "ContextRootPage"); + + assertEquals("ContextRootPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); } - private void trainGetSpecLocation(MockControl control, INamespace namespace, Resource root, - String path) - { - namespace.getSpecificationLocation(); - control.setReturnValue(root.getRelativeResource(path)); - } - - public void testFoundInWebInfAppFolder() + public void testFoundInFramework() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); + INamespace application = newNamespace(); Resource contextRoot = newResource("context/"); IComponentSpecification spec = newSpecification(); - Resource resource = contextRoot.getRelativeResource("WEB-INF/myapp/MyAppPage.page"); - - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); + ComponentPropertySource propertySource = newPropertySource(application); - INamespace framework = newNamespace(); - ISpecificationSource source = newSource(application, framework, resource, spec); + INamespace framework = newNamespace("FrameworkPage", spec); + ISpecificationSource source = newSource(application, framework); IRequestCycle cycle = newCycle(); - trainContainsPage(applicationc, application, "MyAppPage", false); + trainContainsPage(application, "FrameworkPage", false); - train(log, logc, ResolverMessages.resolvingPage("MyAppPage", application)); + train(log, ResolverMessages.resolvingPage("FrameworkPage", application)); // Pretend the app spec is in the WEB-INF folder - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/MyAppPage.page"))); - - trainIsApplicationNamespace(applicationc, application, true); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/FrameworkPage.page"))); - train(log, logc, ResolverMessages.checkingResource(resource)); + trainIsApplicationNamespace(application, true); - train(log, logc, ResolverMessages.installingPage("MyAppPage", application, spec)); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/myapp/FrameworkPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/FrameworkPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("FrameworkPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("FrameworkPage.html"))); - application.installPageSpecification("MyAppPage", spec); + train(log, ResolverMessages.foundFrameworkPage("FrameworkPage")); replayControls(); @@ -448,127 +500,98 @@ resolver.setSpecificationSource(source); resolver.setLog(log); resolver.setApplicationId("myapp"); + resolver.setComponentPropertySource(propertySource); resolver.initializeService(); - resolver.resolve(cycle, "MyAppPage"); + resolver.resolve(cycle, "FrameworkPage"); - assertEquals("MyAppPage", resolver.getSimplePageName()); + assertEquals("FrameworkPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); - assertSame(application, resolver.getNamespace()); + assertSame(framework, resolver.getNamespace()); verifyControls(); } - private void trainIsApplicationNamespace(MockControl control, INamespace namespace, - boolean isApplicationNamespace) - { - namespace.isApplicationNamespace(); - control.setReturnValue(isApplicationNamespace); - } - - public void testFoundInWebInfFolder() + public void testFoundInNamespaceFolder() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); Resource contextRoot = newResource("context/"); IComponentSpecification spec = newSpecification(); - Resource resource = contextRoot.getRelativeResource("WEB-INF/MyWebInfPage.page"); + Resource resource = contextRoot.getRelativeResource("WEB-INF/NamespacePage.page"); - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); + INamespace application = newNamespace(); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework, resource, spec); IRequestCycle cycle = newCycle(); - application.containsPage("MyWebInfPage"); - applicationc.setReturnValue(false); - - train(log, logc, ResolverMessages.resolvingPage("MyWebInfPage", application)); + trainContainsPage(application, "NamespacePage", false); - // Pretend the app spec is in the context root folder - // Which isn't really something that happens in a real application - // but is necessary to keep from finding the file too early. - - application.getSpecificationLocation(); - applicationc.setReturnValue(contextRoot); - - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("MyWebInfPage.page"))); + train(log, ResolverMessages.resolvingPage("NamespacePage", application)); - application.isApplicationNamespace(); - applicationc.setReturnValue(true); + // Pretend the app spec is in the WEB-INF folder - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/myapp/MyWebInfPage.page"))); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(resource)); + train(log, ResolverMessages.checkingResource(resource)); - train(log, logc, ResolverMessages.installingPage("MyWebInfPage", application, spec)); + train(log, ResolverMessages.installingPage("NamespacePage", application, spec)); - application.installPageSpecification("MyWebInfPage", spec); + application.installPageSpecification("NamespacePage", spec); replayControls(); PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); resolver.setContextRoot(contextRoot); resolver.setSpecificationSource(source); - resolver.setLog(log); - resolver.setApplicationId("myapp"); - resolver.initializeService(); + resolver.setLog(log); - resolver.resolve(cycle, "MyWebInfPage"); + resolver.resolve(cycle, "NamespacePage"); - assertEquals("MyWebInfPage", resolver.getSimplePageName()); + assertEquals("NamespacePage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); } - public void testFoundInContextRootFolder() + public void testFoundInWebInfAppFolder() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); Resource contextRoot = newResource("context/"); IComponentSpecification spec = newSpecification(); - Resource resource = contextRoot.getRelativeResource("ContextRootPage.page"); + Resource resource = contextRoot.getRelativeResource("WEB-INF/myapp/MyAppPage.page"); - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); + INamespace application = newNamespace(); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework, resource, spec); IRequestCycle cycle = newCycle(); - trainContainsPage(applicationc, application, "ContextRootPage", false); + trainContainsPage(application, "MyAppPage", false); - train(log, logc, ResolverMessages.resolvingPage("ContextRootPage", application)); + train(log, ResolverMessages.resolvingPage("MyAppPage", application)); // Pretend the app spec is in the WEB-INF folder - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/ContextRootPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/MyAppPage.page"))); - trainIsApplicationNamespace(applicationc, application, true); + trainIsApplicationNamespace(application, true); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/myapp/ContextRootPage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/ContextRootPage.page"))); - train(log, logc, ResolverMessages.checkingResource(resource)); + train(log, ResolverMessages.checkingResource(resource)); - train(log, logc, ResolverMessages.installingPage("ContextRootPage", application, spec)); + train(log, ResolverMessages.installingPage("MyAppPage", application, spec)); - application.installPageSpecification("ContextRootPage", spec); + application.installPageSpecification("MyAppPage", spec); replayControls(); @@ -580,64 +603,53 @@ resolver.initializeService(); - resolver.resolve(cycle, "ContextRootPage"); + resolver.resolve(cycle, "MyAppPage"); - assertEquals("ContextRootPage", resolver.getSimplePageName()); + assertEquals("MyAppPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); } - private void trainContainsPage(MockControl control, INamespace namespace, String pageName, - boolean containsPage) - { - namespace.containsPage(pageName); - control.setReturnValue(containsPage); - } - - public void testFoundAsTemplate() + public void testFoundInWebInfFolder() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); Resource contextRoot = newResource("context/"); + IComponentSpecification spec = newSpecification(); - Resource resource = contextRoot.getRelativeResource("TemplatePage.html"); + Resource resource = contextRoot.getRelativeResource("WEB-INF/MyWebInfPage.page"); - MockApplicationNamespace application = new MockApplicationNamespace(contextRoot - .getRelativeResource("WEB-INF/")); + INamespace application = newNamespace(); INamespace framework = newNamespace(); - ISpecificationSource source = newSource(application, framework); + ISpecificationSource source = newSource(application, framework, resource, spec); IRequestCycle cycle = newCycle(); - ComponentPropertySource propertySource = newPropertySource(application); + trainContainsPage(application, "MyWebInfPage", false); - train(log, logc, ResolverMessages.resolvingPage("TemplatePage", application)); + train(log, ResolverMessages.resolvingPage("MyWebInfPage", application)); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/TemplatePage.page"))); + // Pretend the app spec is in the context root folder + // Which isn't really something that happens in a real application + // but is necessary to keep from finding the file too early. - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/myapp/TemplatePage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/TemplatePage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("TemplatePage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("TemplatePage.html"))); + trainGetSpecificationLocation(application, contextRoot); - train(log, logc, ResolverMessages.foundHTMLTemplate(resource)); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("MyWebInfPage.page"))); - IComponentSpecification expectedSpec = new ComponentSpecification(); - expectedSpec.setPageSpecification(true); - expectedSpec.setSpecificationLocation(resource); + trainIsApplicationNamespace(application, true); - // The toString() on ComponentSpecification means we can't predict - // what the string would be. + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/myapp/MyWebInfPage.page"))); - trainIsDebugEnabled(logc, log, false); + train(log, ResolverMessages.checkingResource(resource)); + + train(log, ResolverMessages.installingPage("MyWebInfPage", application, spec)); + + application.installPageSpecification("MyWebInfPage", spec); replayControls(); @@ -646,141 +658,107 @@ resolver.setSpecificationSource(source); resolver.setLog(log); resolver.setApplicationId("myapp"); - resolver.setComponentPropertySource(propertySource); resolver.initializeService(); - resolver.resolve(cycle, "TemplatePage"); - - IComponentSpecification spec = application._specification; - - assertEquals(true, spec.isPageSpecification()); - - // The specification location is used to find relative assets and the like, and is baesd - // on the page name and the namespace location. - - assertEquals(contextRoot.getRelativeResource("WEB-INF/TemplatePage.page"), spec - .getSpecificationLocation()); - - // The Location is used for any error reporting, and should be the actual file - // located, the template. - - assertEquals(resource, spec.getLocation().getResource()); - assertEquals("TemplatePage", resolver.getSimplePageName()); - assertEquals("TemplatePage", application._pageName); + resolver.resolve(cycle, "MyWebInfPage"); + assertEquals("MyWebInfPage", resolver.getSimplePageName()); assertSame(spec, resolver.getSpecification()); assertSame(application, resolver.getNamespace()); verifyControls(); } - private void trainIsDebugEnabled(MockControl control, Log log, boolean isDebugEnabled) - { - log.isDebugEnabled(); - control.setReturnValue(isDebugEnabled); - } - - public void testFoundInFramework() + public void testWebInf() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); - - Resource contextRoot = newResource("context/"); - IComponentSpecification spec = newSpecification(); - - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); - - ComponentPropertySource propertySource = newPropertySource(application); + Log log = newLog(); + INamespace application = newNamespace(); + INamespace framework = newNamespace(); - INamespace framework = newNamespace("FrameworkPage", spec); ISpecificationSource source = newSource(application, framework); IRequestCycle cycle = newCycle(); + Resource contextRoot = newResource("context/"); - trainContainsPage(applicationc, application, "FrameworkPage", false); - - train(log, logc, ResolverMessages.resolvingPage("FrameworkPage", application)); - - // Pretend the app spec is in the WEB-INF folder - - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainContainsPage(application, "/WEB-Inf/BadName", false); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/FrameworkPage.page"))); - - trainIsApplicationNamespace(applicationc, application, true); - - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/myapp/FrameworkPage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/FrameworkPage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("FrameworkPage.page"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("FrameworkPage.html"))); - - train(log, logc, ResolverMessages.foundFrameworkPage("FrameworkPage")); + trainIsDebugEnabled(log, false); replayControls(); PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl(); - resolver.setContextRoot(contextRoot); + resolver.setSpecificationSource(source); + resolver.setContextRoot(contextRoot); resolver.setLog(log); - resolver.setApplicationId("myapp"); - resolver.setComponentPropertySource(propertySource); resolver.initializeService(); - resolver.resolve(cycle, "FrameworkPage"); + try + { + resolver.resolve(cycle, "/WEB-Inf/BadName"); + unreachable(); + } + catch (ApplicationRuntimeException ex) + { + assertEquals( + "Page name '/WEB-Inf/BadName' is not valid, as it directly references a file stored in the WEB-INF folder.", + ex.getMessage()); + } - assertEquals("FrameworkPage", resolver.getSimplePageName()); - assertSame(spec, resolver.getSpecification()); - assertSame(framework, resolver.getNamespace()); + verifyControls(); + + trainContainsPage(application, "web-inf/BadName", false); + + trainIsDebugEnabled(log, false); + + replayControls(); + + try + { + resolver.resolve(cycle, "web-inf/BadName"); + unreachable(); + } + catch (ApplicationRuntimeException ex) + { + assertEquals( + "Page name 'web-inf/BadName' is not valid, as it directly references a file stored in the WEB-INF folder.", + ex.getMessage()); + } verifyControls(); + } - public void testProvidedByDelegate() + public void testNotFoundAnywhere() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); + INamespace application = newNamespace(); Resource contextRoot = newResource("context/"); - IComponentSpecification spec = newSpecification(); - - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework); IRequestCycle cycle = newCycle(); - trainContainsPage(applicationc, application, "DelegatePage", false); + trainContainsPage(application, "MissingPage", false); - train(log, logc, ResolverMessages.resolvingPage("DelegatePage", application)); + train(log, ResolverMessages.resolvingPage("MissingPage", application)); // Pretend the app spec is in the WEB-INF folder - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/DelegatePage.page"))); - - application.isApplicationNamespace(); - applicationc.setReturnValue(false); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/MissingPage.page"))); - MockControl delegatec = newControl(ISpecificationResolverDelegate.class); - ISpecificationResolverDelegate delegate = (ISpecificationResolverDelegate) delegatec - .getMock(); + trainIsApplicationNamespace(application, false); - delegate.findPageSpecification(cycle, application, "DelegatePage"); - delegatec.setReturnValue(spec); + ISpecificationResolverDelegate delegate = newDelegate(); - trainIsDebugEnabled(logc, log, false); + trainFindPageSpecification(delegate, cycle, application, "MissingPage", null); - application.installPageSpecification("DelegatePage", spec); + trainGetNamespaceId(application, "<application namespace>"); replayControls(); @@ -793,52 +771,52 @@ resolver.initializeService(); - resolver.resolve(cycle, "DelegatePage"); - - assertEquals("DelegatePage", resolver.getSimplePageName()); - assertSame(spec, resolver.getSpecification()); - assertSame(application, resolver.getNamespace()); + try + { + resolver.resolve(cycle, "MissingPage"); + unreachable(); + } + catch (PageNotFoundException ex) + { + assertEquals("Page 'MissingPage' not found in <application namespace>.", ex + .getMessage()); + } verifyControls(); } - public void testNotFoundAnywhere() + public void testProvidedByDelegate() { - MockControl logc = newControl(Log.class); - Log log = (Log) logc.getMock(); + Log log = newLog(); + INamespace application = newNamespace(); Resource contextRoot = newResource("context/"); - - MockControl applicationc = newControl(INamespace.class); - INamespace application = (INamespace) applicationc.getMock(); + IComponentSpecification spec = newSpecification(); INamespace framework = newNamespace(); ISpecificationSource source = newSource(application, framework); IRequestCycle cycle = newCycle(); - trainContainsPage(applicationc, application, "MissingPage", false); + trainContainsPage(application, "DelegatePage", false); - train(log, logc, ResolverMessages.resolvingPage("MissingPage", application)); + train(log, ResolverMessages.resolvingPage("DelegatePage", application)); // Pretend the app spec is in the WEB-INF folder - trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/"); + trainGetSpecificationLocation(application, contextRoot, "WEB-INF/"); - train(log, logc, ResolverMessages.checkingResource(contextRoot - .getRelativeResource("WEB-INF/MissingPage.page"))); + train(log, ResolverMessages.checkingResource(contextRoot + .getRelativeResource("WEB-INF/DelegatePage.page"))); - application.isApplicationNamespace(); - applicationc.setReturnValue(false); + trainIsApplicationNamespace(application, false); - MockControl delegatec = newControl(ISpecificationResolverDelegate.class); - ISpecificationResolverDelegate delegate = (ISpecificationResolverDelegate) delegatec - .getMock(); + ISpecificationResolverDelegate delegate = newDelegate(); - delegate.findPageSpecification(cycle, application, "MissingPage"); - delegatec.setReturnValue(null); + trainFindPageSpecification(delegate, cycle, application, "DelegatePage", spec); - application.getNamespaceId(); - applicationc.setReturnValue("<application namespace>"); + trainIsDebugEnabled(log, false); + + application.installPageSpecification("DelegatePage", spec); replayControls(); @@ -851,17 +829,26 @@ resolver.initializeService(); - try - { - resolver.resolve(cycle, "MissingPage"); - unreachable(); - } - catch (PageNotFoundException ex) - { - assertEquals("Page 'MissingPage' not found in <application namespace>.", ex - .getMessage()); - } + resolver.resolve(cycle, "DelegatePage"); + + assertEquals("DelegatePage", resolver.getSimplePageName()); + assertSame(spec, resolver.getSpecification()); + assertSame(application, resolver.getNamespace()); verifyControls(); + } + + private void trainGetPageSpecification(INamespace namespace, String pageName, + IComponentSpecification spec) + { + namespace.getPageSpecification(pageName); + setReturnValue(namespace, spec); + } + + private void trainGetPageSpecification(ISpecificationSource source, Resource resource, + IComponentSpecification pageSpec) + { + source.getPageSpecification(resource); + setReturnValue(source, pageSpec); } }
Modified: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestComponentSpecificationResolver.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestComponentSpecificationResolver.java?rev=351507&r1=351506&r2=351507&view=diff ============================================================================== --- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestComponentSpecificationResolver.java (original) +++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/resolver/TestComponentSpecificationResolver.java Thu Dec 1 14:29:33 2005 @@ -203,13 +203,13 @@ namespace.containsComponentType("MyComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("MyComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("MyComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(specLocation)); - train(log, logc, ResolverMessages.installingComponent("MyComponent", namespace, spec)); + train(log, ResolverMessages.checkingResource(specLocation)); + train(log, ResolverMessages.installingComponent("MyComponent", namespace, spec)); namespace.installComponentSpecification("MyComponent", spec); @@ -251,12 +251,12 @@ namespace.containsComponentType("FrameworkComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("FrameworkComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("FrameworkComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("FrameworkComponent.jwc"))); namespace.isApplicationNamespace(); @@ -273,7 +273,7 @@ framework.getComponentSpecification("FrameworkComponent"); frameworkc.setReturnValue(spec); - train(log, logc, ResolverMessages + train(log, ResolverMessages .installingComponent("FrameworkComponent", namespace, spec)); namespace.installComponentSpecification("FrameworkComponent", spec); @@ -322,12 +322,12 @@ namespace.containsComponentType("DelegateComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("DelegateComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("DelegateComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("DelegateComponent.jwc"))); namespace.isApplicationNamespace(); @@ -406,12 +406,12 @@ namespace.containsComponentType("NotFoundComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("NotFoundComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("NotFoundComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("NotFoundComponent.jwc"))); namespace.isApplicationNamespace(); @@ -478,19 +478,19 @@ namespace.containsComponentType("MyAppComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("MyAppComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("MyAppComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("MyAppComponent.jwc"))); namespace.isApplicationNamespace(); namespacec.setReturnValue(true); - train(log, logc, ResolverMessages.checkingResource(specLocation)); - train(log, logc, ResolverMessages.installingComponent("MyAppComponent", namespace, spec)); + train(log, ResolverMessages.checkingResource(specLocation)); + train(log, ResolverMessages.installingComponent("MyAppComponent", namespace, spec)); namespace.installComponentSpecification("MyAppComponent", spec); @@ -537,21 +537,21 @@ namespace.containsComponentType("MyWebInfComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("MyWebInfComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("MyWebInfComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("MyWebInfComponent.jwc"))); namespace.isApplicationNamespace(); namespacec.setReturnValue(true); - train(log, logc, ResolverMessages.checkingResource(contextRoot + train(log, ResolverMessages.checkingResource(contextRoot .getRelativeResource("WEB-INF/myapp/MyWebInfComponent.jwc"))); - train(log, logc, ResolverMessages.checkingResource(specLocation)); - train(log, logc, ResolverMessages.installingComponent("MyWebInfComponent", namespace, spec)); + train(log, ResolverMessages.checkingResource(specLocation)); + train(log, ResolverMessages.installingComponent("MyWebInfComponent", namespace, spec)); namespace.installComponentSpecification("MyWebInfComponent", spec); @@ -598,23 +598,23 @@ namespace.containsComponentType("ContextRootComponent"); namespacec.setReturnValue(false); - train(log, logc, ResolverMessages.resolvingComponent("ContextRootComponent", namespace)); + train(log, ResolverMessages.resolvingComponent("ContextRootComponent", namespace)); namespace.getSpecificationLocation(); namespacec.setReturnValue(namespaceLocation); - train(log, logc, ResolverMessages.checkingResource(namespaceLocation + train(log, ResolverMessages.checkingResource(namespaceLocation .getRelativeResource("ContextRootComponent.jwc"))); namespace.isApplicationNamespace(); namespacec.setReturnValue(true); - train(log, logc, ResolverMessages.checkingResource(contextRoot + train(log, ResolverMessages.checkingResource(contextRoot .getRelativeResource("WEB-INF/myapp/ContextRootComponent.jwc"))); - train(log, logc, ResolverMessages.checkingResource(contextRoot + train(log, ResolverMessages.checkingResource(contextRoot .getRelativeResource("WEB-INF/ContextRootComponent.jwc"))); - train(log, logc, ResolverMessages.checkingResource(specLocation)); - train(log, logc, ResolverMessages.installingComponent( + train(log, ResolverMessages.checkingResource(specLocation)); + train(log, ResolverMessages.installingComponent( "ContextRootComponent", namespace, spec)); Modified: jakarta/tapestry/trunk/status.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=351507&r1=351506&r2=351507&view=diff ============================================================================== --- jakarta/tapestry/trunk/status.xml (original) +++ jakarta/tapestry/trunk/status.xml Thu Dec 1 14:29:33 2005 @@ -82,6 +82,8 @@ ListenerMapSource.createListenerMethodInvoker()</action> <action type="fix" dev="HLS" fixes-bug="TAPESTRY-387" due-to="Kevin J. Menard, Jr.">Typographical Errors in Documentation</action> + <action type="fix" dev="HLS" fixes-bug="TAPESTRY-724">Tapestry may, in some cases, look for a page class in the wrong package</action> + <action type="fix" dev="HLS" fixes-bug="TAPESTRY-783">contrib:Tree fails with NullPointerException</action> </release> <release version="4.0-beta-13" date="Nov 12 2005"> <action type="update" dev="HLS">Switch to HiveMind 1.1 (final)</action> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
