01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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 238816 2004-02-29 16:36:46Z vmassol $
30: */
31: public class TestSetUpTearDown extends ServletTestCase {
32: /**
33: * Put a value in the session to verify that this method is called prior
34: * to the test, and that it can access servlet implicit objects.
35: */
36: protected void setUp() {
37: session.setAttribute("setUpFlag", "a setUp test flag");
38: }
39:
40: /**
41: * Verify that <code>setUp()</code> has been called and that it put a
42: * value in the session object.
43: */
44: public void testSetUp() {
45: assertEquals("a setUp test flag", session
46: .getAttribute("setUpFlag"));
47: }
48:
49: //-------------------------------------------------------------------------
50:
51: /**
52: * Set an HTTP response header to verify that this method is called after
53: * the test, and that it can access servlet implicit objects.
54: */
55: protected void tearDown() {
56: response.setHeader("Teardownheader", "tear down header");
57: }
58:
59: /**
60: * Verify that <code>tearDown()</code> has been called and that it created
61: * an HTTP reponse header.
62: */
63: public void testTearDown() {
64: }
65:
66: /**
67: * Verify that <code>tearDown()</code> has been called and that it created
68: * an HTTP reponse header.
69: *
70: * @param theResponse the HTTP connection that was used to call the
71: * server redirector. It contains the returned HTTP
72: * response.
73: */
74: public void endTearDown(WebResponse theResponse) {
75: assertEquals("tear down header", theResponse.getConnection()
76: .getHeaderField("Teardownheader"));
77: }
78: }
|