View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
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   * The Class WhoisTests.
24   */
25  class WhoisTests {
26  
27    /**
28     * Lookup null query test.
29     *
30     * @throws IOException Signals that an I/O exception has occurred.
31     */
32    @Test
33    void nullQueryReturnsNullTest() throws IOException {
34      Assertions.assertNull(Whois.lookup("localhost", 43, null, 1));
35    }
36  
37    /**
38     * Test localhost.
39     *
40     * @throws IOException Signals that an I/O exception has occurred.
41     */
42    // TODO breaks with latest surefire versions
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     * Test google.
62     *
63     * @throws IOException Signals that an I/O exception has occurred.
64     */
65    // TODO breaks with latest surefire versions
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  }