|
| 1 | +import org.junit.jupiter.api.BeforeAll; |
| 2 | +import org.junit.jupiter.api.BeforeEach; |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import org.junit.jupiter.api.AfterEach; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 7 | +import java.nio.file.*; |
| 8 | +import java.io.*; |
| 9 | +import com.ip2location.*; |
| 10 | + |
| 11 | +class IP2LocationTest { |
| 12 | + private static IP2Location loc; |
| 13 | + private static String binfile = "IP2LOCATION-LITE-DB1.BIN"; |
| 14 | + private static String binfilepath; |
| 15 | + private static String ip = "8.8.8.8"; |
| 16 | + |
| 17 | + @BeforeAll |
| 18 | + static void Setup() { |
| 19 | + Path binpath = Paths.get("src","test","resources", binfile); |
| 20 | + binfilepath = binpath.toFile().getAbsolutePath(); |
| 21 | + } |
| 22 | + |
| 23 | + @BeforeEach |
| 24 | + void Init() { |
| 25 | + loc = new IP2Location(); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void TestOpenException() { |
| 30 | + assertThrows(IOException.class, () -> { |
| 31 | + loc.Open("dummy.bin"); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void TestQueryCountryCode() throws IOException { |
| 37 | + loc.Open(binfilepath); |
| 38 | + IPResult rec = loc.IPQuery(ip); |
| 39 | + assertEquals(rec.getCountryShort(), "US"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void TestQueryCountryLong() throws IOException { |
| 44 | + loc.Open(binfilepath); |
| 45 | + IPResult rec = loc.IPQuery(ip); |
| 46 | + assertEquals(rec.getCountryLong(), "United States of America"); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void TestQueryRegion() throws IOException { |
| 51 | + loc.Open(binfilepath); |
| 52 | + IPResult rec = loc.IPQuery(ip); |
| 53 | + assertEquals(rec.getRegion(), "Not_Supported"); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void TestQueryCity() throws IOException { |
| 58 | + loc.Open(binfilepath); |
| 59 | + IPResult rec = loc.IPQuery(ip); |
| 60 | + assertEquals(rec.getCity(), "Not_Supported"); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void TestQueryLatitude() throws IOException { |
| 65 | + loc.Open(binfilepath); |
| 66 | + IPResult rec = loc.IPQuery(ip); |
| 67 | + assertEquals(rec.getLatitude(), 0.0); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + void TestQueryLongitude() throws IOException { |
| 72 | + loc.Open(binfilepath); |
| 73 | + IPResult rec = loc.IPQuery(ip); |
| 74 | + assertEquals(rec.getLongitude(), 0.0); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void TestQueryZipCode() throws IOException { |
| 79 | + loc.Open(binfilepath); |
| 80 | + IPResult rec = loc.IPQuery(ip); |
| 81 | + assertEquals(rec.getZipCode(), "Not_Supported"); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void TestQueryTimeZone() throws IOException { |
| 86 | + loc.Open(binfilepath); |
| 87 | + IPResult rec = loc.IPQuery(ip); |
| 88 | + assertEquals(rec.getTimeZone(), "Not_Supported"); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + void TestQueryISP() throws IOException { |
| 93 | + loc.Open(binfilepath); |
| 94 | + IPResult rec = loc.IPQuery(ip); |
| 95 | + assertEquals(rec.getISP(), "Not_Supported"); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + void TestQueryDomain() throws IOException { |
| 100 | + loc.Open(binfilepath); |
| 101 | + IPResult rec = loc.IPQuery(ip); |
| 102 | + assertEquals(rec.getDomain(), "Not_Supported"); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + void TestQueryNetSpeed() throws IOException { |
| 107 | + loc.Open(binfilepath); |
| 108 | + IPResult rec = loc.IPQuery(ip); |
| 109 | + assertEquals(rec.getNetSpeed(), "Not_Supported"); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + void TestQueryIDDCode() throws IOException { |
| 114 | + loc.Open(binfilepath); |
| 115 | + IPResult rec = loc.IPQuery(ip); |
| 116 | + assertEquals(rec.getIDDCode(), "Not_Supported"); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + void TestQueryAreaCode() throws IOException { |
| 121 | + loc.Open(binfilepath); |
| 122 | + IPResult rec = loc.IPQuery(ip); |
| 123 | + assertEquals(rec.getAreaCode(), "Not_Supported"); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + void TestQueryWeatherStationCode() throws IOException { |
| 128 | + loc.Open(binfilepath); |
| 129 | + IPResult rec = loc.IPQuery(ip); |
| 130 | + assertEquals(rec.getWeatherStationCode(), "Not_Supported"); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + void TestQueryWeatherStationName() throws IOException { |
| 135 | + loc.Open(binfilepath); |
| 136 | + IPResult rec = loc.IPQuery(ip); |
| 137 | + assertEquals(rec.getWeatherStationName(), "Not_Supported"); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + void TestQueryMCC() throws IOException { |
| 142 | + loc.Open(binfilepath); |
| 143 | + IPResult rec = loc.IPQuery(ip); |
| 144 | + assertEquals(rec.getMCC(), "Not_Supported"); |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + void TestQueryMNC() throws IOException { |
| 149 | + loc.Open(binfilepath); |
| 150 | + IPResult rec = loc.IPQuery(ip); |
| 151 | + assertEquals(rec.getMNC(), "Not_Supported"); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + void TestQueryMobileBrand() throws IOException { |
| 156 | + loc.Open(binfilepath); |
| 157 | + IPResult rec = loc.IPQuery(ip); |
| 158 | + assertEquals(rec.getMobileBrand(), "Not_Supported"); |
| 159 | + } |
| 160 | + |
| 161 | + @Test |
| 162 | + void TestQueryElevation() throws IOException { |
| 163 | + loc.Open(binfilepath); |
| 164 | + IPResult rec = loc.IPQuery(ip); |
| 165 | + assertEquals(rec.getElevation(), 0.0); |
| 166 | + } |
| 167 | + |
| 168 | + @Test |
| 169 | + void TestQueryUsageType() throws IOException { |
| 170 | + loc.Open(binfilepath); |
| 171 | + IPResult rec = loc.IPQuery(ip); |
| 172 | + assertEquals(rec.getUsageType(), "Not_Supported"); |
| 173 | + } |
| 174 | + |
| 175 | + @AfterEach |
| 176 | + void TearDown() { |
| 177 | + loc.Close(); |
| 178 | + loc = null; |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | + |
0 commit comments