KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > TestResponseStatus


1 package servletunit.struts.tests;
2
3 import servletunit.struts.MockStrutsTestCase;
4 import servletunit.HttpServletResponseSimulator;
5 import junit.framework.AssertionFailedError;
6
7 /**
8  * Created by IntelliJ IDEA.
9  * User: deryl
10  * Date: May 20, 2003
11  * Time: 5:16:57 PM
12  * To change this template use Options | File Templates.
13  */

14 public class TestResponseStatus extends MockStrutsTestCase {
15
16     public TestResponseStatus(String JavaDoc testName) {
17         super(testName);
18     }
19
20     public void setUp() throws Exception JavaDoc {
21         super.setUp();
22         setServletConfigFile("/WEB-INF/web.xml");
23     }
24
25     public void testResponseCode() {
26         setRequestPathInfo("/badActionPath");
27         try {
28             actionPerform();
29         } catch (AssertionFailedError afe) {
30             int statusCode = ((HttpServletResponseSimulator) getResponse()).getStatusCode();
31             // todo: backwards compatible with struts 1.1
32
assertTrue("unexpected response code",statusCode == 404 || statusCode == 400);
33             return;
34         }
35         fail("expected some error code!");
36
37     }
38
39
40 }
41
Popular Tags