KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > selection > RequestAttributeSelectorTestCase


1 /*
2 * Copyright 1999-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 package org.apache.cocoon.selection;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20 import junit.textui.TestRunner;
21 import org.apache.avalon.framework.parameters.Parameters;
22 import org.apache.cocoon.SitemapComponentTestCase;
23
24
25 public class RequestAttributeSelectorTestCase extends SitemapComponentTestCase {
26
27     /**
28      * Run this test suite from commandline
29      *
30      * @param args commandline arguments (ignored)
31      */

32     public static void main( String JavaDoc[] args ) {
33         TestRunner.run(suite());
34     }
35     
36     /** Create a test suite.
37      * This test suite contains all test cases of this class.
38      * @return the Test object containing all test cases.
39      */

40     public static Test suite() {
41         TestSuite suite = new TestSuite(RequestAttributeSelectorTestCase.class);
42         return suite;
43     }
44     
45     /**
46      * A request-attribute parameter select test
47      */

48     public void testRequestAttributeSelect() throws Exception JavaDoc {
49         final String JavaDoc attributeName = "requestAttributeSelector";
50         final String JavaDoc attributeValue = "requestAttributeSelectorValue";
51         getRequest().setAttribute( attributeName, attributeValue );
52         Parameters parameters = new Parameters();
53         boolean result;
54         
55         // test selection success
56
result = this.select( "request-attribute", attributeValue, parameters );
57         System.out.println( result );
58         assertTrue( "Test if a request attribtue is selected", result );
59         
60         // test selection failure
61
result = this.select( "request-attribute", "unknownValue", parameters );
62         System.out.println( result );
63         assertTrue( "Test if a request attribute is not selected", !result );
64     }
65
66     /**
67      * A request-attribute parameter select test
68      */

69     public void testRequestAttributeSelectOverridden() throws Exception JavaDoc {
70         final String JavaDoc attributeName = "requestAttributeSelector1";
71         final String JavaDoc attributeValue = "requestAttributeSelectorValue1";
72         getRequest().setAttribute( attributeName, attributeValue );
73         
74         final String JavaDoc attributeNameOverridden = "requestAttributeSelector";
75         final String JavaDoc attributeValueOverridden = "requestAttributeSelectorValue";
76         getRequest().setAttribute( attributeNameOverridden, attributeValueOverridden );
77         
78         Parameters parameters = new Parameters();
79         parameters.setParameter( "attribute-name", attributeName );
80         boolean result;
81         
82         // test selection success
83
result = this.select( "request-attribute", attributeValue, parameters );
84         System.out.println( result );
85         assertTrue( "Test if a requst attribtue is selected", result );
86         
87         // test selection failure
88
result = this.select( "request-attribute", attributeValueOverridden, parameters );
89         System.out.println( result );
90         assertTrue( "Test if a request attribute is not selected", !result );
91     }
92 }
93
Popular Tags