1
2
3
4
5
6
7
8
9
10
11 package psiprobe.tools;
12
13 import java.io.IOException;
14 import java.net.InetAddress;
15
16 import org.junit.jupiter.api.Assertions;
17 import org.junit.jupiter.api.Disabled;
18 import org.junit.jupiter.api.Test;
19
20 import psiprobe.tools.Whois.Response;
21
22
23
24
25 class WhoisTests {
26
27
28
29
30
31
32 @Test
33 void nullQueryReturnsNullTest() throws IOException {
34 Assertions.assertNull(Whois.lookup("localhost", 43, null, 1));
35 }
36
37
38
39
40
41
42
43 @Disabled
44 @Test
45 void localhostTest() throws IOException {
46 int a = 127;
47 int b = 0;
48 int c = 0;
49 int d = 1;
50 String dotted = a + "." + b + "." + c + "." + d;
51 byte[] bytes = {(byte) a, (byte) b, (byte) c, (byte) d};
52
53 Response response = Whois.lookup("whois.arin.net", 43, "n " + dotted, 5);
54 Assertions.assertEquals("SPECIAL-IPV4-LOOPBACK-IANA-RESERVED",
55 response.getData().get("NetName"));
56 Assertions.assertEquals("127.0.0.1", InetAddress.getByName(dotted).getHostName());
57 Assertions.assertEquals("127.0.0.1", InetAddress.getByAddress(bytes).getHostName());
58 }
59
60
61
62
63
64
65
66 @Disabled
67 @Test
68 void googleTest() throws IOException {
69 int a = 74;
70 int b = 125;
71 int c = 45;
72 int d = 100;
73 String dotted = a + "." + b + "." + c + "." + d;
74 byte[] bytes = {(byte) a, (byte) b, (byte) c, (byte) d};
75
76 Response response = Whois.lookup("whois.arin.net", 43, "n " + dotted, 5);
77 Assertions.assertEquals("GOOGLE", response.getData().get("NetName"));
78 Assertions.assertEquals("74.125.45.100", InetAddress.getByName(dotted).getHostName());
79 Assertions.assertEquals("74.125.45.100", InetAddress.getByAddress(bytes).getHostName());
80 }
81
82 }