You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jb...@apache.org on 2006/01/16 18:46:13 UTC
svn commit: r369531 - in /cocoon/branches/BRANCH_2_1_X/src:
test/htmlunit/org/apache/cocoon/ test/org/apache/cocoon/acting/
test/org/apache/cocoon/generation/ test/org/apache/cocoon/transformation/
webapp/test-suite/caching/
Author: jbq
Date: Mon Jan 16 09:45:53 2006
New Revision: 369531
URL: http://svn.apache.org/viewcvs?rev=369531&view=rev
Log:
Adding test suite for CachingProcessingPipeline and CachingPointProcessingPipeline
Added:
cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java (with props)
cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/
cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap (with props)
cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt (with props)
Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java Mon Jan 16 09:45:53 2006
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+/**
+ * Test the CachingProcessingPipeline and CachingPointProcessingPipeline.
+ *
+ * Uses the test-suite/caching module in the Cocoon webapp. The pipelines
+ * invoke the IncrementGenerator and IncrementTransformer that both increment a
+ * value in an attribute of the Cocoon context.
+ *
+ * @version $Id$
+ */
+public class CachingPipelineTestCase extends HtmlUnitTestCase {
+ final String testPipeline = "/test-suite/caching/a";
+ final String clearCachePipeline = "/test-suite/caching/clear-cache";
+ final String checkPipeline = "/test-suite/caching/check";
+ final String resetPipeline = "/test-suite/caching/reset";
+ final String sitemapPath = "test-suite/caching/sitemap.xmap";
+ final String resultPath = "context/key[@name='count']";
+ public void testCachingProcessingPipeline() throws Exception {
+ // replace @pipeline.type@ with caching
+ copyWebappFile(sitemapPath, "@pipeline.type@", "caching");
+ // clear cache
+ loadResponse(clearCachePipeline);
+ // reset count
+ loadResponse(resetPipeline);
+ // execute pipeline a1 and a2
+ loadResponse(testPipeline + "1");
+ loadResponse(testPipeline + "2");
+ // check that count is 2
+ loadXmlPage(checkPipeline);
+ String count = evalXPath(resultPath);
+ assertEquals("4", count);
+ // check that store has 2 objects
+ }
+ public void testCachingPointProcessingPipeline() throws Exception {
+ // replace @pipeline.type@ with caching-point
+ copyWebappFile(sitemapPath, "@pipeline.type@", "caching-point");
+ // clear cache
+ loadResponse(clearCachePipeline);
+ // reset count
+ loadResponse(resetPipeline);
+ // execute pipeline a1 and a2
+ loadResponse(testPipeline + "1");
+ loadResponse(testPipeline + "2");
+ // check that count is 3
+ loadXmlPage(checkPipeline);
+ String count = evalXPath(resultPath);
+ assertEquals("3", count);
+ // check that store has 3 objects
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CachingPipelineTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java Mon Jan 16 09:45:53 2006
@@ -0,0 +1,39 @@
+/*
+ * 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.acting;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * Set context attribute "count" to zero for testing purposes.
+ *
+ * @version $Id$
+ */
+public class ResetCounterAction implements Action {
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
+ Context context = ObjectModelHelper.getContext(objectModel);
+ Integer count = new Integer(0);
+ context.setAttribute("count", count);
+ return new HashMap();
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/acting/ResetCounterAction.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java Mon Jan 16 09:45:53 2006
@@ -0,0 +1,67 @@
+/*
+ * 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.io.IOException;
+import java.util.Enumeration;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Outputs an XML representation of the set of attributes contained in the
+ * Cocoon environment's context for testing purposes.
+ *
+ * @version $Id$
+ */
+public class ContextGenerator implements Generator {
+ XMLConsumer consumer;
+ Map objectModel;
+
+ public void setConsumer(XMLConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ public void generate() throws IOException, SAXException, ProcessingException {
+ consumer.startDocument();
+ consumer.startElement("", "context", "context", new AttributesImpl());
+ Context context = ObjectModelHelper.getContext(objectModel);
+ Enumeration keys = context.getAttributeNames();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ Object value = context.getAttribute(key);
+ AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute("", "name", "name", "CDATA", key);
+ consumer.startElement("", "key", "key", attrs);
+ String str = value.toString();
+ consumer.characters(str.toCharArray(), 0, str.length());
+ consumer.endElement("", "key", "key");
+ }
+ consumer.endElement("", "context", "context");
+ consumer.endDocument();
+ }
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+ this.objectModel = objectModel;
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/ContextGenerator.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java Mon Jan 16 09:45:53 2006
@@ -0,0 +1,99 @@
+/*
+ * 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.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Increment context attribute "count" for testing purposes.
+ *
+ * This generator always returns a VALID validity, and the cache key is given as
+ * a sitemap parameter.
+ *
+ * @version $Id$
+ */
+public class IncrementGenerator implements Contextualizable, Generator, CacheableProcessingComponent {
+ XMLConsumer consumer;
+ Map objectModel;
+ String key;
+ Context context;
+
+ public void generate() throws IOException, SAXException, ProcessingException {
+ increment(objectModel, "count");
+
+ consumer.startDocument();
+ consumer.startElement("", "node", "node", new AttributesImpl());
+ consumer.endElement("", "node", "node");
+ consumer.endDocument();
+ }
+
+ public Context getAvalonContext() {
+ return context;
+ }
+
+ public void setConsumer(XMLConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+ this.objectModel = objectModel;
+ try {
+ this.key = par.getParameter("key");
+ } catch (ParameterException e) {
+ throw new CascadingRuntimeException("Could not find parameter key", e);
+ }
+ }
+
+ public static void increment(Map objectModel, String key) {
+ Context context = ObjectModelHelper.getContext(objectModel);
+ Integer count = (Integer) context.getAttribute(key);
+ if (count == null) {
+ count = new Integer(0);
+ }
+ count = new Integer(count.intValue() + 1);
+ context.setAttribute(key, count);
+ }
+
+ public Serializable getKey() {
+ return key;
+ }
+
+ public SourceValidity getValidity() {
+ return NOPValidity.SHARED_INSTANCE;
+ }
+
+ public void contextualize(org.apache.avalon.framework.context.Context arg0) throws ContextException {
+ this.context = context;
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/generation/IncrementGenerator.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java Mon Jan 16 09:45:53 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.transformation;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.generation.IncrementGenerator;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Increment context attribute "count" for testing purposes.
+ *
+ * This transformer always returns a VALID validity, and the cache key is given as
+ * a sitemap parameter.
+ *
+ * @version $Id$
+ */
+public class IncrementTransformer extends AbstractTransformer implements Transformer, CacheableProcessingComponent {
+ XMLConsumer consumer;
+ Map objectModel;
+ String key;
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+ this.objectModel = objectModel;
+ try {
+ this.key = par.getParameter("key");
+ } catch (ParameterException e) {
+ throw new CascadingRuntimeException("Could not find parameter key", e);
+ }
+ }
+
+ public Serializable getKey() {
+ return key;
+ }
+
+ public SourceValidity getValidity() {
+ return NOPValidity.SHARED_INSTANCE;
+ }
+
+ public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException {
+ IncrementGenerator.increment(objectModel, "count");
+ super.startElement(uri, loc, raw, a);
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/transformation/IncrementTransformer.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap (added)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap Mon Jan 16 09:45:53 2006
@@ -0,0 +1,64 @@
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ <map:components>
+ <map:generators default="increment">
+ <map:generator name="increment" src="org.apache.cocoon.generation.IncrementGenerator"/>
+ <map:generator name="context" src="org.apache.cocoon.generation.ContextGenerator"/>
+ </map:generators>
+
+ <map:transformers default="increment">
+ <map:transformer name="increment" src="org.apache.cocoon.transformation.IncrementTransformer"/>
+ </map:transformers>
+
+ <map:actions>
+ <map:action name="reset-counter" src="org.apache.cocoon.acting.ResetCounterAction"/>
+ </map:actions>
+ </map:components>
+
+ <map:pipelines>
+ <map:pipeline type="@pipeline.type@">
+ <map:match pattern="a1">
+ <map:generate pipeline-hints="caching-point">
+ <map:parameter name="key" value="a"/>
+ </map:generate>
+ <map:transform>
+ <map:parameter name="key" value="a1"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+
+ <map:match pattern="a2">
+ <map:generate pipeline-hints="caching-point">
+ <map:parameter name="key" value="a"/>
+ </map:generate>
+ <map:transform>
+ <map:parameter name="key" value="a2"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+ </map:pipeline>
+
+ <map:pipeline type="noncaching">
+ <map:match pattern="check">
+ <map:generate type="context"/>
+ <map:serialize type="xml"/>
+ </map:match>
+
+ <map:match pattern="clear-cache">
+ <map:act type="clear-cache">
+ <map:read src="success.txt"/>
+ </map:act>
+ </map:match>
+
+ <map:match pattern="reset">
+ <map:act type="reset-counter">
+ <map:read src="success.txt"/>
+ </map:act>
+ </map:match>
+
+ <map:match pattern="status">
+ <map:generate type="status"/>
+ <map:serialize type="xml"/>
+ </map:match>
+ </map:pipeline>
+ </map:pipelines>
+</map:sitemap>
Propchange: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/sitemap.xmap
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt?rev=369531&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt (added)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt Mon Jan 16 09:45:53 2006
@@ -0,0 +1 @@
+Success!
Propchange: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/webapp/test-suite/caching/success.txt
------------------------------------------------------------------------------
svn:keywords = Id