KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestHttpUnitIntegration


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

20 package org.apache.cactus.sample.servlet.unit;
21
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 import org.apache.cactus.ServletTestCase;
26
27 /**
28  * Test the HtppUnit integration.
29  *
30  * @version $Id: TestHttpUnitIntegration.java,v 1.3 2004/02/29 16:36:44 vmassol Exp $
31  */

32 public class TestHttpUnitIntegration extends ServletTestCase
33 {
34     /**
35      * Verify that the HttpUnit integration works.
36      *
37      * @exception IOException on test failure
38      */

39     public void testHttpUnitGetText() throws IOException JavaDoc
40     {
41         PrintWriter JavaDoc pw = response.getWriter();
42
43         pw.print("something to return for the test");
44     }
45
46     /**
47      * Verify that HttpUnit integration works
48      *
49      * @param theResponse the response from the server side.
50      *
51      * @exception IOException on test failure
52      */

53     public void endHttpUnitGetText(
54         com.meterware.httpunit.WebResponse theResponse) throws IOException JavaDoc
55     {
56         String JavaDoc text = theResponse.getText();
57
58         assertEquals("something to return for the test", text);
59     }
60
61     //-------------------------------------------------------------------------
62

63     /**
64      * Verify that we can set several headers in the response and
65      * assert them in endXXX().
66      */

67     public void testResponseAddHeadersHttpUnit()
68     {
69         response.addHeader("X-Access-Header1", "value1");
70         response.addHeader("X-Access-Header2", "value2");
71     }
72
73     /**
74      * Verify that we can set several headers in the response and
75      * assert them in endXXX().
76      *
77      * @param theResponse the response from the server side.
78      */

79     public void endResponseAddHeadersHttpUnit(
80     com.meterware.httpunit.WebResponse theResponse)
81     {
82         String JavaDoc value1 = theResponse.getHeaderField("X-Access-Header1");
83         String JavaDoc value2 = theResponse.getHeaderField("X-Access-Header2");
84
85         assertEquals("value1", value1);
86         assertEquals("value2", value2);
87     }
88
89 }
90
Popular Tags