You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/01/29 23:07:33 UTC

svn commit: r616536 - in /cocoon/whiteboard/micro/misc: cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/ cocoon-micro-it-block/src/main/resources/COB-INF/ cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/ cocoon-webapp/src...

Author: reinhard
Date: Tue Jan 29 14:07:32 2008
New Revision: 616536

URL: http://svn.apache.org/viewvc?rev=616536&view=rev
Log:
add test for accessing the object model from within a generator and redirection (redirecting to a servlet source doesn't work ATM)

Added:
    cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java   (with props)
    cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java   (with props)
    cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java   (with props)
Modified:
    cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/overview.html
    cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/sitemap.xmap
    cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/cocoon-micro-it-sitemap-components.xml
    cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ExpressionLanguageTest.java

Added: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java?rev=616536&view=auto
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java (added)
+++ cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java Tue Jan 29 14:07:32 2008
@@ -0,0 +1,34 @@
+package org.apache.cocoon.micro.it;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.generation.AbstractGenerator;
+import org.apache.cocoon.xml.AttributesImpl;
+import org.xml.sax.SAXException;
+
+public class RequestParametersGenerator extends AbstractGenerator {
+
+    public void generate() throws IOException, SAXException, ProcessingException {
+        Request request = ObjectModelHelper.getRequest(this.objectModel);
+
+        this.contentHandler.startDocument();
+        this.contentHandler.startElement("", "request-paramters", "request-paramters", new AttributesImpl());
+
+        Enumeration parameterNames = request.getParameterNames();
+        while (parameterNames.hasMoreElements()) {
+            String name = (String) parameterNames.nextElement();
+            String value = (String) request.getParameter(name);
+            this.contentHandler.startElement("", name, name, new AttributesImpl());
+            this.contentHandler.characters(value.toCharArray(), 0, value.length());
+            this.contentHandler.endElement("", name, name);
+        }
+
+        this.contentHandler.endElement("", "request-paramters", "request-paramters");
+        this.contentHandler.endDocument();
+    }
+
+}

Propchange: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/RequestParametersGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/overview.html
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/overview.html?rev=616536&r1=616535&r2=616536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/overview.html (original)
+++ cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/overview.html Tue Jan 29 14:07:32 2008
@@ -45,5 +45,20 @@
 	<ul>
 		<li><a href="ssf/local">servlet:/</a>: Using a local servlet service.</li>
 	</ul>
+	<h2>Expression language</h2>
+	<ul>
+		<li><a href="expression-language/jexl?fileName=simple">request attribute (jexl)</a>: Accessing a request attribute using Jexl.</li>
+		<li><a href="expression-language/jxpath?fileName=simple">request attribute (jxpath)</a>: Accessing a request attribute using JXPath.</li>
+		<li><a href="expression-language/map/simple">sitemap parameter</a>: Accessing a sitemap parameter.</li>
+		<li><a href="expression-language/nested/simple">nested matchers</a>: Accessing a parameter from one level above.</li>
+	</ul>
+	<h2>Redirects</h2>
+	<ul>
+		<li><a href="redirect/www.orf.at">Temporary (302)</a>: Temporary redirect to orf.at.</li>
+	</ul>
+	<h2>Object Model</h2>
+	<ul>
+		<li><a href="object-model/request-parameters?a=1&b=2&c=3">All request parameters</a>: Print all request parameters.</li>
+	</ul>
   </body>
 </html>

Modified: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/sitemap.xmap?rev=616536&r1=616535&r2=616536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/sitemap.xmap (original)
+++ cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/COB-INF/sitemap.xmap Tue Jan 29 14:07:32 2008
@@ -100,6 +100,33 @@
         <map:generate src="sax-pipeline/{map:1}.xml"/>
         <map:serialize type="xml"/>
       </map:match>
+      <map:match pattern="**">
+        <map:match pattern="expression-language/*/*">
+          <map:match pattern="expression-language/nested/*">
+            <map:generate src="sax-pipeline/{map:../2}.xml"/>
+            <map:serialize type="xml"/>
+          </map:match>
+        </map:match>
+      </map:match>
+    </map:pipeline>
+
+    <!-- ~~~~~~~~~~~~~~~~ object model ~~~~~~~~~~~~~~~ -->
+    <map:pipeline>
+      <map:match pattern="object-model/request-parameters">
+        <map:generate type="request-parameters"/>
+        <map:serialize type="xml"/>
+      </map:match>
+    </map:pipeline>
+
+    <!-- ~~~~~~~~~~~~~~~~ redirect ~~~~~~~~~~~~~~~ -->
+    <map:pipeline>
+      <map:match pattern="redirect/www.orf.at">
+        <map:redirect-to uri="http://www.orf.at"/>
+      </map:match>
+      <!-- Redirecting to a servlet service doesn't work -->
+      <!--map:match pattern="redirect/sax-pipeline/simple-xml">
+        <map:redirect-to uri="servlet:/sax-pipeline/simple-xml"/>
+      </map:match-->
     </map:pipeline>
 
     <!-- ~~~~~~~~~~~~~~~~ error handling ~~~~~~~~~~~~~~~ -->

Modified: cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/cocoon-micro-it-sitemap-components.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/cocoon-micro-it-sitemap-components.xml?rev=616536&r1=616535&r2=616536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/cocoon-micro-it-sitemap-components.xml (original)
+++ cocoon/whiteboard/micro/misc/cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/cocoon-micro-it-sitemap-components.xml Tue Jan 29 14:07:32 2008
@@ -26,4 +26,6 @@
 
   <bean name="org.apache.cocoon.generation.Generator/date" class="org.apache.cocoon.micro.it.DateGenerator"/>
 
+  <bean name="org.apache.cocoon.generation.Generator/request-parameters" class="org.apache.cocoon.micro.it.RequestParametersGenerator"/>
+
 </beans>

Modified: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ExpressionLanguageTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ExpressionLanguageTest.java?rev=616536&r1=616535&r2=616536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ExpressionLanguageTest.java (original)
+++ cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ExpressionLanguageTest.java Tue Jan 29 14:07:32 2008
@@ -43,12 +43,22 @@
         assertEquals("text/xml", this.response.getContentType());
         assertXPath("/simple", "simple-text");
     }
