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.junit.jupiter.api.Assertions.fail;
18
19 import java.io.IOException;
20 import java.net.URL;
21
22 import org.junit.jupiter.api.Test;
23
24 /**
25 * Tests for {@link WebClient}.
26 *
27 * @author Mike Bowler
28 * @author Christian Sell
29 * @author Ben Curren
30 * @author Marc Guillemot
31 * @author David D. Kilzer
32 * @author Chris Erskine
33 * @author Hans Donner
34 * @author Paul King
35 * @author Ahmed Ashour
36 * @author Daniel Gredler
37 * @author Sudhan Moghe
38 * @author Ronald Brill
39 */
40 public class WebClient5Test extends WebTestCase {
41
42 /**
43 * @throws Exception if the test fails
44 */
45 @Test
46 public void addRequestHeader_Cookie() throws Exception {
47 try (WebClient wc = new WebClient()) {
48 wc.addRequestHeader(HttpHeader.COOKIE, "some_value");
49 fail("Should have thrown an exception ");
50 }
51 catch (final IllegalArgumentException e) {
52 //success
53 }
54 }
55
56 /**
57 * Test that WebClient.getPage(String) calls WebClient.getPage(URL) with the right URL.
58 * @throws Exception if the test fails
59 */
60 @Test
61 public void getPageWithStringArg() throws Exception {
62 final URL[] calledUrls = {null};
63 try (WebClient wc = new WebClient() {
64 @Override
65 @SuppressWarnings("unchecked")
66 public Page getPage(final URL url) throws IOException, FailingHttpStatusCodeException {
67 calledUrls[0] = url;
68 return null;
69 }
70 }) {
71 wc.getPage(URL_FIRST.toExternalForm());
72 assertEquals(URL_FIRST, calledUrls[0]);
73 }
74 }
75 }