huber 2004/07/04 10:57:03
Modified: src/test/org/apache/cocoon/matching
WildcardURIMatcherTestCase.java
Added: src/test/org/apache/cocoon/matching
CookieMatcherTestCase.java
CookieMatcherTestCase.xtest
HeaderMatcherTestCase.java
HeaderMatcherTestCase.xtest
ParameterMatcherTestCase.java
ParameterMatcherTestCase.xtest
RegexpURIMatcherTestCase.java
RegexpURIMatcherTestCase.xtest
RequestAttributeMatcherTestCase.java
RequestAttributeMatcherTestCase.xtest
RequestParameterMatcherTestCase.java
RequestParameterMatcherTestCase.xtest
SessionAttributeMatcherTestCase.java
SessionAttributeMatcherTestCase.xtest
Log:
added junit tests for nearly all matching components of cocoon core
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.4 +22 -1
cocoon-2.1/src/test/org/apache/cocoon/matching/WildcardURIMatcherTestCase.java
Index: WildcardURIMatcherTestCase.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/matching/WildcardURIMatcherTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WildcardURIMatcherTestCase.java 6 Mar 2004 02:26:17 -0000 1.3
+++ WildcardURIMatcherTestCase.java 4 Jul 2004 17:57:03 -0000 1.4
@@ -16,16 +16,37 @@
package org.apache.cocoon.matching;
import java.util.Map;
-
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
+
public class WildcardURIMatcherTestCase extends SitemapComponentTestCase {
public WildcardURIMatcherTestCase(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(WildcardURIMatcherTestCase.class);
+ return suite;
+ }
+
public void testWildcardURIMatch() throws Exception {
getRequest().setRequestURI("/test/foo/bla/end");
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/CookieMatcherTestCase.java
Index: CookieMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
import org.apache.cocoon.environment.mock.MockCookie;
public class CookieMatcherTestCase extends SitemapComponentTestCase {
public CookieMatcherTestCase(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(CookieMatcherTestCase.class);
return suite;
}
/**
* A simple cookie matcher test
*/
public void testCookieMatch() throws Exception {
// create a cookie
// setting name := cookieName, value := cookieValue
Map cookies = getRequest().getCookieMap();
MockCookie mockCookie = new MockCookie();
mockCookie.setName("cookieName");
mockCookie.setValue("cookieValue");
cookies.put( "cookieName", mockCookie );
Parameters parameters = new Parameters();
Map result = match("cookie", "cookieName", parameters);
System.out.println(result);
assertNotNull("Test if cookie exists", result);
assertEquals("Test for cookie cookieName having value cookieValue",
"cookieValue", result.get("1"));
}
/**
* A simple cookie matcher test
*/
public void testCookieMatchFails() throws Exception {
// create a cookie
// setting name := cookieName, value := cookieValue
Map cookies = getRequest().getCookieMap();
MockCookie mockCookie = new MockCookie();
mockCookie.setName("cookieName");
mockCookie.setValue("cookieValue");
cookies.put( "cookieName", mockCookie );
Parameters parameters = new Parameters();
Map result = match( "cookie", "cookieNameDoesNotExists", parameters );
System.out.println(result);
assertNull( "Test if cookie does not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/CookieMatcherTestCase.xtest
Index: CookieMatcherTestCase.xtest
===================================================================
<?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: CookieMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance class="org.apache.cocoon.matching.CookieMatcher"
name="cookie"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/HeaderMatcherTestCase.java
Index: HeaderMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
public class HeaderMatcherTestCase extends SitemapComponentTestCase {
public HeaderMatcherTestCase(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(HeaderMatcherTestCase.class);
return suite;
}
/**
* A simple header matcher test
*/
public void testHeaderMatch() throws Exception {
// create a header attribute
final String headerName = "headerMatchTestCase";
final String headerValue = "headerMatchTestCaseValue";
getRequest().setHeader(headerName, headerValue );
Parameters parameters = new Parameters();
Map result = match("header", headerName, parameters);
System.out.println(result);
assertNotNull("Test if header entry exists", result);
assertEquals("Test for header " + headerName + " having value " +
headerValue, headerValue, result.get("1"));
}
/**
* A simple header matcher test
*/
public void testHeaderMatchFails() throws Exception {
final String headerNameDoesNotExist = "headerNameDoesNotExist";
final String headerName = "headerMatchTestCase";
final String headerValue = "headerMatchTestCaseValue";
getRequest().setHeader(headerName, headerValue );
Parameters parameters = new Parameters();
Map result = match("header", headerNameDoesNotExist, parameters);
assertNull( "Test if header entry " + headerNameDoesNotExist + " does
not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/HeaderMatcherTestCase.xtest
Index: HeaderMatcherTestCase.xtest
===================================================================
<?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: HeaderMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance class="org.apache.cocoon.matching.HeaderMatcher"
name="header"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/ParameterMatcherTestCase.java
Index: ParameterMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
public class ParameterMatcherTestCase extends SitemapComponentTestCase {
public ParameterMatcherTestCase(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(ParameterMatcherTestCase.class);
return suite;
}
/**
* A simple parameter matcher test
*/
public void testParameterMatch() throws Exception {
// create a parameter attribute
Parameters parameters = new Parameters();
final String parameterName = "paramterMatchTestCase";
final String parameterValue = "parameterMatchTestCaseValue";
parameters.setParameter( parameterName, parameterValue );
Map result = match("parameter", parameterName, parameters);
System.out.println(result);
assertNotNull("Test if parameter entry exists", result);
assertEquals("Test for parameter " + parameterName + " having value "
+ parameterValue, parameterValue, result.get("1"));
}
/**
* A simple parameter matcher test
*/
public void testParameterMatchFails() throws Exception {
Parameters parameters = new Parameters();
final String parameterNameDoesNotExist = "parameterNameDoesNotExist";
// create a parameter attribute
final String parameterName = "paramterMatchTestCase";
final String parameterValue = "parameterMatchTestCaseValue";
parameters.setParameter( parameterName, parameterValue );
Map result = match("parameter", parameterNameDoesNotExist,
parameters);
assertNull( "Test if parameter entry " + parameterNameDoesNotExist +
" does not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/ParameterMatcherTestCase.xtest
Index: ParameterMatcherTestCase.xtest
===================================================================
<?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: ParameterMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance class="org.apache.cocoon.matching.ParameterMatcher"
name="parameter"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RegexpURIMatcherTestCase.java
Index: RegexpURIMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
public class RegexpURIMatcherTestCase extends SitemapComponentTestCase {
public RegexpURIMatcherTestCase(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(RegexpURIMatcherTestCase.class);
return suite;
}
/**
* A simple regexp matcher test
*/
public void testRegexpURIMatch() throws Exception {
getRequest().setRequestURI("/test/foo/bla/end");
Parameters parameters = new Parameters();
Map result = match("regexp-uri", "(.*)", parameters);
System.out.println(result);
assertNotNull("Test if resource exists", result);
assertEquals("Test for .*", "test/foo/bla/end", result.get("1"));
result = match("regexp-uri", "(.*)/bla/(.*)", parameters);
System.out.println(result);
assertNotNull("Test if resource exists", result);
assertEquals("Test for (.*)/bla/(.*) {1}", "test/foo",
result.get("1"));
assertEquals("Test for (.*)/bla/(.*) {2}", "end", result.get("2"));
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RegexpURIMatcherTestCase.xtest
Index: RegexpURIMatcherTestCase.xtest
===================================================================
<?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: RegexpUriMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance class="org.apache.cocoon.matching.RegexpURIMatcher"
name="regexp-uri"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RequestAttributeMatcherTestCase.java
Index: RequestAttributeMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
public class RequestAttributeMatcherTestCase extends SitemapComponentTestCase
{
public RequestAttributeMatcherTestCase(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(RequestAttributeMatcherTestCase.class);
return suite;
}
/**
* A simple request-attribute matcher test
*/
public void testRequestAttributeMatch() throws Exception {
// create a request attribute
final String requestAttributeName = "requestAttributeMatchTestCase";
final String requestAttributeValue =
"requestAttributeMatchTestCaseValue";
getRequest().setAttribute( requestAttributeName,
requestAttributeValue );
Parameters parameters = new Parameters();
Map result = match("request-attribute", requestAttributeName,
parameters);
System.out.println(result);
assertNotNull("Test if request-attribute entry exists", result);
assertEquals("Test for request-attribute " + requestAttributeName + "
having value " + requestAttributeValue, requestAttributeValue, result.get("1"));
}
/**
* A simple request-attribute matcher test
*/
public void testHeaderMatchFails() throws Exception {
final String requestAttributeNameDoesNotExist =
"requestAttributeDoesNotExist";
// create a request attribute
final String requestAttributeName = "requestAttributeMatchTestCase";
final String requestAttributeValue =
"requestAttributeMatchTestCaseValue";
getRequest().setAttribute( requestAttributeName,
requestAttributeValue );
Parameters parameters = new Parameters();
Map result = match("request-attribute",
requestAttributeNameDoesNotExist, parameters);
assertNull( "Test if request-attribute entry " +
requestAttributeNameDoesNotExist + " does not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RequestAttributeMatcherTestCase.xtest
Index: RequestAttributeMatcherTestCase.xtest
===================================================================
<?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: RequestAttributeMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance
class="org.apache.cocoon.matching.RequestAttributeMatcher"
name="request-attribute"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RequestParameterMatcherTestCase.java
Index: RequestParameterMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
public class RequestParameterMatcherTestCase extends SitemapComponentTestCase
{
public RequestParameterMatcherTestCase(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(RequestParameterMatcherTestCase.class);
return suite;
}
/**
* A simple request-parameter matcher test
*/
public void testRequestParameterMatch() throws Exception {
// create a request parameter
final String requestParameterName = "requestParameterMatchTestCase";
final String requestParameterValue =
"requestParameterMatchTestCaseValue";
getRequest().addParameter( requestParameterName,
requestParameterValue );
Parameters parameters = new Parameters();
Map result = match("request-parameter", requestParameterName,
parameters);
System.out.println(result);
assertNotNull("Test if request-parameter entry exists", result);
assertEquals("Test for request-parameter " + requestParameterName + "
having value " + requestParameterValue, requestParameterValue, result.get("1"));
}
/**
* A simple request-parameter matcher test
*/
public void testParameterMatchFails() throws Exception {
final String requestParameterNameDoesNotExist =
"requestParameterDoesNotExist";
// create a request attribute
// create a request parameter
final String requestParameterName = "requestParameterMatchTestCase";
final String requestParameterValue =
"requestParameterMatchTestCaseValue";
getRequest().addParameter( requestParameterName,
requestParameterValue );
Parameters parameters = new Parameters();
Map result = match("request-parameter",
requestParameterNameDoesNotExist, parameters);
assertNull( "Test if request-parameter entry " +
requestParameterNameDoesNotExist + " does not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/RequestParameterMatcherTestCase.xtest
Index: RequestParameterMatcherTestCase.xtest
===================================================================
<?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: RequestParameterMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance
class="org.apache.cocoon.matching.RequestParameterMatcher"
name="request-parameter"/>
</matchers>
</components>
</testcase>
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/SessionAttributeMatcherTestCase.java
Index: SessionAttributeMatcherTestCase.java
===================================================================
/*
* 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.matching;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.SitemapComponentTestCase;
import org.apache.cocoon.environment.Session;
public class SessionAttributeMatcherTestCase extends SitemapComponentTestCase
{
public SessionAttributeMatcherTestCase(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(SessionAttributeMatcherTestCase.class);
return suite;
}
/**
* A simple session-attribute matcher test
*/
public void testSessionAttributeMatch() throws Exception {
// create a session attribute
final String sessionAttributeName = "sessionAttributeMatchTestCase";
final String sessionAttributeValue =
"sessionAttributeMatchTestCaseValue";
Session session = getRequest().getSession(true);
session.setAttribute(sessionAttributeName, sessionAttributeValue );
Parameters parameters = new Parameters();
Map result = match("session-attribute", sessionAttributeName,
parameters);
System.out.println(result);
assertNotNull("Test if session-attribute entry exists", result);
assertEquals("Test for session-attribute " + sessionAttributeName + "
having value " + sessionAttributeValue, sessionAttributeValue, result.get("1"));
}
/**
* A simple request-attribute matcher test
*/
public void testSessionMatchFails() throws Exception {
final String sessionAttributeNameDoesNotExist =
"sessionAttributeDoesNotExist";
Parameters parameters = new Parameters();
// test w/o an existing session
getRequest().clearSession();
Map result;
result = match("session-attribute", sessionAttributeNameDoesNotExist,
parameters);
assertNull( "Test if session-attribute entry " +
sessionAttributeNameDoesNotExist + " does not exist", result );
// create a session attribute
final String sessionAttributeName = "sessionAttributeMatchTestCase";
final String sessionAttributeValue =
"sessionAttributeMatchTestCaseValue";
Session session = getRequest().getSession(true);
session.setAttribute(sessionAttributeName, sessionAttributeValue );
// test w an existing session
result = match("session-attribute", sessionAttributeNameDoesNotExist,
parameters);
assertNull( "Test if session-attribute entry " +
sessionAttributeNameDoesNotExist + " does not exist", result );
}
}
1.1
cocoon-2.1/src/test/org/apache/cocoon/matching/SessionAttributeMatcherTestCase.xtest
Index: SessionAttributeMatcherTestCase.xtest
===================================================================
<?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: SessionAttributeMatcher
</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.matching.MatcherSelector"
shorthand="matchers"
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"/>
<matchers logger="test">
<component-instance
class="org.apache.cocoon.matching.SessionAttributeMatcher"
name="session-attribute"/>
</matchers>
</components>
</testcase>