Parth Joshi 224a3a8a42 GeoIp Article PR (#789)
* GEO Ip Article first commit.

* Changes in controller and flow as per review by Kevin.

* Removed this file from spring-mvc-java as I had worked on spring-mvc-xml
and this was commited by mistake.

* Some fix in service usage as i was initializing service, intializing the
db in the each requests.

* Changes for Integration Testing Config. Renaming the test file for the
same purpose.

* Removed integration profile.
2016-11-18 16:02:52 -06:00

32 lines
1.0 KiB
Java

package com.baeldung.geoip;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import org.junit.Test;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
public class GeoIpIntegrationTest {
@Test
public void givenIP_whenFetchingCity_thenReturnsCityData() throws IOException, GeoIp2Exception {
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
DatabaseReader dbReader = new DatabaseReader.Builder(database).build();
InetAddress ipAddress = InetAddress.getByName("202.47.112.9");
CityResponse response = dbReader.city(ipAddress);
String countryName = response.getCountry().getName();
String cityName = response.getCity().getName();
String postal = response.getPostal().getCode();
String state = response.getLeastSpecificSubdivision().getName();
}
}