-    
+
     /**
      * Map language test
      */
     public void testMap() throws Exception {
         this.loadXmlPage("expression-language/map/simple");
+        assertTrue(this.response.getStatusCode() == 200);
+        assertEquals("text/xml", this.response.getContentType());
+        assertXPath("/simple", "simple-text");
+    }
+
+    /**
+     * Nested matchers/maps
+     */
+    public void testNextedMap() throws Exception {
+        this.loadXmlPage("expression-language/nested/simple");
         assertTrue(this.response.getStatusCode() == 200);
         assertEquals("text/xml", this.response.getContentType());
         assertXPath("/simple", "simple-text");

Added: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java?rev=616536&view=auto
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java (added)
+++ cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java Tue Jan 29 14:07:32 2008
@@ -0,0 +1,39 @@
+package org.apache.cocoon.micro.it;
+
+/*
+ * 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.
+ */
+
+import org.apache.cocoon.tools.it.HtmlUnitTestCase;
+import org.custommonkey.xmlunit.Diff;
+
+/**
+ * Test accessing the object model.
+ */
+public class ObjectModelTest extends HtmlUnitTestCase {
+
+    /**
+     * Accessing all request parameters from within a generator.
+     */
+    public void testTemporaryRedirect() throws Exception {
+        this.loadResponse("object-model/request-parameters?a=1&b=2&c=3");
+        assertEquals(200, this.response.getStatusCode());
+        String content = this.response.getContentAsString();
+        String expectedContent = "<?xml version=\"1.0\"?><request-paramters><a>1</a><c>3</c><b>2</b></request-paramters>";
+        assertTrue(new Diff(expectedContent, content).similar());
+    }
+
+}

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/ObjectModelTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java?rev=616536&view=auto
==============================================================================
--- cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java (added)
+++ cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java Tue Jan 29 14:07:32 2008
@@ -0,0 +1,36 @@
+package org.apache.cocoon.micro.it;
+
+/*
+ * 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.
+ */
+
+import org.apache.cocoon.tools.it.HtmlUnitTestCase;
+
+/**
+ * Test redirecting
+ */
+public class RedirectTest extends HtmlUnitTestCase {
+
+    /**
+     * A temporary redirect
+     */
+    public void testTemporaryRedirect() throws Exception {
+        this.loadResponse("redirect/www.orf.at");
+        assertEquals(302, this.response.getStatusCode());
+        assertEquals("http://www.orf.at", this.response.getResponseHeaderValue("Location"));
+    }
+
+}

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/micro/misc/cocoon-webapp/src/test/java/org/apache/cocoon/micro/it/RedirectTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Re: svn commit: r616536 - in /cocoon/whiteboard/micro/misc: cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/ cocoon-micro-it-block/src/main/resources/COB-INF/ cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/ cocoon-webapp/src...

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> reinhard@apache.org pisze:
>> Author: reinhard Date: Tue Jan 29 14:07:32 2008 New Revision: 616536
>> 
>> URL: http://svn.apache.org/viewvc?rev=616536&view=rev Log: add test for
>> accessing the object model from within a generator and redirection
>> (redirecting to a servlet source doesn't work ATM)
> 
> Which object model you want to test here?

TBH, from an integration test perspective, I don't care which one. I want to 
test if the object model can be accessed at all from within a generator. I want 
to make sure that the OM is still available after doing refactorings, because I 
guess that the old one will be removed sooner or later.


>> + +public class RequestParametersGenerator extends AbstractGenerator { + +
>> public void generate() throws IOException, SAXException,
>> ProcessingException { +        Request request =
>> ObjectModelHelper.getRequest(this.objectModel); +
> 
> Modern way to access request object is PipelineInfoProvider bean.

ok

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: svn commit: r616536 - in /cocoon/whiteboard/micro/misc: cocoon-micro-it-block/src/main/java/org/apache/cocoon/micro/it/ cocoon-micro-it-block/src/main/resources/COB-INF/ cocoon-micro-it-block/src/main/resources/META-INF/cocoon/spring/ cocoon-webapp/src...

Posted by Grzegorz Kossakowski <gk...@apache.org>.
reinhard@apache.org pisze:
> Author: reinhard
> Date: Tue Jan 29 14:07:32 2008
> New Revision: 616536
> 
> URL: http://svn.apache.org/viewvc?rev=616536&view=rev
> Log:
> add test for accessing the object model from within a generator and redirection (redirecting to a servlet source doesn't work ATM)

Which object model you want to test here?

> +
> +public class RequestParametersGenerator extends AbstractGenerator {
> +
> +    public void generate() throws IOException, SAXException, ProcessingException {
> +        Request request = ObjectModelHelper.getRequest(this.objectModel);
> +

Modern way to access request object is PipelineInfoProvider bean.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/