001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.selection;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021: import junit.textui.TestRunner;
022: import org.apache.avalon.framework.parameters.Parameters;
023: import org.apache.cocoon.SitemapComponentTestCase;
024:
025: public class RegexpRequestParameterSelectorTestCase extends
026: SitemapComponentTestCase {
027:
028: /**
029: * Run this test suite from commandline
030: *
031: * @param args commandline arguments (ignored)
032: */
033: public static void main(String[] args) {
034: TestRunner.run(suite());
035: }
036:
037: /** Create a test suite.
038: * This test suite contains all test cases of this class.
039: * @return the Test object containing all test cases.
040: */
041: public static Test suite() {
042: TestSuite suite = new TestSuite(
043: RegexpRequestParameterSelectorTestCase.class);
044: return suite;
045: }
046:
047: /**
048: * A simple regexp-request-parameter selector test
049: */
050: public void testRegexpRequestParameterSelectEmpty()
051: throws Exception {
052: // create a request parameter
053: getRequest().addParameter(
054: "parameterRegexpRequestParameterSelector", "");
055:
056: Parameters parameters = new Parameters();
057: boolean result;
058:
059: result = this .select("regexp-request-parameter", "empty",
060: parameters);
061: System.out.println(result);
062: assertTrue(
063: "Test is regexp-request-parameter selects successfully",
064: result);
065:
066: result = this .select("regexp-request-parameter", "number",
067: parameters);
068: System.out.println(result);
069: assertTrue(
070: "Test is regexp-request-parameter does not select successfully",
071: !result);
072:
073: result = this .select("regexp-request-parameter",
074: "non-defined-name", parameters);
075: System.out.println(result);
076: assertTrue(
077: "Test is regexp-request-parameter does not select successfully",
078: !result);
079: }
080:
081: /**
082: * A simple regexp-request-parameter selector test
083: */
084: public void testRegexpRequestParameterSelectNumber()
085: throws Exception {
086: Parameters parameters = new Parameters();
087: boolean result;
088:
089: // test w/o set request parameter
090: result = this .select("regexp-request-parameter", "number",
091: parameters);
092: System.out.println(result);
093: assertTrue(
094: "Test is regexp-request-parameter does not select successfully",
095: !result);
096:
097: // create a request parameter
098: getRequest().addParameter(
099: "parameterRegexpRequestParameterSelector1", "123");
100:
101: // override configured parameter name
102: parameters.setParameter("parameter-name",
103: "parameterRegexpRequestParameterSelector1");
104:
105: result = this .select("regexp-request-parameter", "number",
106: parameters);
107: System.out.println(result);
108: assertTrue(
109: "Test is regexp-request-parameter does not selects successfully",
110: result);
111:
112: result = this .select("regexp-request-parameter",
113: "non-defined-name", parameters);
114: System.out.println(result);
115: assertTrue(
116: "Test is regexp-request-parameter does not select successfully",
117: !result);
118: }
119: }
|