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: /**
026: * Test case for RegexpHeaderSelector.
027: *
028: * @version CVS $Id: RegexpHeaderSelectorTestCase.java 433543 2006-08-22 06:22:54Z crossley $
029: */
030: public class RegexpHeaderSelectorTestCase extends
031: SitemapComponentTestCase {
032:
033: private static final String REGEXP_HEADER_SELECTOR = "regexp-header";
034:
035: /**
036: * Run this test suite from commandline
037: *
038: * @param args commandline arguments (ignored)
039: */
040: public static void main(String[] args) {
041: TestRunner.run(suite());
042: }
043:
044: /** Create a test suite.
045: * This test suite contains all test cases of this class.
046: * @return the Test object containing all test cases.
047: */
048: public static Test suite() {
049: TestSuite suite = new TestSuite(
050: RegexpHeaderSelectorTestCase.class);
051: return suite;
052: }
053:
054: /**
055: * A simple regexp-header selector test
056: */
057: public void testRegexpHeaderSelectEmpty() throws Exception {
058: // create a header
059: final String headerName = "headerSelectorTestCase";
060: getRequest().setHeader(headerName, "");
061:
062: Parameters parameters = new Parameters();
063: boolean result;
064:
065: result = this .select(REGEXP_HEADER_SELECTOR, "empty",
066: parameters);
067: System.out.println(result);
068: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
069: + " selects successfully", result);
070:
071: result = this .select(REGEXP_HEADER_SELECTOR, "number",
072: parameters);
073: System.out.println(result);
074: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
075: + " does not select successfully", !result);
076:
077: result = this .select(REGEXP_HEADER_SELECTOR,
078: "non-defined-name", parameters);
079: System.out.println(result);
080: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
081: + " does not select successfully", !result);
082: }
083:
084: /**
085: * A simple regexp-header selector test
086: */
087: public void testRegexpHeaderSelectNumber() throws Exception {
088: // create a header
089: final String headerName = "headerSelectorTestCase";
090: final String headerName2 = "headerSelectorTestCase1";
091:
092: Parameters parameters = new Parameters();
093: boolean result;
094:
095: // test w/o set request parameter
096: result = this .select(REGEXP_HEADER_SELECTOR, "empty",
097: parameters);
098: System.out.println(result);
099: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
100: + " does not select successfully", !result);
101:
102: // this time, set the header
103: getRequest().setHeader(headerName, "");
104:
105: // create another header
106: getRequest().setHeader(headerName2, "123");
107:
108: // override configured header name
109: parameters.setParameter("header-name", headerName2);
110:
111: result = this .select(REGEXP_HEADER_SELECTOR, "empty",
112: parameters);
113: System.out.println(result);
114: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
115: + " does not select successfully", !result);
116:
117: result = this .select(REGEXP_HEADER_SELECTOR, "number",
118: parameters);
119: System.out.println(result);
120: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
121: + " selects successfully", result);
122:
123: result = this .select(REGEXP_HEADER_SELECTOR,
124: "non-defined-name", parameters);
125: System.out.println(result);
126: assertTrue("Test is " + REGEXP_HEADER_SELECTOR
127: + " does not select successfully", !result);
128: }
129: }
|