You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ug...@apache.org on 2004/09/03 18:06:23 UTC
svn commit: rev 37489 - in cocoon/branches/BRANCH_2_1_X/src: java/org/apache/cocoon/selection test/org/apache/cocoon/environment/mock test/org/apache/cocoon/selection
Author: ugo
Date: Fri Sep 3 09:06:21 2004
New Revision: 37489
Added:
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.java (contents, props changed)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.xtest (contents, props changed)
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/RegexpHeaderSelector.java
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/mock/MockRequest.java
Log:
Sync with trunk
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/RegexpHeaderSelector.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/RegexpHeaderSelector.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/RegexpHeaderSelector.java Fri Sep 3 09:06:21 2004
@@ -49,8 +49,7 @@
* also be specified as a <code><map:parameter .../></code> inside the
* pipeline itself.</p>
*
- * @version CVS $Revision: 1.0 $
- * @author <a href="mailto:colin@colina.demon.co.uk">Colin Adams</a>
+ * @version CVS $Id: RegexpHeaderSelector.java 36086 2004-08-08 14:27:52Z ugo $
*/
public class RegexpHeaderSelector extends AbstractRegexpSelector {
Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/mock/MockRequest.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/mock/MockRequest.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/mock/MockRequest.java Fri Sep 3 09:06:21 2004
@@ -334,5 +334,13 @@
public void setHeader( String key, String value ) {
this.headers.put(key, value );
}
+
+ public void setMethod( String method ) {
+ this.method = method;
+ }
+
+ public void clearSession() {
+ this.session = null;
+ }
}
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.java Fri Sep 3 09:06:21 2004
@@ -0,0 +1,117 @@
+/*
+* 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.selection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.SitemapComponentTestCase;
+
+/**
+ * Test case for RegexpHeaderSelector.
+ *
+ * @version CVS $Id$
+ */
+public class RegexpHeaderSelectorTestCase extends SitemapComponentTestCase {
+
+ private final String REGEXP_HEADER_SELECTOR = "regexp-header";
+
+ public RegexpHeaderSelectorTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Run this test suite from commandline
+ *
+ * @param args commandline arguments (ignored)
+ */
+ public static void main( String[] args ) {
+ TestRunner.run(suite());
+ }
+
+ /** Create a test suite.
+ * This test suite contains all test cases of this class.
+ * @return the Test object containing all test cases.
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(RegexpHeaderSelectorTestCase.class);
+ return suite;
+ }
+
+
+ /**
+ * A simple regexp-header selector test
+ */
+ public void testRegexpHeaderSelectEmpty() throws Exception {
+ // create a header
+ final String headerName = "headerSelectorTestCase";
+ getRequest().setHeader(headerName, "");
+
+ Parameters parameters = new Parameters();
+ boolean result;
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " selects successfully", result );
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "number", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result );
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "non-defined-name", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result );
+ }
+
+ /**
+ * A simple regexp-header selector test
+ */
+ public void testRegexpHeaderSelectNumber() throws Exception {
+ // create a header
+ final String headerName = "headerSelectorTestCase";
+ final String headerName2 = "headerSelectorTestCase1";
+
+ Parameters parameters = new Parameters();
+ boolean result;
+
+ // test w/o set request parameter
+ result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result );
+
+ // this time, set the header
+ getRequest().setHeader(headerName, "");
+
+ // create another header
+ getRequest().setHeader(headerName2, "123");
+
+ // override configured header name
+ parameters.setParameter( "header-name", headerName2 );
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result );
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "number", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " selects successfully", result );
+
+ result = this.select( REGEXP_HEADER_SELECTOR, "non-defined-name", parameters );
+ System.out.println( result );
+ assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result );
+ }
+}
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.xtest
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.xtest Fri Sep 3 09:06:21 2004
@@ -0,0 +1,76 @@
+<?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>
+ <annotation>
+ Test Cases: RegexpHeaderSelector
+ </annotation>
+
+ <logkit>
+ <factories>
+ <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
+ </factories>
+ <targets>
+ <stream id="root">
+ <stream>System.out</stream>
+ <format type="extended">
+ %7.7{priority} %5.5{time} [%9.9{category}] (%{context}): %{message}\n%{throwable}
+ </format>
+ </stream>
+ </targets>
+ <categories>
+ <category name="test" log-level="WARN">
+ <log-target id-ref="root"/>
+ </category>
+ </categories>
+ </logkit>
+
+ <context/>
+
+ <roles>
+ <role name="org.apache.excalibur.source.SourceFactorySelector"
+ shorthand="source-factories"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
+
+ <role name="org.apache.excalibur.source.SourceResolver"
+ shorthand="source-resolver"
+ default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+
+ <role name="org.apache.cocoon.selection.SelectorSelector"
+ shorthand="selectors"
+ default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+ </roles>
+
+ <components>
+ <source-factories>
+ <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/>
+ <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
+ </source-factories>
+
+ <source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+
+ <selectors logger="test">
+ <component-instance class="org.apache.cocoon.selection.RegexpHeaderSelector"
+ name="regexp-header">
+ <pattern name="empty">^$</pattern>
+ <pattern name="number">^[0-9]+$</pattern>
+ <pattern name="string">^.+$</pattern>
+ <header-name>headerSelectorTestCase</header-name>
+ </component-instance>
+ </selectors>
+ </components>
+
+</testcase>