View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit;
16  
17  import static org.apache.http.client.utils.DateUtils.formatDate;
18  
19  import java.util.ArrayList;
20  import java.util.Date;
21  import java.util.List;
22  
23  import org.apache.commons.lang3.time.DateUtils;
24  import org.htmlunit.junit.BrowserRunner;
25  import org.htmlunit.util.NameValuePair;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  
29  /**
30   * Tests for {@link AbstractPage}.
31   *
32   * @author Ahmed Ashour
33   */
34  @RunWith(BrowserRunner.class)
35  public final class AbstractPageTest extends WebServerTestCase {
36  
37      /**
38       * Do not cleanup WebResponse between pages if it is cached.
39       * @throws Exception if the test fails
40       */
41      @Test
42      public void onlyCacheToCleanUpWebResponse() throws Exception {
43          try (WebClient webClient = getWebClient()) {
44              webClient.getOptions().setMaxInMemory(3);
45  
46              final List<NameValuePair> headers = new ArrayList<>();
47              headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1))));
48              getMockWebConnection().setDefaultResponse("something", 200, "Ok", "unknown_type", headers);
49              startWebServer(getMockWebConnection());
50  
51              webClient.getPage(URL_FIRST);
52              webClient.getPage(URL_FIRST);
53          }
54      }
55  }