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 HeaderSelectorTestCase extends SitemapComponentTestCase {
026:
027: private static final String HEADER_SELECTOR = "header";
028:
029: /**
030: * Run this test suite from commandline
031: *
032: * @param args commandline arguments (ignored)
033: */
034: public static void main(String[] args) {
035: TestRunner.run(suite());
036: }
037:
038: /** Create a test suite.
039: * This test suite contains all test cases of this class.
040: * @return the Test object containing all test cases.
041: */
042: public static Test suite() {
043: TestSuite suite = new TestSuite(HeaderSelectorTestCase.class);
044: return suite;
045: }
046:
047: /**
048: * A simple header select test
049: */
050: public void testHeaderSelect() throws Exception {
051: final String headerName = "headerSelectorTestCase";
052: final String headerValue = "headerValue";
053: // create a header
054: // setting name := headerName, value := headerValue
055: getRequest().setHeader(headerName, headerValue);
056:
057: Parameters parameters = new Parameters();
058: boolean result;
059:
060: // test selection success
061: result = this .select(HEADER_SELECTOR, headerValue, parameters);
062: System.out.println(result);
063: assertTrue("Test if a header is selected", result);
064:
065: // test selection failure
066: result = this .select(HEADER_SELECTOR, "unknownHeaderValue",
067: parameters);
068: System.out.println(result);
069: assertTrue("Test if a header is not selected", !result);
070: }
071:
072: /**
073: * A simple header select test
074: */
075: public void testHeaderSelectUsingParameters() throws Exception {
076: final String headerName = "headerSelectorTestCase1";
077: final String headerValue = "headerValue1";
078: // create a header
079: // setting name := headerName, value := headerValue
080: getRequest().setHeader(headerName, headerValue);
081:
082: // check the header as defined by this parameter, not as
083: // defined in the component configuration
084: Parameters parameters = new Parameters();
085: parameters.setParameter("header-name", headerName);
086:
087: boolean result;
088:
089: // test selection success
090: result = this .select(HEADER_SELECTOR, headerValue, parameters);
091: System.out.println(result);
092: assertTrue("Test if a header is selected", result);
093:
094: // test selection failure
095: result = this .select(HEADER_SELECTOR, "unknownHeaderValue",
096: parameters);
097: System.out.println(result);
098: assertTrue("Test if a header is not selected", !result);
099: }
100: }
|