KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > Bug36872HttpHeaderActionTestCase


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;
17
18 public class Bug36872HttpHeaderActionTestCase
19     extends HtmlUnitTestCase {
20
21     static final String JavaDoc BASE_URL = "/samples/test/http-header-action/";
22     
23     static final String JavaDoc HEADER = "X-HttpHeaderActionTest";
24     
25     /** some pages must return the X-HttpHeaderActionTest header with the value "from-" + page */
26     private void assertHeaderPresent(String JavaDoc page) throws Exception JavaDoc {
27         loadResponse(BASE_URL + page);
28         final String JavaDoc value = response.getResponseHeaderValue(HEADER);
29         assertNotNull("Header '" + HEADER + "' must be present in'" + page + "' response",value);
30         final String JavaDoc expected = "from-" + page;
31         assertEquals("Header '" + HEADER + "' must match expected value in'" + page + "' response",expected,value);
32     }
33     
34     private void assertHeaderNotPresent(String JavaDoc page) throws Exception JavaDoc {
35         loadResponse(BASE_URL + page);
36         final String JavaDoc value = response.getResponseHeaderValue(HEADER);
37         assertNull("Header '" + HEADER + "' must not be present in'" + page + "' response",value);
38     }
39     
40     public void testMountedSitemap() throws Exception JavaDoc {
41             assertHeaderPresent("mounted-sitemap");
42     }
43
44     public void testInternalRequestNoFlow() throws Exception JavaDoc {
45             // currently, internal requests do not allow HTTP headers to be set, see bugzilla 36872
46
assertHeaderNotPresent("internal-request");
47 }
48
49     public void testInternalRequestWithFlow() throws Exception JavaDoc {
50         assertHeaderPresent("internal-request-flow");
51 }
52
53 }
54
Popular Tags