Author: danielf Date: Mon Mar 28 13:27:59 2005 New Revision: 159314 URL: http://svn.apache.org/viewcvs?view=rev&rev=159314 Log: Test cases for VPCs, and some updates on the mock environment.
Added: cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest cocoon/trunk/src/test/org/apache/cocoon/generation/sub/ cocoon/trunk/src/test/org/apache/cocoon/generation/sub/sitemap.xmap cocoon/trunk/src/test/org/apache/cocoon/generation/sub/test.xml cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param-expected.xml cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param.xml cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-sitemap.xmap cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-source-param.xml cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-test.xml Modified: cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java Modified: cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java?view=diff&r1=159313&r2=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java Mon Mar 28 13:27:59 2005 @@ -57,7 +57,8 @@ } public void setURI(String prefix, String uri) { - throw new AssertionFailedError("Not implemented"); + this.uriprefix = prefix; + this.uri = uri; } public void redirect(String url, boolean global, boolean permanent) throws IOException { @@ -101,6 +102,10 @@ return objectmodel; } + public void setObjectModel(Map objectmodel) { + this.objectmodel = objectmodel; + } + public boolean isResponseModified(long lastModified) { throw new AssertionFailedError("Not implemented"); } @@ -155,4 +160,3 @@ return false; } } - Modified: cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java?view=diff&r1=159313&r2=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java Mon Mar 28 13:27:59 2005 @@ -32,6 +32,7 @@ import junit.framework.AssertionFailedError; import org.apache.cocoon.environment.Cookie; +import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; @@ -66,10 +67,16 @@ private Map cookies = new HashMap(); private MockSession session; + private Environment environment = null; private boolean isRequestedSessionIdFromCookie = true; private boolean isRequestedSessionIdFromURL = false; - + + // Needed to get getSitemapURI and getSitemapPath right + public void setEnvironment(Environment environment) { + this.environment = environment; + } + /* (non-Javadoc) * @see org.apache.cocoon.environment.Request#get(java.lang.String) */ @@ -257,7 +264,10 @@ } public String getRequestURI() { - return requestURI; + if (this.environment == null) + return requestURI; + else + return this.environment.getURI(); } public void setRequestURI(String uri) { @@ -265,11 +275,17 @@ } public String getSitemapURI() { - return requestURI; + if (this.environment == null) + return requestURI; + else + return this.environment.getURI(); } public String getSitemapPath() { - return ""; + if (this.environment == null) + return ""; + else + return this.environment.getURIPrefix(); } public String getServletPath() { @@ -431,14 +447,14 @@ } } - /* (non-Javadoc) - * @see org.apache.cocoon.environment.Request#getInputStream() - */ - public InputStream getInputStream() throws IOException, UnsupportedOperationException { - return this.inputStream; - } + /* (non-Javadoc) + * @see org.apache.cocoon.environment.Request#getInputStream() + */ + public InputStream getInputStream() throws IOException, UnsupportedOperationException { + return this.inputStream; + } public void setInputStream(InputStream is) { - this.inputStream = is; + this.inputStream = is; } } Added: 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=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.java Mon Mar 28 13:27:59 2005 @@ -0,0 +1,120 @@ +/* + * 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.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); + } + + public void testSimplePipe() throws Exception { + pipeTest("test", "vpc-test.xml"); + } + + public void testVirtualPipe() throws Exception { + pipeTest("v1", "vpc-test.xml"); + } + + public void testVirtualPipeParam() throws Exception { + pipeTest("v2", "vpc-param-expected.xml"); + } + + public void testVirtualPipeSourceParam() throws Exception { + process("v3"); + } + + public void testVirtualSubPipeSourceParam() throws Exception { + process("sub/v3"); + } + + public void testVirtualPipeSrc() throws Exception { + process("v4"); + } + + public void testVirtualSubPipeSrc() throws Exception { + process("sub/v4"); + } +} Added: 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.xtest?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/VirtualPipelineGeneratorTestCase.xtest Mon Mar 28 13:27:59 2005 @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + 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. +--> + +<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"/> + </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> + + <xmlizer/> + + <input-modules> + <component-instance class="org.apache.cocoon.components.modules.input.AvalonContextModule" name="avalon-context"/> + </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> + + <!-- Relative sitemap path works during sitemap execution but + give exceptions during decommissioning --> + <sitemap file="resource://org/apache/cocoon/generation/vpc-sitemap.xmap"/> + + </components> + +</testcase> Added: cocoon/trunk/src/test/org/apache/cocoon/generation/sub/sitemap.xmap URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/sub/sitemap.xmap?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/sub/sitemap.xmap (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/sub/sitemap.xmap Mon Mar 28 13:27:59 2005 @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<!-- SVN $Id$ --> + +<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> + + <map:pipelines> + <map:pipeline> + + <map:match pattern="v3"> + <map:generate type="virtual3"> + <map:parameter name="source" value="test.xml"/> + <map:parameter name="foo" value="bar"/> + </map:generate> + <map:serialize type="xml"/> + </map:match> + + <map:match pattern="v4"> + <map:generate type="virtual4" src="test.xml"/> + <map:serialize type="xml"/> + </map:match> + + </map:pipeline> + </map:pipelines> +</map:sitemap> Added: cocoon/trunk/src/test/org/apache/cocoon/generation/sub/test.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/sub/test.xml?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/sub/test.xml (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/sub/test.xml Mon Mar 28 13:27:59 2005 @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><test/> \ No newline at end of file Added: cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param-expected.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param-expected.xml?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param-expected.xml (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param-expected.xml Mon Mar 28 13:27:59 2005 @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><test foo2="bar"/> \ No newline at end of file Added: cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param.xml?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param.xml (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-param.xml Mon Mar 28 13:27:59 2005 @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test foo2="${cocoon.parameters.foo2}"/> \ No newline at end of file Added: cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-sitemap.xmap URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-sitemap.xmap?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-sitemap.xmap (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-sitemap.xmap Mon Mar 28 13:27:59 2005 @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<!-- SVN $Id$ --> + +<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> + + <map:components> + <map:generators default="file"> + <map:generator name="file" src="org.apache.cocoon.generation.FileGenerator"/> + <map:generator name="jx" src="org.apache.cocoon.generation.JXTemplateGenerator"/> + <map:generator name="virtual1" src="org.apache.cocoon.generation.VirtualPipelineGenerator"> + <map:generate type="file" src="vpc-test.xml"/> + </map:generator> + <map:generator name="virtual2" src="org.apache.cocoon.generation.VirtualPipelineGenerator"> + <map:generate type="jx" src="vpc-param.xml"> + <map:parameter name="foo2" value="{foo}"/> + </map:generate> + </map:generator> + <map:generator name="virtual3" src="org.apache.cocoon.generation.VirtualPipelineGenerator"> + <map:source param="source"/> + <map:generate type="jx" src="vpc-source-param.xml"> + <map:parameter name="source" value="{source}"/> + <map:parameter name="foo2" value="{foo}"/> + </map:generate> + </map:generator> + <map:generator name="virtual4" src="org.apache.cocoon.generation.VirtualPipelineGenerator"> + <map:generate src="{src}"/> + </map:generator> + </map:generators> + + <map:transformers default="xslt"> + <map:transformer name="xslt" src="org.apache.cocoon.transformation.TraxTransformer"> + <xslt-processor-role>xalan</xslt-processor-role> + </map:transformer> + </map:transformers> + + <map:serializers default="xml"> + <map:serializer mime-type="text/xml" name="xml" src="org.apache.cocoon.serialization.XMLSerializer"/> + </map:serializers> + + <map:matchers default="wildcard"> + <map:matcher name="wildcard" src="org.apache.cocoon.matching.WildcardURIMatcher"/> + </map:matchers> + + <map:pipes default="noncaching"> + <map:pipe name="noncaching" src="org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline"> + </map:pipe> + </map:pipes> + </map:components> + + <map:pipelines> + <map:pipeline> + + <map:match pattern="test"> + <map:generate type="file" src="vpc-test.xml"/> + <map:serialize type="xml"/> + </map:match> + + <map:match pattern="v1"> + <map:generate type="virtual1"/> + <map:serialize type="xml"/> + </map:match> + + <map:match pattern="v2"> + <map:generate type="virtual2"> + <map:parameter name="foo" value="bar"/> + </map:generate> + <map:serialize type="xml"/> + </map:match> + + <map:match pattern="v3"> + <map:generate type="virtual3"> + <map:parameter name="source" value="vpc-test.xml"/> + <map:parameter name="foo" value="bar"/> + </map:generate> + <map:serialize type="xml"/> + </map:match> + + <map:match pattern="sub/**"> + <map:mount uri-prefix="sub" + src="resource://org/apache/cocoon/generation/sub/"/> + </map:match> + + <map:match pattern="v4"> + <map:generate type="virtual4" src="vpc-test.xml"/> + <map:serialize type="xml"/> + </map:match> + + </map:pipeline> + </map:pipelines> +</map:sitemap> Added: cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-source-param.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-source-param.xml?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-source-param.xml (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-source-param.xml Mon Mar 28 13:27:59 2005 @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test source="${cocoon.parameters.source}" foo2="${cocoon.parameters.foo2}"/> Added: cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-test.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-test.xml?view=auto&rev=159314 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-test.xml (added) +++ cocoon/trunk/src/test/org/apache/cocoon/generation/vpc-test.xml Mon Mar 28 13:27:59 2005 @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><test/> \ No newline at end of file