Author: danielf Date: Thu Apr 7 13:19:48 2005 New Revision: 160454 URL: http://svn.apache.org/viewcvs?view=rev&rev=160454 Log: SitemapTestCase is a base class for sitemap based functional testing, see generation/VirtualPipelineGeneratorTestCase for an example. Not much features and probably rather buggy this far. It uses the MockEnvironment as environment and the MockEnvironment hasn't full functionality yet.
Added: cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java (with props) cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xconf - copied, changed from r160337, cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest Removed: cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest Modified: cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java Added: cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java?view=auto&rev=160454 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java (added) +++ cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java Thu Apr 7 13:19:48 2005 @@ -0,0 +1,116 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon; + +import java.net.URL; + +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.DefaultConfiguration; +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; +import org.apache.avalon.framework.context.DefaultContext; +import org.apache.cocoon.Constants; +import org.apache.cocoon.Processor; +import org.apache.cocoon.components.ContextHelper; +import org.apache.cocoon.environment.internal.EnvironmentHelper; +import org.apache.cocoon.environment.mock.MockEnvironment; + +public class SitemapTestCase extends SitemapComponentTestCase { + + protected Processor processor; + protected String classDir; + protected URL classDirURL; + + public void setUp() throws Exception { + this.classDirURL = getClassDirURL(); + this.classDir = this.classDirURL.toExternalForm(); + super.setUp(); + this.processor = (Processor)this.lookup(Processor.ROLE); + } + + public void tearDown() throws Exception { + this.release(this.processor); + super.tearDown(); + } + + protected void prepare() + throws Exception { + // The context is set in addContext instead + Configuration context = new DefaultConfiguration("", "-"); + + URL rolesURL = + getClass().getClassLoader().getResource("org/apache/cocoon/cocoon.roles"); + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + Configuration roles = builder.build( rolesURL.openStream() ); + + String componentsName = getClass().getName().replace( '.', '/' ) + ".xconf"; + URL componentsURL = getClass().getClassLoader().getResource( componentsName ); + Configuration components; + if ( componentsURL != null ) { + components = builder.build( componentsURL.openStream() ); + } else { + components = new DefaultConfiguration("", "-"); + } + prepare(context, roles, components); + } + + + // Hack to get the URL to the directory that this class is in + protected URL getClassDirURL() throws RuntimeException { + String className = getClass().getName().replace( '.', '/' ) + ".class"; + try { + String classURL = + getClass().getClassLoader().getResource( className ).toExternalForm(); + String classDir = classURL.substring(0, classURL.lastIndexOf('/') + 1); + + return new URL(classDir); + } catch (Exception e) { + throw new RuntimeException("Couldn't create URL for " + className, e); + } + } + + protected void addContext(DefaultContext context) { + super.addContext(context); + context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, getContext()); + context.put(ContextHelper.CONTEXT_ROOT_URL, this.classDirURL); + } + + protected boolean addSourceFactories() { + return false; + } + + protected byte[] process(String uri) throws Exception { + MockEnvironment env = new MockEnvironment(); + env.setURI("", uri); + getRequest().setEnvironment(env); + env.setObjectModel(getObjectModel()); + + EnvironmentHelper.enterProcessor(this.processor, this.getManager(), env); + try { + this.processor.process(env); + getLogger().info("Output: " + new String(env.getOutput(), "UTF-8")); + + return env.getOutput(); + } finally { + EnvironmentHelper.leaveProcessor(); + } + } + + protected void pipeTest(String uri, String expectedSource) throws Exception { + byte[] expected = loadByteArray(this.classDir + expectedSource); + byte[] actual = process(uri); + assertIdentical(expected, actual); + } +} Propchange: cocoon/trunk/src/test/org/apache/cocoon/SitemapTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java?view=diff&r1=160453&r2=160454 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java Thu Apr 7 13:19:48 2005 @@ -15,81 +15,9 @@ */ package org.apache.cocoon.generation; -import java.net.URL; - -import org.apache.avalon.framework.context.DefaultContext; -import org.apache.cocoon.Constants; -import org.apache.cocoon.Processor; -import org.apache.cocoon.SitemapComponentTestCase; -import org.apache.cocoon.components.ContextHelper; -import org.apache.cocoon.environment.internal.EnvironmentHelper; -import org.apache.cocoon.environment.mock.MockEnvironment; - -public class VirtualPipelineGeneratorTestCase extends SitemapComponentTestCase { - - private Processor processor; - private String classDir; - private URL classDirURL; - - public void setUp() throws Exception { - this.classDirURL = getClassDirURL(); - this.classDir = this.classDirURL.toExternalForm(); - super.setUp(); - this.processor = (Processor)this.lookup(Processor.ROLE); - } - - public void tearDown() throws Exception { - this.release(this.processor); - super.tearDown(); - } - - // Hack to get the URL to the directory that this class is in - private URL getClassDirURL() throws RuntimeException { - String className = getClass().getName().replace( '.', '/' ) + ".class"; - try { - String classURL = - getClass().getClassLoader().getResource( className ).toExternalForm(); - String classDir = classURL.substring(0, classURL.lastIndexOf('/') + 1); - - return new URL(classDir); - } catch (Exception e) { - throw new RuntimeException("Couldn't create URL for " + className, e); - } - } - - protected void addContext(DefaultContext context) { - super.addContext(context); - context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, getContext()); - context.put(ContextHelper.CONTEXT_ROOT_URL, this.classDirURL); - } - - protected boolean addSourceFactories() { - return false; - } - - public byte[] process(String uri) throws Exception { - MockEnvironment env = new MockEnvironment(); - env.setURI("", uri); - getRequest().setEnvironment(env); - env.setObjectModel(getObjectModel()); - - EnvironmentHelper.enterProcessor(this.processor, this.getManager(), env); - try { - this.processor.process(env); - getLogger().info("Output: " + new String(env.getOutput(), "UTF-8")); - - return env.getOutput(); - } finally { - EnvironmentHelper.leaveProcessor(); - } - } - - public void pipeTest(String uri, String expectedSource) throws Exception { - byte[] expected = loadByteArray(this.classDir + expectedSource); - byte[] actual = process(uri); - assertIdentical(expected, actual); - } +import org.apache.cocoon.SitemapTestCase; +public class VirtualPipelineGeneratorTestCase extends SitemapTestCase { public void testSimplePipe() throws Exception { pipeTest("test", "vpc-test.xml"); } Copied: cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xconf (from r160337, cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest) URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xconf?view=diff&rev=160454&p1=cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest&r1=160337&p2=cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xconf&r2=160454 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest (original) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xconf Thu Apr 7 13:19:48 2005 @@ -15,77 +15,32 @@ limitations under the License. --> -<testcase> - <roles> - <role name="org.apache.excalibur.xml.sax.SAXParser" - shorthand="xml-parser" - default-class="org.apache.excalibur.xml.impl.JaxpParser"/> - <role name="org.apache.excalibur.xmlizer.XMLizer" - shorthand="xmlizer" - default-class="org.apache.excalibur.xmlizer.DefaultXMLizer"/> - <role name="org.apache.cocoon.components.pipeline.ProcessingPipelineSelector" - shorthand="pipes" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - <role name="org.apache.cocoon.matching.MatcherSelector" - shorthand="matchers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - <role name="org.apache.cocoon.generation.GeneratorSelector" - shorthand="generators" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - <role name="org.apache.cocoon.transformation.TransformerSelector" - shorthand="transformers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.serialization.SerializerSelector" - shorthand="serializers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - <role name="org.apache.excalibur.source.SourceFactorySelector" - shorthand="source-factories" - default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/> - <role name="org.apache.excalibur.source.SourceResolver" - shorthand="source-resolver" - default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/> - <role name="org.apache.cocoon.Processor" - shorthand="sitemap" - default-class="org.apache.cocoon.components.treeprocessor.TreeProcessor"/> - <role name="org.apache.cocoon.components.treeprocessor.TreeBuilder/sitemap-1.0" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage"/> - <role name="org.apache.cocoon.components.modules.input.InputModuleSelector" - shorthand="input-modules" - default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/> - <role name="org.apache.cocoon.components.fam.SitemapMonitor" - shorthand="fam" - default-class="org.apache.cocoon.components.fam.SitemapMonitorImpl"/> - </roles> - - <components> - <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser"> - <parameter name="validate" value="false"/> - <parameter name="namespace-prefixes" value="false"/> - <parameter name="stop-on-warning" value="true"/> - <parameter name="stop-on-recoverable-error" value="true"/> - <parameter name="reuse-parsers" value="false"/> - </xml-parser> +<components> + <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser"> + <parameter name="validate" value="false"/> + <parameter name="namespace-prefixes" value="false"/> + <parameter name="stop-on-warning" value="true"/> + <parameter name="stop-on-recoverable-error" value="true"/> + <parameter name="reuse-parsers" value="false"/> + </xml-parser> - <xmlizer/> + <xmlizer/> - <input-modules> - <component-instance class="org.apache.cocoon.components.modules.input.EnvironmentAttributeModule" name="environment-attribute"/> - </input-modules> + <input-modules> + <component-instance class="org.apache.cocoon.components.modules.input.EnvironmentAttributeModule" name="environment-attribute"/> + </input-modules> - <source-factories> - <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/> - <component-instance class="org.apache.cocoon.components.source.impl.ContextSourceFactory" name="context"/> - <component-instance class="org.apache.cocoon.components.source.impl.ModuleSourceFactory" name="module"/> - <component-instance class="org.apache.cocoon.components.source.impl.XModuleSourceFactory" name="xmodule"/> - <component-instance class="org.apache.excalibur.source.impl.FileSourceFactory" name="file"/> - <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/> - </source-factories> + <source-factories> + <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/> + <component-instance class="org.apache.cocoon.components.source.impl.ContextSourceFactory" name="context"/> + <component-instance class="org.apache.cocoon.components.source.impl.ModuleSourceFactory" name="module"/> + <component-instance class="org.apache.cocoon.components.source.impl.XModuleSourceFactory" name="xmodule"/> + <component-instance class="org.apache.excalibur.source.impl.FileSourceFactory" name="file"/> + <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/> + </source-factories> - <!-- Relative sitemap path works during sitemap execution but - give exceptions during decommissioning --> - <sitemap file="resource://org/apache/cocoon/generation/vpc-sitemap.xmap"/> + <!-- Relative sitemap path works during sitemap execution but + give exceptions during decommissioning --> + <sitemap file="resource://org/apache/cocoon/generation/vpc-sitemap.xmap"/> - </components> - -</testcase> +</components> \ No newline at end of file