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 RequestAttributeSelectorTestCase 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: RequestAttributeSelectorTestCase.class);
044: return suite;
045: }
046:
047: /**
048: * A request-attribute parameter select test
049: */
050: public void testRequestAttributeSelect() throws Exception {
051: final String attributeName = "requestAttributeSelector";
052: final String attributeValue = "requestAttributeSelectorValue";
053: getRequest().setAttribute(attributeName, attributeValue);
054: Parameters parameters = new Parameters();
055: boolean result;
056:
057: // test selection success
058: result = this .select("request-attribute", attributeValue,
059: parameters);
060: System.out.println(result);
061: assertTrue("Test if a request attribtue is selected", result);
062:
063: // test selection failure
064: result = this .select("request-attribute", "unknownValue",
065: parameters);
066: System.out.println(result);
067: assertTrue("Test if a request attribute is not selected",
068: !result);
069: }
070:
071: /**
072: * A request-attribute parameter select test
073: */
074: public void testRequestAttributeSelectOverridden() throws Exception {
075: final String attributeName = "requestAttributeSelector1";
076: final String attributeValue = "requestAttributeSelectorValue1";
077: getRequest().setAttribute(attributeName, attributeValue);
078:
079: final String attributeNameOverridden = "requestAttributeSelector";
080: final String attributeValueOverridden = "requestAttributeSelectorValue";
081: getRequest().setAttribute(attributeNameOverridden,
082: attributeValueOverridden);
083:
084: Parameters parameters = new Parameters();
085: parameters.setParameter("attribute-name", attributeName);
086: boolean result;
087:
088: // test selection success
089: result = this .select("request-attribute", attributeValue,
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-attribute",
096: attributeValueOverridden, parameters);
097: System.out.println(result);
098: assertTrue("Test if a request attribute is not selected",
099: !result);
100: }
101: }
|