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.junit.jupiter.api.Test;
20
21
22
23
24
25
26
27 public final class ImmediateRefreshHandlerTest extends SimpleWebTestCase {
28
29
30
31
32
33 @Test
34 public void refreshSamePageAfterPost() throws Exception {
35 final WebClient client = getWebClient();
36 client.setRefreshHandler(new ImmediateRefreshHandler());
37
38
39
40 final MockWebConnection webConnection = new MockWebConnection() {
41 private int nbCalls_ = 0;
42 @Override
43 public WebResponse getResponse(final WebRequest request) throws IOException {
44 String content = DOCTYPE_HTML + "<html><head>\n";
45 if (nbCalls_ == 0) {
46 content += "<meta http-equiv='refresh' content='0;url="
47 + URL_FIRST.toExternalForm()
48 + "'>\n";
49 }
50 content += "</head><body></body></html>";
51 nbCalls_++;
52 final StringWebResponse response = new StringWebResponse(content, request.getUrl());
53 response.getWebRequest().setHttpMethod(request.getHttpMethod());
54 return response;
55 }
56 };
57 client.setWebConnection(webConnection);
58
59 final WebRequest request = new WebRequest(URL_FIRST);
60 request.setHttpMethod(HttpMethod.POST);
61 client.getPage(request);
62 }
63 }