From 32783534e709016102a6f5cb4a542a291497ba9c Mon Sep 17 00:00:00 2001 From: Ankush Sharma Date: Wed, 8 Feb 2017 12:04:32 +0530 Subject: [PATCH] Tests updated for the last version of DB-IP file( Feb version) , Support added for IPV6 and tests included for IPV6 , country code added to GeoEntity. --- .../java/in/ankushs/dbip/api/DbIpClient.java | 3 +- .../java/in/ankushs/dbip/api/GeoEntity.java | 24 ++- .../dbip/importer/ResourceImporter.java | 23 ++- .../lookup/GeoEntityLookupServiceImpl.java | 16 +- .../in/ankushs/dbip/model/GeoAttributes.java | 7 +- .../ankushs/dbip/model/GeoAttributesImpl.java | 55 +++-- .../repository/JavaMapDbIpRepositoryImpl.java | 53 ++++- .../java/in/ankushs/dbip/utils/IPUtils.java | 16 ++ src/main/java/in/ankushs/dbip/utils/Tes.java | 13 -- .../groovy/in/ankushs/dbip/BaseSpec.groovy | 11 - .../in/ankushs/dbip/DbIpClientSpec.groovy | 11 +- .../in/ankushs/dbip/DbIpLookupSpec.groovy | 193 ++++++++++++++++-- 12 files changed, 323 insertions(+), 102 deletions(-) create mode 100644 src/main/java/in/ankushs/dbip/utils/IPUtils.java delete mode 100644 src/main/java/in/ankushs/dbip/utils/Tes.java delete mode 100644 src/test/groovy/in/ankushs/dbip/BaseSpec.groovy diff --git a/src/main/java/in/ankushs/dbip/api/DbIpClient.java b/src/main/java/in/ankushs/dbip/api/DbIpClient.java index a7d64c2..4d29a75 100644 --- a/src/main/java/in/ankushs/dbip/api/DbIpClient.java +++ b/src/main/java/in/ankushs/dbip/api/DbIpClient.java @@ -2,6 +2,8 @@ import java.io.File; import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Arrays; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -90,5 +92,4 @@ public GeoEntity lookup(final InetAddress inetAddress){ PreConditions.checkNull(inetAddress, "inetAddress cannot be null"); return lookupService.lookup(inetAddress); } - } diff --git a/src/main/java/in/ankushs/dbip/api/GeoEntity.java b/src/main/java/in/ankushs/dbip/api/GeoEntity.java index 67c4951..5d24201 100644 --- a/src/main/java/in/ankushs/dbip/api/GeoEntity.java +++ b/src/main/java/in/ankushs/dbip/api/GeoEntity.java @@ -10,17 +10,25 @@ public final class GeoEntity { private final String city; private final String country; private final String province; - + private final String countryCode; + public GeoEntity(final Builder builder){ this.city = builder.city; this.country = builder.country; this.province = builder.province; + this.countryCode = builder.countryCode; } public static class Builder{ + private String countryCode; private String city; private String country; private String province; + + public Builder withCountryCode(final String countryCode){ + this.countryCode = countryCode; + return this; + } public Builder withCity(final String city ){ this.city = city; @@ -54,10 +62,18 @@ public String getProvince() { return province; } + + public String getCountryCode() { + return countryCode; + } + @Override public String toString() { - return "GeoEntity [city=" + city + ", country=" + country + ", province=" + province + "]"; + return "GeoEntity{" + + "city='" + city + '\'' + + ", country='" + country + '\'' + + ", province='" + province + '\'' + + ", countryCode='" + countryCode + '\'' + + '}'; } - - } diff --git a/src/main/java/in/ankushs/dbip/importer/ResourceImporter.java b/src/main/java/in/ankushs/dbip/importer/ResourceImporter.java index 437e21d..147efb4 100644 --- a/src/main/java/in/ankushs/dbip/importer/ResourceImporter.java +++ b/src/main/java/in/ankushs/dbip/importer/ResourceImporter.java @@ -63,10 +63,11 @@ public void load(final File file) { logger.error("",ex); } - try (InputStream fis = new FileInputStream(file); - InputStream gis = new GZIPInputStream(fis); - Reader decorator = new InputStreamReader(gis, StandardCharsets.UTF_8); - BufferedReader reader = new BufferedReader(decorator);) + try (final InputStream fis = new FileInputStream(file); + final InputStream gis = new GZIPInputStream(fis); + final Reader decorator = new InputStreamReader(gis, StandardCharsets.UTF_8); + final BufferedReader reader = new BufferedReader(decorator); + ) { logger.debug("Reading dbip data from {}", file.getName()); String line = null; @@ -74,19 +75,23 @@ public void load(final File file) { while ((line = reader.readLine()) != null) { i++; final String[] array = csvParser.parseRecord(line); - final GeoAttributes geoAttributes = new GeoAttributesImpl.Builder() - .withCity(interner.intern(array[4])) + final GeoAttributes geoAttributes = new GeoAttributesImpl + .Builder() + .withStartInetAddress(InetAddresses.forString(array[0])) + .withEndInetAddress(InetAddresses.forString(array[1])) + .withCountryCode(array[2]) .withCountry(CountryResolver.resolveToFullName(array[2])) .withProvince(interner.intern(array[3])) - .withEndIp(InetAddresses.coerceToInteger(InetAddresses.forString(array[1]))) - .withStartIp(InetAddresses.coerceToInteger(InetAddresses.forString(array[0]))) + .withCity(interner.intern(array[4])) .build(); repository.save(geoAttributes); if (i % 100000 == 0) { logger.debug("Loaded {} entries", i); } } - } catch (final Exception e) { + } + + catch (final Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/in/ankushs/dbip/lookup/GeoEntityLookupServiceImpl.java b/src/main/java/in/ankushs/dbip/lookup/GeoEntityLookupServiceImpl.java index 97b684b..1e33da5 100644 --- a/src/main/java/in/ankushs/dbip/lookup/GeoEntityLookupServiceImpl.java +++ b/src/main/java/in/ankushs/dbip/lookup/GeoEntityLookupServiceImpl.java @@ -1,7 +1,9 @@ package in.ankushs.dbip.lookup; +import java.io.File; import java.net.InetAddress; +import in.ankushs.dbip.api.DbIpClient; import in.ankushs.dbip.api.GeoEntity; import in.ankushs.dbip.repository.DbIpRepository; import in.ankushs.dbip.repository.JavaMapDbIpRepositoryImpl; @@ -33,14 +35,14 @@ public GeoEntity lookup(final InetAddress inetAddress) { PreConditions.checkNull(inetAddress, "inetAddress cannot be null "); GeoEntity geoEntity = repository.get(inetAddress); if( geoEntity == null ){ - geoEntity = new GeoEntity.Builder() - .withCity(UNKNOWN).withCountry(UNKNOWN) - .withProvince(UNKNOWN).build(); + geoEntity = new GeoEntity + .Builder() + .withCity(UNKNOWN) + .withCountry(UNKNOWN) + .withCountryCode(UNKNOWN) + .withProvince(UNKNOWN) + .build(); } return geoEntity; } - - public static void main(String[] args) { - GeoEntityLookupService g1 = getInstance(); - } } diff --git a/src/main/java/in/ankushs/dbip/model/GeoAttributes.java b/src/main/java/in/ankushs/dbip/model/GeoAttributes.java index 9986fc4..716ff5c 100644 --- a/src/main/java/in/ankushs/dbip/model/GeoAttributes.java +++ b/src/main/java/in/ankushs/dbip/model/GeoAttributes.java @@ -5,7 +5,10 @@ import in.ankushs.dbip.api.GeoEntity; public interface GeoAttributes { - int getStartIp(); - int getEndIp(); + + InetAddress getStartInetAddress(); + + InetAddress getEndInetAddress(); + GeoEntity getGeoEntity(); } diff --git a/src/main/java/in/ankushs/dbip/model/GeoAttributesImpl.java b/src/main/java/in/ankushs/dbip/model/GeoAttributesImpl.java index 49c6fbe..2393f08 100644 --- a/src/main/java/in/ankushs/dbip/model/GeoAttributesImpl.java +++ b/src/main/java/in/ankushs/dbip/model/GeoAttributesImpl.java @@ -5,38 +5,48 @@ import in.ankushs.dbip.api.GeoEntity; public final class GeoAttributesImpl implements GeoAttributes { - private final int startIp; - private final int endIp; + private final String city; private final String country; private final String province ; + private final String countryCode; + private final InetAddress startInetAddress; + private final InetAddress endInetAddress; + private GeoAttributesImpl(final Builder builder){ - this.startIp = builder.startIp; - this.endIp = builder.endIp; + this.startInetAddress = builder.startInetAddress; + this.endInetAddress = builder.endInetAddress; this.city = builder.city; this.country = builder.country; this.province = builder.province; + this.countryCode = builder.countryCode; } public static class Builder{ - private int startIp; - private int endIp; + private InetAddress startInetAddress; + private InetAddress endInetAddress; private String city; private String country; private String province ; - - public Builder withStartIp(final int startIp){ - this.startIp = startIp; + private String countryCode; + + + public Builder withStartInetAddress(final InetAddress startInetAddress){ + this.startInetAddress = startInetAddress; return this; } - - public Builder withEndIp(final int endIp){ - this.endIp = endIp; + + public Builder withCountryCode(final String countryCode){ + this.countryCode = countryCode; return this; } - - + public Builder withEndInetAddress(final InetAddress endInetAddress){ + this.endInetAddress = endInetAddress; + return this; + } + + public Builder withCity(final String city){ this.city = city; return this; @@ -59,21 +69,26 @@ public GeoAttributesImpl build(){ } } + + @Override - public int getStartIp() { - return startIp; + public InetAddress getStartInetAddress() { + return startInetAddress; } @Override - public int getEndIp() { - return endIp; + public InetAddress getEndInetAddress() { + return endInetAddress; } @Override public GeoEntity getGeoEntity() { return new GeoEntity.Builder() - .withCity(city).withCountry(country) - .withProvince(province).build(); + .withCity(city) + .withCountry(country) + .withCountryCode(countryCode) + .withProvince(province) + .build(); } diff --git a/src/main/java/in/ankushs/dbip/repository/JavaMapDbIpRepositoryImpl.java b/src/main/java/in/ankushs/dbip/repository/JavaMapDbIpRepositoryImpl.java index 5bbe7a0..a62cb93 100644 --- a/src/main/java/in/ankushs/dbip/repository/JavaMapDbIpRepositoryImpl.java +++ b/src/main/java/in/ankushs/dbip/repository/JavaMapDbIpRepositoryImpl.java @@ -1,5 +1,8 @@ package in.ankushs.dbip.repository; +import java.math.BigInteger; +import java.net.Inet4Address; +import java.net.Inet6Address; import java.net.InetAddress; import java.util.TreeMap; import java.util.concurrent.Executor; @@ -9,14 +12,19 @@ import in.ankushs.dbip.api.GeoEntity; import in.ankushs.dbip.model.GeoAttributes; +import in.ankushs.dbip.utils.IPUtils; import in.ankushs.dbip.utils.PreConditions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * - * Singletonclass that uses a TreeMap + * Singletonthat uses a TreeMap * as repository. * @author Ankush Sharma */ public final class JavaMapDbIpRepositoryImpl implements DbIpRepository { + private static final Logger logger = LoggerFactory.getLogger(JavaMapDbIpRepositoryImpl.class); private static JavaMapDbIpRepositoryImpl instance = null; @@ -28,8 +36,9 @@ public static JavaMapDbIpRepositoryImpl getInstance(){ return instance; } - private static final TreeMap repository = new TreeMap<>(); - + private static final TreeMap IPV4_REPOSITORY = new TreeMap<>(); + private static final TreeMap IPV6_REPOSITORY = new TreeMap<>(); + /** * Lookup GeoEntity for an InetAddress * @param inetAddress The InetAddress to be resolved. @@ -38,10 +47,19 @@ public static JavaMapDbIpRepositoryImpl getInstance(){ @Override public GeoEntity get(final InetAddress inetAddress) { PreConditions.checkNull(inetAddress, "inetAddress must not be null"); - final Integer startIpNum = InetAddresses.coerceToInteger(inetAddress); - - return repository.floorEntry(startIpNum) == null ? null - : repository.floorEntry(startIpNum).getValue() ; + GeoEntity result = null; + if(inetAddress instanceof Inet4Address){ + final Integer startIpNum = InetAddresses.coerceToInteger(inetAddress); + + return IPV4_REPOSITORY.floorEntry(startIpNum) == null ? null + : IPV4_REPOSITORY.floorEntry(startIpNum).getValue() ; + } + else{ + final BigInteger startIpBigInt = IPUtils.ipv6ToBigInteger(inetAddress); + return IPV6_REPOSITORY.floorEntry(startIpBigInt) == null ? null + : IPV6_REPOSITORY.floorEntry(startIpBigInt).getValue(); + + } } /** @@ -52,8 +70,25 @@ public GeoEntity get(final InetAddress inetAddress) { @Override public void save(final GeoAttributes geoAttributes) { PreConditions.checkNull(geoAttributes, "geoAttributes must not be null"); - final Integer startIpNum = geoAttributes.getStartIp(); + final InetAddress startInetAddress = geoAttributes.getStartInetAddress(); + final InetAddress endInetAddress = geoAttributes.getEndInetAddress(); final GeoEntity geoEntity = geoAttributes.getGeoEntity(); - repository.put(startIpNum,geoEntity); + + if(startInetAddress instanceof Inet6Address + && endInetAddress instanceof Inet6Address) + { + final BigInteger startIpBigInt = IPUtils.ipv6ToBigInteger(startInetAddress); + IPV6_REPOSITORY.put(startIpBigInt,geoEntity); + } + else if (startInetAddress instanceof Inet4Address + && endInetAddress instanceof Inet4Address) + { + final Integer startIpNum = InetAddresses.coerceToInteger(startInetAddress); + IPV4_REPOSITORY.put(startIpNum,geoEntity); + } + else{ + //Well, this case should never happen. Maybe I'll throw in an exception later. + logger.warn("This shouldn't ever happen"); + } } } diff --git a/src/main/java/in/ankushs/dbip/utils/IPUtils.java b/src/main/java/in/ankushs/dbip/utils/IPUtils.java new file mode 100644 index 0000000..99df252 --- /dev/null +++ b/src/main/java/in/ankushs/dbip/utils/IPUtils.java @@ -0,0 +1,16 @@ +package in.ankushs.dbip.utils; + +import java.math.BigInteger; +import java.net.InetAddress; + +/** + * Created by Ankush on 07/02/17. + */ +public class IPUtils { + + public static BigInteger ipv6ToBigInteger(final InetAddress inetAddress){ + PreConditions.checkNull(inetAddress,"inetAddress cannot be null"); + final byte[] bytes = inetAddress.getAddress(); + return new BigInteger(1, bytes); + } +} diff --git a/src/main/java/in/ankushs/dbip/utils/Tes.java b/src/main/java/in/ankushs/dbip/utils/Tes.java deleted file mode 100644 index f6664ae..0000000 --- a/src/main/java/in/ankushs/dbip/utils/Tes.java +++ /dev/null @@ -1,13 +0,0 @@ -package in.ankushs.dbip.utils; - -import java.io.File; - -import in.ankushs.dbip.api.DbIpClient; - -public class Tes { - public static void main(String[] args) { - File gzip = new File("/Users/Ankush/Downloads/dbip-city-latest.csv.gz"); - DbIpClient client = new DbIpClient(gzip); - - } -} diff --git a/src/test/groovy/in/ankushs/dbip/BaseSpec.groovy b/src/test/groovy/in/ankushs/dbip/BaseSpec.groovy deleted file mode 100644 index 4b93c17..0000000 --- a/src/test/groovy/in/ankushs/dbip/BaseSpec.groovy +++ /dev/null @@ -1,11 +0,0 @@ -package in.ankushs.dbip - -import java.io.File; - -import spock.lang.Specification - -class BaseSpec extends Specification{ - - File file = new File(getClass().getClassLoader().getResource("dbip-city-2016-09.csv.gz").getFile()); - -} diff --git a/src/test/groovy/in/ankushs/dbip/DbIpClientSpec.groovy b/src/test/groovy/in/ankushs/dbip/DbIpClientSpec.groovy index 31a141a..b91b8cc 100644 --- a/src/test/groovy/in/ankushs/dbip/DbIpClientSpec.groovy +++ b/src/test/groovy/in/ankushs/dbip/DbIpClientSpec.groovy @@ -3,17 +3,18 @@ package in.ankushs.dbip import in.ankushs.dbip.api.DbIpClient import in.ankushs.dbip.api.GeoEntity import in.ankushs.dbip.exceptions.InvalidIPException +import spock.lang.Specification -class DbIpClientSpec extends BaseSpec { +class DbIpClientSpec extends Specification { def client def setup(){ - client = new DbIpClient(file) + client = new DbIpClient(new File("/Users/Ankush/Downloads/dbip-city-2017-02.csv.gz")) } def "Pass a valid Ip.All should work fine"(){ when : "Call the client" def ip = "216.159.232.248" - def client = new DbIpClient(file) + GeoEntity geoEntity = client.lookup(ip) then : "Should return some info.No exception thrown" geoEntity.city == 'Columbus' @@ -26,10 +27,12 @@ class DbIpClientSpec extends BaseSpec { given : "Some ip" def ip = "invalidIp" when : "Call the client" - def client = new DbIpClient(file) + GeoEntity geoEntity = client.lookup(ip) then : "Should return some info.No exception thrown" thrown InvalidIPException } + + } diff --git a/src/test/groovy/in/ankushs/dbip/DbIpLookupSpec.groovy b/src/test/groovy/in/ankushs/dbip/DbIpLookupSpec.groovy index 3e90b1b..4c065c1 100644 --- a/src/test/groovy/in/ankushs/dbip/DbIpLookupSpec.groovy +++ b/src/test/groovy/in/ankushs/dbip/DbIpLookupSpec.groovy @@ -2,16 +2,17 @@ package in.ankushs.dbip import in.ankushs.dbip.api.DbIpClient import in.ankushs.dbip.api.GeoEntity +import spock.lang.Specification -import javax.swing.plaf.metal.MetalBorders - -class DbIpLookupSpec extends BaseSpec{ +\ +class DbIpLookupSpec extends Specification{ def client def setup(){ - client = new DbIpClient(file) + client = new DbIpClient(new File("/Users/Ankush/Downloads/dbip-city-2017-02.csv.gz")) } - //Format City,State,Country + + //Format :City,State,Country def "New Delhi,Delhi,India"(){ when: def ip = "59.178.193.100" @@ -21,6 +22,7 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'New Delhi' geoEntity.country == 'India' geoEntity.province == 'Delhi' + geoEntity.countryCode == 'IN' } def "Mézin,Aquitaine-Limousin-Poitou-Charentes,France"(){ @@ -31,6 +33,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Bourlens' geoEntity.country == 'France' geoEntity.province == 'Aquitaine' + geoEntity.countryCode == 'FR' + } def "Columbus,Ohio,United States"(){ @@ -41,6 +45,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Columbus' geoEntity.country == 'United States' geoEntity.province == 'Ohio' + geoEntity.countryCode == 'US' + } def "Newark,New Jersey,United States"(){ @@ -51,6 +57,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Newark' geoEntity.country == 'United States' geoEntity.province == 'New Jersey' + geoEntity.countryCode == 'US' + } def "Lisbon,Lisbon District,Portugal"(){ @@ -61,6 +69,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Lisbon' geoEntity.country == 'Portugal' geoEntity.province == 'Lisbon District' + geoEntity.countryCode == 'PT' + } def "Melbourne,Victoria,Australia"(){ @@ -68,9 +78,11 @@ class DbIpLookupSpec extends BaseSpec{ def ip = "49.199.255.255" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Bundoora' + geoEntity.city == 'Melbourne' geoEntity.country == 'Australia' geoEntity.province == 'Victoria' + geoEntity.countryCode == 'AU' + } def "Auckland,Auckland,New Zealand"(){ @@ -81,6 +93,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Auckland' geoEntity.country == 'New Zealand' geoEntity.province == 'Auckland' + geoEntity.countryCode == 'NZ' + } def "Yekaterinburg,Sverdlovsk Oblast,Russian Federation"(){ @@ -91,6 +105,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Yekaterinburg' geoEntity.country == 'Russian Federation' geoEntity.province == 'Sverdlovsk Oblast' + geoEntity.countryCode == 'RU' + } def "Yekaterinburg,Sverdlovsk Oblast,Sri Lanka"(){ @@ -101,6 +117,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Colombo' geoEntity.country == 'Sri Lanka' geoEntity.province == 'Western Province' + geoEntity.countryCode == 'LK' + } def "Dunker,Södermanland County,Sweden"(){ @@ -111,6 +129,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Dunker' geoEntity.country == 'Sweden' geoEntity.province == 'Södermanland County' + geoEntity.countryCode == 'SE' + } def "Oslo,Oslo,Norway"(){ @@ -121,9 +141,11 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Oslo' geoEntity.country == 'Norway' geoEntity.province == 'Oslo' + geoEntity.countryCode == 'NO' } def "London,England,United Kingdom"(){ + when: def ip = "31.48.109.127" GeoEntity geoEntity = client.lookup(ip) @@ -131,28 +153,34 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'London' geoEntity.country == 'United Kingdom' geoEntity.province == 'England' + geoEntity.countryCode == 'GB' + } - def "Paris,Ile-de-france,France"(){ + def "Issy-les-Moulineaux,Ile-de-france,France"(){ when: def ip = "194.3.31.52" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Paris' + geoEntity.city == 'Issy-les-Moulineaux' geoEntity.country == 'France' - geoEntity.province == 'Ile-de-france' + geoEntity.province == 'Île-de-france' + geoEntity.countryCode == 'FR' + } - def "Qasr an Nile,Cairo Governorate,Egypt"(){ + def "Cairo,Cairo Governorate,Egypt"(){ when: def ip = "197.55.197.243" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Qasr an Nile' + geoEntity.city == 'Cairo' geoEntity.country == 'Egypt' geoEntity.province == 'Cairo Governorate' + geoEntity.countryCode == 'EG' + } - + def "Seoul,Seoul,Korea, Republic of"(){ when: def ip = "211.232.184.31" @@ -161,6 +189,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Seoul' geoEntity.country == "'Korea, Republic of'" geoEntity.province == 'Seoul' + geoEntity.countryCode == 'KR' + } def "Florence,Tuscany,Italy"(){ @@ -171,6 +201,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Florence' geoEntity.country == "Italy" geoEntity.province == 'Tuscany' + geoEntity.countryCode == 'IT' + } def "Amsterdam,North Holland,Netherlands"(){ @@ -178,11 +210,13 @@ class DbIpLookupSpec extends BaseSpec{ def ip = "92.68.194.100" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Den Haag' + geoEntity.city == 'Amsterdam' geoEntity.country == "Netherlands" - geoEntity.province == 'Zuid-holland' + geoEntity.province == 'North Holland' + geoEntity.countryCode == 'NL' + } - //1 + def "Bangkok,จังหวัด กรุงเทพมหานคร,Thailand"(){ when: def ip = "1.0.255.255" @@ -191,6 +225,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Bangkok' geoEntity.country == "Thailand" geoEntity.province == 'จังหวัด กรุงเทพมหานคร' + geoEntity.countryCode == 'TH' + } def "Minato,Tokyo,Japan"(){ @@ -201,6 +237,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Minato' geoEntity.country == "Japan" geoEntity.province == 'Tokyo' + geoEntity.countryCode == 'JP' + } def "Ahmedabad,Gujarat,India"(){ @@ -211,6 +249,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Ahmedabad' geoEntity.country == "India" geoEntity.province == 'Gujarat' + geoEntity.countryCode == 'IN' + } def "Adelaide,South Australia,Australia"(){ when: @@ -220,6 +260,8 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Adelaide' geoEntity.country == "Australia" geoEntity.province == 'South Australia' + geoEntity.countryCode == 'AU' + } def "Minsyong Township,Chiayi County,'Taiwan, Province Of China'"(){ @@ -227,11 +269,13 @@ class DbIpLookupSpec extends BaseSpec{ def ip = "1.170.171.25" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Taoyuan District' + geoEntity.city == 'Taitung City' geoEntity.country == "'Taiwan, Province Of China'" - geoEntity.province == 'Kaohsiung City' + geoEntity.province == 'Taitung County' + geoEntity.countryCode == 'TW' + } - + def "Roma,Lazio,Italy"(){ when: def ip = "2.40.217.22" @@ -240,17 +284,122 @@ class DbIpLookupSpec extends BaseSpec{ geoEntity.city == 'Milan' geoEntity.country == "Italy" geoEntity.province == 'Lombardy' + geoEntity.countryCode == 'IT' + } - def "Matamoros,Tamaulipas,Mexico"(){ + def "Ciudad de México,Tamaulipas,Mexico"(){ when: def ip = "189.159.147.1" GeoEntity geoEntity = client.lookup(ip) then: - geoEntity.city == 'Matamoros' + geoEntity.city == 'Ciudad de México' geoEntity.country == "Mexico" - geoEntity.province == 'Tamaulipas' + geoEntity.province == 'Distrito Federal' + geoEntity.countryCode == 'MX' + } - + + //=============== IPV6 =================== +//city,state,country + def "Ebène,Plaines Wilhems District,Mauritus"(){ + when: + def ip = "2c0f:ffbf:ffff:ffff:ffff:ffff:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Ebène' + geoEntity.country == "Mauritius" + geoEntity.province == 'Plaines Wilhems District' + geoEntity.countryCode == 'MU' + + } + + def "New York,New York,United States of America"(){ + when: + def ip = "2c10::" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'New York' + geoEntity.country == "United States" + geoEntity.province == 'New York' + geoEntity.countryCode == 'US' + + } + + + def "Gaborone,South-east,Botswana"(){ + when: + def ip = "2c0f:fac8:f2ff:ffff:ffff:ffff:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Gaborone' + geoEntity.country == "Botswana" + geoEntity.province == 'South-east' + geoEntity.countryCode == 'BW' + + } + + def "Nairobi,Nairobi,Kenya"(){ + when: + def ip = "2c0f:f468:ff2f:ffff:ffff:ffff:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Nairobi' + geoEntity.country == "Kenya" + geoEntity.province == 'Nairobi' + geoEntity.countryCode == 'KE' + + } + + + def "Vejle,Region Syddanmark,Denmark"(){ + when: + def ip = "2a0b:ee00::" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Vejle' + geoEntity.country == "Denmark" + geoEntity.province == 'Region Syddanmark' + geoEntity.countryCode == 'DK' + + } + + def "Tehran,Tehran Province,Iran, Islamic Republic Of"(){ + when: + def ip = "2a0b:6b07:ffff:ffff:ffff:f1ff:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Tehran' + geoEntity.country == "'Iran, Islamic Republic Of'" + geoEntity.province == 'Tehran Province' + geoEntity.countryCode == 'IR' + + } + + def "Amsterdam, North Holland,Netherlands"(){ + when: + def ip = "2a0b:6eff:ffff:ffff:ffff:f2ff:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Amsterdam' + geoEntity.country == "Netherlands" + geoEntity.province == 'North Holland' + geoEntity.countryCode == 'NL' + + } + + + + def "Modena, Emilia-romagna,Italy"(){ + when: + def ip = "2a0b:5f00:0:ffff:ffff:fff2:ffff:ffff" + GeoEntity geoEntity = client.lookup(ip) + then: + geoEntity.city == 'Modena' + geoEntity.country == "Italy" + geoEntity.province == 'Emilia-romagna' + geoEntity.countryCode == 'IT' + + } }