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 RequestParameterSelectorTestCase 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: RequestParameterSelectorTestCase.class);
044: return suite;
045: }
046:
047: /**
048: * A request-parameter parameter select test
049: */
050: public void testRequestParameterSelect() throws Exception {
051: final String parameterName = "requestParameterSelector";
052: final String parameterValue = "requestParameterSelectorValue";
053: getRequest().addParameter(parameterName, parameterValue);
054: Parameters parameters = new Parameters();
055: boolean result;
056:
057: // test selection success
058: result = this .select("request-parameter", parameterValue,
059: parameters);
060: System.out.println(result);
061: assertTrue("Test if a requst parameter is selected", result);
062:
063: // test selection failure
064: result = this .select("request-parameter", "unknownValue",
065: parameters);
066: System.out.println(result);
067: assertTrue("Test if a request parameter is not selected",
068: !result);
069: }
070:
071: /**
072: * A request-parameter parameter select test
073: */
074: public void testRequestParameterSelectOverridden() throws Exception {
075: final String parameterName = "requestParameterSelector1";
076: final String parameterValue = "requestParameterSelectorValue1";
077: getRequest().addParameter(parameterName, parameterValue);
078:
079: final String parameterNameOverridden = "requestParameterSelector";
080: final String parameterValueOverridden = "requestParameterSelectorValue";
081: getRequest().addParameter(parameterNameOverridden,
082: parameterValueOverridden);
083:
084: Parameters parameters = new Parameters();
085: parameters.setParameter("parameter-name", parameterName);
086: boolean result;
087:
088: // test selection success
089: result = this .select("request-parameter", parameterValue,
090: parameters);
091: System.out.println(result);
092: assertTrue("Test if a requst attribtue is selected", result);
093:
094: // test selection failure
095: result = this .select("request-parameter",
096: parameterValueOverridden, parameters);
097: System.out.println(result);
098: assertTrue("Test if a request parameter is not selected",
099: !result);
100: }
101: }
|