1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.client5.http.impl;
29
30 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
31 import static org.junit.jupiter.api.Assertions.assertEquals;
32
33 import java.net.InetAddress;
34 import java.net.UnknownHostException;
35
36 import org.junit.jupiter.api.Test;
37
38
39
40
41 class InMemoryDnsResolverTest {
42
43 @Test
44 void resolve() throws UnknownHostException {
45 final InMemoryDnsResolver resolver = new InMemoryDnsResolver();
46 final String hostString = "127.0.0.1";
47 final byte[] address = new byte[] { 127, 0, 0, 1 };
48 resolver.add(hostString, InetAddress.getByAddress(hostString, address));
49 final InetAddress[] result1 = resolver.resolve(hostString);
50 assertEquals(1, result1.length);
51 assertArrayEquals(address, result1[0].getAddress());
52 }
53
54 @Test
55 void resolveIPv6ZoneId() throws UnknownHostException {
56 final InMemoryDnsResolver resolver = new InMemoryDnsResolver();
57 final String hostStr = "[fe80::221:b7ff:fe8a:57d5%en4]";
58 final byte[] address = new byte[] { (byte) 0xfe, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x21, (byte) 0xb7, (byte) 0xff, (byte) 0xfe, (byte) 0x8a, 0x57,
59 (byte) 0xd5 };
60 resolver.add(hostStr, InetAddress.getByAddress(hostStr, address));
61
62 final InetAddress[] result = resolver.resolve(hostStr);
63 assertEquals(1, result.length);
64 assertArrayEquals(address, result[0].getAddress());
65
66 }
67
68 }