You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by il...@apache.org on 2012/06/08 17:50:03 UTC

svn commit: r1348125 - in /cocoon/cocoon3/trunk/cocoon-sax/src: main/java/org/apache/cocoon/sax/component/XSLTTransformer.java test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java

Author: ilgrosso
Date: Fri Jun  8 15:50:02 2012
New Revision: 1348125

URL: http://svn.apache.org/viewvc?rev=1348125&view=rev
Log:
[COCOON3-62] XSLTTransformer.constructCacheKey() updated and dedicated test added

Added:
    cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java   (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java?rev=1348125&r1=1348124&r2=1348125&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java Fri Jun  8 15:50:02 2012
@@ -31,6 +31,8 @@ import javax.xml.transform.sax.Transform
 import javax.xml.transform.stream.StreamSource;
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
+import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
 import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
@@ -260,7 +262,11 @@ public class XSLTTransformer extends Abs
             throw new SetupException(this.getClass().getSimpleName() + " has no source.");
         }
 
-        return new TimestampCacheKey(this.source, URLUtils.getLastModified(this.source));
+        final CompoundCacheKey cacheKey = new CompoundCacheKey();
+        cacheKey.addCacheKey(new TimestampCacheKey(this.source, URLUtils.getLastModified(this.source)));
+        cacheKey.addCacheKey(new ParameterCacheKey("contextParameters", this.parameters));
+
+        return cacheKey;
     }
 
     /**

Added: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java?rev=1348125&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java Fri Jun  8 15:50:02 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sax.component;
+
+import static junit.framework.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.util.Collections;
+import org.apache.cocoon.pipeline.CachingPipeline;
+import org.apache.cocoon.pipeline.caching.Cache;
+import org.apache.cocoon.pipeline.caching.SimpleCache;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.junit.Test;
+
+public class XSLTTransformerTest {
+
+    private CachingPipeline<SAXPipelineComponent> makePipeline(final Cache cache, final String paramValue) {
+        CachingPipeline<SAXPipelineComponent> pipeline = new CachingPipeline<SAXPipelineComponent>();
+        pipeline.setCache(cache);
+
+        pipeline.addComponent(new XMLGenerator(getClass().getResource("/test.xml")));
+
+        XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/test.xslt"));
+        xslt.setParameters(Collections.singletonMap("myParam", paramValue));
+        pipeline.addComponent(xslt);
+
+        pipeline.addComponent(XMLSerializer.createXMLSerializer());
+
+        return pipeline;
+    }
+
+    @Test
+    public void cache() throws Exception {
+        Cache cache = new SimpleCache();
+
+        CachingPipeline<SAXPipelineComponent> pipeline1 = makePipeline(cache, "value1");
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pipeline1.setup(baos);
+        pipeline1.execute();
+        String result1 = new String(baos.toByteArray(), "UTF-8");
+
+        CachingPipeline<SAXPipelineComponent> pipeline2 = makePipeline(cache, "value2");
+        baos = new ByteArrayOutputStream();
+        pipeline2.setup(baos);
+        pipeline2.execute();
+        String result2 = new String(baos.toByteArray(), "UTF-8");
+
+        assertFalse("Pipeline caching is not working as expected", result1.equals(result2));
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XSLTTransformerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain