Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 49620 invoked from network); 16 Jan 2006 17:46:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Jan 2006 17:46:42 -0000 Received: (qmail 29279 invoked by uid 500); 16 Jan 2006 17:46:41 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 29228 invoked by uid 500); 16 Jan 2006 17:46:41 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 29217 invoked by uid 99); 16 Jan 2006 17:46:41 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jan 2006 09:46:41 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 16 Jan 2006 09:46:40 -0800 Received: (qmail 49498 invoked by uid 65534); 16 Jan 2006 17:46:19 -0000 Message-ID: <20060116174619.49495.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Mon, 16 Jan 2006 17:46:13 -0000 To: cvs@cocoon.apache.org From: jbq@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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