-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
112b3c5
commit 551bc73
Showing
3 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.AfterEach; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import java.nio.file.*; | ||
import java.io.*; | ||
import com.ip2proxy.*; | ||
|
||
class IP2ProxyTest { | ||
private static IP2Proxy Proxy; | ||
private static ProxyResult All; | ||
private static String binfile = "IP2PROXY-LITE-PX1.BIN"; | ||
private static String binfilepath; | ||
private static String ip = "8.8.8.8"; | ||
|
||
@BeforeAll | ||
static void Setup() { | ||
Path binpath = Paths.get("src","test","resources", binfile); | ||
binfilepath = binpath.toFile().getAbsolutePath(); | ||
} | ||
|
||
@BeforeEach | ||
void Init() { | ||
Proxy = new IP2Proxy(); | ||
} | ||
|
||
@Test | ||
void TestOpenException() { | ||
assertThrows(IOException.class, () -> { | ||
Proxy.Open("dummy.bin"); | ||
}); | ||
} | ||
|
||
@Test | ||
void TestQueryIsProxy() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Is_Proxy, 0); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryProxyType() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Proxy_Type, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryCountryShort() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Country_Short, "-"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryCountryLong() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Country_Long, "-"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryRegion() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Region, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryCity() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.City, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryISP() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.ISP, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryDomain() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Domain, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryUsageType() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Usage_Type, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryASN() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.ASN, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryAS() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.AS, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryLastSeen() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Last_Seen, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@Test | ||
void TestQueryThreat() throws IOException { | ||
if (Proxy.Open(binfilepath) == 0) { | ||
All = Proxy.GetAll(ip); | ||
assertEquals(All.Threat, "NOT SUPPORTED"); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void TearDown() { | ||
Proxy.Close(); | ||
Proxy = null; | ||
} | ||
} | ||
|
||
|
Binary file not shown.