KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.cactus.ServletTestCase;
23 import org.apache.cactus.WebResponse;
24
25 /**
26  * Test that <code>setUp()</code> and <code>tearDown()</code> methods are
27  * called and can access implicit objects in <code>ServletTestCase</code>.
28  *
29  * @version $Id: TestSetUpTearDown.java,v 1.3 2004/02/29 16:36:44 vmassol Exp $
30  */

31 public class TestSetUpTearDown extends ServletTestCase
32 {
33     /**
34      * Put a value in the session to verify that this method is called prior
35      * to the test, and that it can access servlet implicit objects.
36      */

37     protected void setUp()
38     {
39         session.setAttribute("setUpFlag", "a setUp test flag");
40     }
41
42     /**
43      * Verify that <code>setUp()</code> has been called and that it put a
44      * value in the session object.
45      */

46     public void testSetUp()
47     {
48         assertEquals("a setUp test flag", session.getAttribute("setUpFlag"));
49     }
50
51     //-------------------------------------------------------------------------
52

53     /**
54      * Set an HTTP response header to verify that this method is called after
55      * the test, and that it can access servlet implicit objects.
56      */

57     protected void tearDown()
58     {
59         response.setHeader("Teardownheader", "tear down header");
60     }
61
62     /**
63      * Verify that <code>tearDown()</code> has been called and that it created
64      * an HTTP reponse header.
65      */

66     public void testTearDown()
67     {
68     }
69
70     /**
71      * Verify that <code>tearDown()</code> has been called and that it created
72      * an HTTP reponse header.
73      *
74      * @param theResponse the HTTP connection that was used to call the
75      * server redirector. It contains the returned HTTP
76      * response.
77      */

78     public void endTearDown(WebResponse theResponse)
79     {
80         assertEquals("tear down header",
81             theResponse.getConnection().getHeaderField("Teardownheader"));
82     }
83 }
84
Popular Tags