com.maxmind.geoip2.record.Continent Java Examples
The following examples show how to use
com.maxmind.geoip2.record.Continent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MaxMindGeoLocationServiceTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void lookupShouldReturnCountryIsoWhenDatabaseReaderWasSet() throws NoSuchFieldException, IOException, GeoIp2Exception { // given final Country country = new Country(null, null, null, "fr", null); final Continent continent = new Continent(null, "eu", null, null); final City city = new City(singletonList("test"), null, null, singletonMap("test", "Paris")); final Location location = new Location(null, null, 48.8566, 2.3522, null, null, null); final ArrayList<Subdivision> subdivisions = new ArrayList<>(); subdivisions.add(new Subdivision(null, null, null, "paris", null)); final CityResponse cityResponse = new CityResponse(city, continent, country, location, null, null, null, null, subdivisions, null); final DatabaseReader databaseReader = Mockito.mock(DatabaseReader.class); given(databaseReader.city(any())).willReturn(cityResponse); FieldSetter.setField(maxMindGeoLocationService, maxMindGeoLocationService.getClass().getDeclaredField("databaseReader"), databaseReader); // when final Future<GeoInfo> future = maxMindGeoLocationService.lookup(TEST_IP, null); // then assertThat(future.succeeded()).isTrue(); assertThat(future.result()) .isEqualTo(GeoInfo.builder() .vendor("maxmind") .continent("eu") .country("fr") .region("paris") .city("Paris") .lat(48.8566f) .lon(2.3522f) .build()); }
Example #2
Source File: GeoIPCountryDissector.java From logparser with Apache License 2.0 | 5 votes |
protected void extractCountryFields(final Parsable<?> parsable, final String inputname, AbstractCountryResponse response) throws DissectionFailure { if (wantAnyContinent) { Continent continent = response.getContinent(); if (continent != null) { if (wantContinentName) { parsable.addDissection(inputname, "STRING", "continent.name", continent.getName()); } if (wantContinentCode) { parsable.addDissection(inputname, "STRING", "continent.code", continent.getCode()); } } } if (wantAnyCountry) { Country country = response.getCountry(); if (country != null) { if (wantCountryName) { parsable.addDissection(inputname, "STRING", "country.name", country.getName()); } if (wantCountryIso) { parsable.addDissection(inputname, "STRING", "country.iso", country.getIsoCode()); } if (wantCountryGetConfidence) { parsable.addDissection(inputname, "NUMBER", "country.getconfidence", country.getConfidence()); } if (wantCountryIsInEuropeanUnion) { parsable.addDissection(inputname, "BOOLEAN", "country.isineuropeanunion", country.isInEuropeanUnion() ? 1L : 0L); } } } }