KickJava   Java API By Example, From Geeks To Geeks.

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


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 HeaderSelectorTestCase extends SitemapComponentTestCase {
26
27     private static final String JavaDoc HEADER_SELECTOR = "header";
28
29     /**
30      * Run this test suite from commandline
31      *
32      * @param args commandline arguments (ignored)
33      */

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

42     public static Test suite() {
43         TestSuite suite = new TestSuite(HeaderSelectorTestCase.class);
44         return suite;
45     }
46     
47     /**
48      * A simple header select test
49      */

50     public void testHeaderSelect() throws Exception JavaDoc {
51         final String JavaDoc headerName = "headerSelectorTestCase";
52         final String JavaDoc headerValue = "headerValue";
53         // create a header
54
// setting name := headerName, value := headerValue
55
getRequest().setHeader(headerName, headerValue);
56         
57         Parameters parameters = new Parameters();
58         boolean result;
59
60         // test selection success
61
result = this.select( HEADER_SELECTOR, headerValue, parameters );
62         System.out.println( result );
63         assertTrue( "Test if a header is selected", result );
64         
65         // test selection failure
66
result = this.select( HEADER_SELECTOR, "unknownHeaderValue", parameters );
67         System.out.println( result );
68         assertTrue( "Test if a header is not selected", !result );
69     }
70
71     /**
72      * A simple header select test
73      */

74     public void testHeaderSelectUsingParameters() throws Exception JavaDoc {
75         final String JavaDoc headerName = "headerSelectorTestCase1";
76         final String JavaDoc headerValue = "headerValue1";
77         // create a header
78
// setting name := headerName, value := headerValue
79
getRequest().setHeader(headerName, headerValue);
80
81         // check the header as defined by this parameter, not as
82
// defined in the component configuration
83
Parameters parameters = new Parameters();
84         parameters.setParameter( "header-name", headerName );
85         
86         boolean result;
87         
88         // test selection success
89
result = this.select( HEADER_SELECTOR, headerValue, parameters );
90         System.out.println( result );
91         assertTrue( "Test if a header is selected", result );
92         
93         // test selection failure
94
result = this.select( HEADER_SELECTOR, "unknownHeaderValue", parameters );
95         System.out.println( result );
96         assertTrue( "Test if a header is not selected", !result );
97     }
98 }
99
Popular Tags