1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import java.io.IOException;
18
19 import org.htmlunit.junit.BrowserRunner;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28 @RunWith(BrowserRunner.class)
29 public final class ImmediateRefreshHandlerTest extends SimpleWebTestCase {
30
31
32
33
34
35 @Test
36 public void refreshSamePageAfterPost() throws Exception {
37 final WebClient client = getWebClient();
38 client.setRefreshHandler(new ImmediateRefreshHandler());
39
40
41
42 final MockWebConnection webConnection = new MockWebConnection() {
43 private int nbCalls_ = 0;
44 @Override
45 public WebResponse getResponse(final WebRequest request) throws IOException {
46 String content = DOCTYPE_HTML + "<html><head>\n";
47 if (nbCalls_ == 0) {
48 content += "<meta http-equiv='refresh' content='0;url="
49 + URL_FIRST.toExternalForm()
50 + "'>\n";
51 }
52 content += "</head><body></body></html>";
53 nbCalls_++;
54 final StringWebResponse response = new StringWebResponse(content, request.getUrl());
55 response.getWebRequest().setHttpMethod(request.getHttpMethod());
56 return response;
57 }
58 };
59 client.setWebConnection(webConnection);
60
61 final WebRequest request = new WebRequest(URL_FIRST);
62 request.setHttpMethod(HttpMethod.POST);
63 client.getPage(request);
64 }
65 }