|
19 | 19 |
|
20 | 20 | package net.sourceforge.jwebunit.tests; |
21 | 21 |
|
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import java.net.SocketTimeoutException; |
| 25 | + |
22 | 26 | import static net.sourceforge.jwebunit.junit.JWebUnit.assertHeaderEquals; |
23 | 27 | import static net.sourceforge.jwebunit.junit.JWebUnit.assertHeaderMatches; |
24 | 28 | import static net.sourceforge.jwebunit.junit.JWebUnit.assertHeaderNotPresent; |
|
36 | 40 | import static org.junit.Assert.assertTrue; |
37 | 41 | import static org.junit.Assert.fail; |
38 | 42 |
|
39 | | -import java.net.SocketTimeoutException; |
40 | | - |
41 | | -import org.junit.Test; |
42 | | - |
43 | 43 | /** |
44 | 44 | * Test redirection support. |
45 | | - * |
| 45 | + * |
46 | 46 | * @author Julien Henry |
47 | 47 | */ |
48 | 48 | public class ResponseServletTest extends JWebUnitAPITestCase { |
49 | 49 |
|
50 | | - public void setUp() throws Exception { |
51 | | - super.setUp(); |
52 | | - setIgnoreFailingStatusCodes(true); // ignore failing status codes |
53 | | - setBaseUrl(HOST_PATH + "/ResponseServletTest"); |
54 | | - } |
| 50 | + public void setUp() throws Exception { |
| 51 | + super.setUp(); |
| 52 | + setIgnoreFailingStatusCodes(true); // ignore failing status codes |
| 53 | + setBaseUrl(HOST_PATH + "/ResponseServletTest"); |
| 54 | + } |
55 | 55 |
|
56 | | - /* |
57 | | - * currently we can't get the response code from HtmlUnit unless it is a failing code |
58 | | - */ |
59 | | - @Test public void testDefault() { |
60 | | - beginAt("/SimpleForm.html"); |
61 | | - submit(); |
62 | | - assertResponseCodeBetween(200, 299); |
63 | | - |
64 | | - // test the headers |
65 | | - assertHeaderPresent("Test"); |
66 | | - assertHeaderNotPresent("Not-present"); |
67 | | - assertHeaderEquals("Test", "test2"); |
68 | | - assertHeaderMatches("Header-Added", "[0-9]{2}"); |
69 | | - } |
| 56 | + /* |
| 57 | + * currently we can't get the response code from HtmlUnit unless it is a failing code |
| 58 | + */ |
| 59 | + @Test |
| 60 | + public void testDefault() { |
| 61 | + beginAt("/SimpleForm.html"); |
| 62 | + submit(); |
| 63 | + assertResponseCodeBetween(200, 299); |
70 | 64 |
|
71 | | - @Test public void testResponse200() { |
72 | | - beginAt("/SimpleForm.html"); |
73 | | - setTextField("status", "200"); |
74 | | - submit(); |
75 | | - assertResponseCode(200); |
76 | | - } |
| 65 | + // test the headers |
| 66 | + assertHeaderPresent("Test"); |
| 67 | + assertHeaderNotPresent("Not-present"); |
| 68 | + assertHeaderEquals("Test", "test2"); |
| 69 | + assertHeaderMatches("Header-Added", "[0-9]{2}"); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testResponse200() { |
| 74 | + beginAt("/SimpleForm.html"); |
| 75 | + setTextField("status", "200"); |
| 76 | + submit(); |
| 77 | + assertResponseCode(200); |
| 78 | + } |
77 | 79 |
|
78 | | - /* |
79 | | - * HtmlUnit cannot handle a 301 without a valid Location: header |
| 80 | + /* |
| 81 | + * HtmlUnit cannot handle a 301 without a valid Location: header |
80 | 82 | @Test public void testResponse301() { |
81 | 83 | beginAt("/SimpleForm.html"); |
82 | 84 | setTextField("status", "301"); |
83 | 85 | submit(); |
84 | 86 | assertResponseCode(301); |
85 | 87 | } |
86 | | - */ |
| 88 | + */ |
87 | 89 |
|
88 | | - @Test public void testResponse404() { |
89 | | - beginAt("/SimpleForm.html"); |
90 | | - assertTitleEquals("response form"); |
91 | | - setTextField("status", "404"); |
92 | | - submit(); |
93 | | - assertResponseCode(404); |
94 | | - } |
| 90 | + @Test |
| 91 | + public void testResponse404() { |
| 92 | + beginAt("/SimpleForm.html"); |
| 93 | + assertTitleEquals("response form"); |
| 94 | + setTextField("status", "404"); |
| 95 | + submit(); |
| 96 | + assertResponseCode(404); |
| 97 | + } |
95 | 98 |
|
96 | | - @Test public void testResponse501() { |
97 | | - beginAt("/SimpleForm.html"); |
98 | | - assertTitleEquals("response form"); |
99 | | - setTextField("status", "501"); |
100 | | - submit(); |
101 | | - assertResponseCode(501); |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * Issue 1674646: add support for specifying the timeout of pages |
106 | | - */ |
107 | | - @Test public void testTimeout() { |
108 | | - |
109 | | - // test that timeout was fired |
110 | | - setTimeout(500); // specify a global timeout of 0.5 seconds (must be set before the WebConnection is initialised) |
111 | | - beginAt("/SimpleForm.html"); |
112 | | - assertTitleEquals("response form"); |
113 | | - setTextField("timeout", "1"); // server wait for 1 seconds |
114 | | - try { |
115 | | - submit(); |
116 | | - fail("timeout was not called"); // we should not get here |
117 | | - } catch (RuntimeException e) { |
118 | | - assertTrue("timeout caused by SocketTimeoutException, but was " + e.getCause().getClass(), e.getCause() instanceof SocketTimeoutException); |
119 | | - } |
120 | | - |
121 | | - // close and reset the browser |
122 | | - closeBrowser(); |
123 | | - |
124 | | - // test that timeout wasn't fired |
125 | | - setTimeout(2000); // specify a global timeout of 2 seconds (must be set before the WebConnection is initialised) |
126 | | - beginAt("/SimpleForm.html"); |
127 | | - assertTitleEquals("response form"); |
128 | | - setTextField("timeout", "1"); // server wait for 1 seconds |
129 | | - submit(); |
130 | | - assertTextPresent("hello, world!"); |
| 99 | + @Test |
| 100 | + public void testResponse501() { |
| 101 | + beginAt("/SimpleForm.html"); |
| 102 | + assertTitleEquals("response form"); |
| 103 | + setTextField("status", "501"); |
| 104 | + submit(); |
| 105 | + assertResponseCode(501); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Issue 1674646: add support for specifying the timeout of pages |
| 110 | + */ |
| 111 | + @Test |
| 112 | + public void testTimeout() { |
| 113 | + |
| 114 | + // test that timeout was fired |
| 115 | + setTimeout(500); // specify a global timeout of 0.5 seconds (must be set before the WebConnection is initialised) |
| 116 | + beginAt("/SimpleForm.html"); |
| 117 | + assertTitleEquals("response form"); |
| 118 | + setTextField("timeout", "1"); // server wait for 1 seconds |
| 119 | + try { |
| 120 | + submit(); |
| 121 | + fail("timeout was not called"); // we should not get here |
| 122 | + } catch (RuntimeException e) { |
| 123 | + assertTrue("timeout caused by SocketTimeoutException, but was " + e.getCause().getClass(), e.getCause() instanceof SocketTimeoutException); |
131 | 124 | } |
132 | 125 |
|
| 126 | + // close and reset the browser |
| 127 | + closeBrowser(); |
| 128 | + |
| 129 | + // test that timeout wasn't fired |
| 130 | + setTimeout(2000); // specify a global timeout of 2 seconds (must be set before the WebConnection is initialised) |
| 131 | + beginAt("/SimpleForm.html"); |
| 132 | + assertTitleEquals("response form"); |
| 133 | + setTextField("timeout", "1"); // server wait for 1 seconds |
| 134 | + submit(); |
| 135 | + assertTextPresent("hello, world!"); |
| 136 | + } |
| 137 | + |
133 | 138 | } |
0 commit comments