View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.hc.client5.http;
28  
29  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  
32  import java.net.InetAddress;
33  import java.net.UnknownHostException;
34  
35  import org.junit.jupiter.api.Test;
36  
37  public class SystemDefaultDnsResolverTest {
38  
39      @Test
40      void resolve() throws UnknownHostException {
41          final SystemDefaultDnsResolver resolver = SystemDefaultDnsResolver.INSTANCE;
42          final InetAddress[] result1 = resolver.resolve("127.0.0.1");
43          assertEquals(1, result1.length);
44          assertArrayEquals(new byte[]{127, 0, 0, 1}, result1[0].getAddress());
45      }
46  
47      @Test
48      void resolveIPv6ZoneId() throws UnknownHostException {
49          final SystemDefaultDnsResolver resolver = SystemDefaultDnsResolver.INSTANCE;
50  
51          // This is an IPv6 address literal with zone ID
52          final InetAddress[] result = resolver.resolve("[fe80::221:b7ff:fe8a:57d5%en4]");
53          assertEquals(1, result.length);
54          assertArrayEquals(new byte[]{(byte) 0xfe, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x21, (byte) 0xb7, (byte) 0xff, (byte) 0xfe, (byte) 0x8a, 0x57, (byte) 0xd5}, result[0].getAddress());
55  
56      }
57  
58  }