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.util.NameValuePair;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests for {@link AbstractPage}.
29   *
30   * @author Ahmed Ashour
31   * @author Ronald Brill
32   */
33  public final class AbstractPageTest extends WebServerTestCase {
34  
35      /**
36       * Do not cleanup WebResponse between pages if it is cached.
37       * @throws Exception if the test fails
38       */
39      @Test
40      public void onlyCacheToCleanUpWebResponse() throws Exception {
41          try (WebClient webClient = getWebClient()) {
42              webClient.getOptions().setMaxInMemory(3);
43  
44              final List<NameValuePair> headers = new ArrayList<>();
45              headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1))));
46              getMockWebConnection().setDefaultResponse("something", 200, "Ok", "unknown_type", headers);
47              startWebServer(getMockWebConnection());
48  
49              webClient.getPage(URL_FIRST);
50              webClient.getPage(URL_FIRST);
51          }
52      }
53  }