From 0882dde502aa4030d83298c742c2056290038065 Mon Sep 17 00:00:00 2001 From: Fernando Nogueira Date: Wed, 8 Mar 2017 12:21:35 -0300 Subject: [PATCH] Improving and adding tests --- build.gradle | 2 +- src/main/java/jingo/maps/geo/Address.java | 7 ++-- .../java/jingo/maps/geo/LocationTypeName.java | 17 ++++++++++ src/main/java/jingo/maps/geo/Point.java | 2 +- .../maps/parser/AdvancedQueryParser.java | 5 +-- .../java/jingo/maps/query/AdvancedQuery.java | 30 ++++++++++++++-- .../jingo/maps/result/geocode/Confidence.java | 5 +++ .../maps/result/geocode/GeocodeResource.java | 6 ++-- .../maps/JingoAdvancedQueryHappyDayTests.java | 34 ++++++++++++++++--- 9 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 src/main/java/jingo/maps/geo/LocationTypeName.java create mode 100644 src/main/java/jingo/maps/result/geocode/Confidence.java diff --git a/build.gradle b/build.gradle index 2ec16e1..16e7962 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.github.fernandonogueira' -version '0.1-SNAPSHOT' +version '0.2-SNAPSHOT' apply plugin: 'java' apply plugin: 'maven' diff --git a/src/main/java/jingo/maps/geo/Address.java b/src/main/java/jingo/maps/geo/Address.java index df7065b..51a6d29 100644 --- a/src/main/java/jingo/maps/geo/Address.java +++ b/src/main/java/jingo/maps/geo/Address.java @@ -3,11 +3,14 @@ public class Address extends AbstractLocationType { /** - * The official street line of an address relative to the area, as specified by the Locality, or PostalCode, properties. Typical use of this element would be to provide a street address or any official address. + * The official street line of an address relative to the area, + * as specified by the Locality, or PostalCode, properties. + * Typical use of this element would be to provide a street address or any official address. */ private String addressLine; /** - * A string specifying the populated place for the address. This typically refers to a city, but may refer to a suburb or a neighborhood in certain countries. + * A string specifying the populated place for the address. + * This typically refers to a city, but may refer to a suburb or a neighborhood in certain countries. */ private String locality; /** diff --git a/src/main/java/jingo/maps/geo/LocationTypeName.java b/src/main/java/jingo/maps/geo/LocationTypeName.java new file mode 100644 index 0000000..7b02c2c --- /dev/null +++ b/src/main/java/jingo/maps/geo/LocationTypeName.java @@ -0,0 +1,17 @@ +package jingo.maps.geo; + +public enum LocationTypeName { + + POINT("Point"); + + private String name; + + LocationTypeName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + +} diff --git a/src/main/java/jingo/maps/geo/Point.java b/src/main/java/jingo/maps/geo/Point.java index 9cd507a..e846787 100644 --- a/src/main/java/jingo/maps/geo/Point.java +++ b/src/main/java/jingo/maps/geo/Point.java @@ -5,7 +5,7 @@ public class Point extends AbstractLocationType { private float[] coordinates; public Point() { - super("Point"); + super(LocationTypeName.POINT.getName()); } public float[] getCoordinates() { diff --git a/src/main/java/jingo/maps/parser/AdvancedQueryParser.java b/src/main/java/jingo/maps/parser/AdvancedQueryParser.java index 7151fc2..76b8ed8 100644 --- a/src/main/java/jingo/maps/parser/AdvancedQueryParser.java +++ b/src/main/java/jingo/maps/parser/AdvancedQueryParser.java @@ -43,11 +43,12 @@ public String parse(Query query) { return str; } - private String concatIfPresent(String property, String value, String currentStr) { + private String concatIfPresent(String property, Object value, String currentStr) { if (value != null) { + String stringVal = String.valueOf(value); currentStr = addSeparatorIfNecessary(currentStr); try { - currentStr += property + "=" + java.net.URLEncoder.encode(value, "utf-8"); + currentStr += property + "=" + java.net.URLEncoder.encode(stringVal, "utf-8"); } catch (UnsupportedEncodingException e) { LOGGER.error("Error parsing Jingo query", e); } diff --git a/src/main/java/jingo/maps/query/AdvancedQuery.java b/src/main/java/jingo/maps/query/AdvancedQuery.java index 4ba8368..3ae7e4c 100644 --- a/src/main/java/jingo/maps/query/AdvancedQuery.java +++ b/src/main/java/jingo/maps/query/AdvancedQuery.java @@ -2,14 +2,35 @@ public class AdvancedQuery implements Query { + /** + * A string specifying the country or region name of an address. + */ private String countryRegion; + /** + * A string specifying the subdivision name in the country or region for an address. + * This element is typically treated as the first order administrative subdivision, + * but in some cases it is the second, third, + * or fourth order subdivision in a country, dependency, or region. + */ private String adminDistrict; + /** + * A string specifying the populated place for the address. + * This typically refers to a city, but may refer to a suburb or a neighborhood in certain countries. + */ private String locality; + /** + * A string specifying the post code, postal code, or ZIP Code of an address. + */ private String postalCode; + /** + * The official street line of an address relative to the area, + * as specified by the Locality, or PostalCode, properties. + * Typical use of this element would be to provide a street address or any official address. + */ private String addressLine; private String userLocation; @@ -18,7 +39,10 @@ public class AdvancedQuery implements Query { private String includeNeighborhood; - private String maxResults; + /** + * Max results + */ + private Long maxResults; public String getCountryRegion() { return countryRegion; @@ -84,11 +108,11 @@ public void setIncludeNeighborhood(String includeNeighborhood) { this.includeNeighborhood = includeNeighborhood; } - public String getMaxResults() { + public Long getMaxResults() { return maxResults; } - public void setMaxResults(String maxResults) { + public void setMaxResults(Long maxResults) { this.maxResults = maxResults; } } diff --git a/src/main/java/jingo/maps/result/geocode/Confidence.java b/src/main/java/jingo/maps/result/geocode/Confidence.java new file mode 100644 index 0000000..2e086d3 --- /dev/null +++ b/src/main/java/jingo/maps/result/geocode/Confidence.java @@ -0,0 +1,5 @@ +package jingo.maps.result.geocode; + +public enum Confidence { + High, Medium, Low +} diff --git a/src/main/java/jingo/maps/result/geocode/GeocodeResource.java b/src/main/java/jingo/maps/result/geocode/GeocodeResource.java index 0f023ee..9eedcd0 100644 --- a/src/main/java/jingo/maps/result/geocode/GeocodeResource.java +++ b/src/main/java/jingo/maps/result/geocode/GeocodeResource.java @@ -36,7 +36,7 @@ public class GeocodeResource implements JingoResource { * The level of confidence that the geocoded location result is a match. * Use this value with the match code to determine for more complete information about the match. */ - private String confidence; + private Confidence confidence; /** * The classification of the geographic entity returned, such as Address. @@ -76,11 +76,11 @@ public void setAddress(Address address) { this.address = address; } - public String getConfidence() { + public Confidence getConfidence() { return confidence; } - public void setConfidence(String confidence) { + public void setConfidence(Confidence confidence) { this.confidence = confidence; } diff --git a/src/test/java/jingo/maps/JingoAdvancedQueryHappyDayTests.java b/src/test/java/jingo/maps/JingoAdvancedQueryHappyDayTests.java index 589a2ef..1a7f228 100644 --- a/src/test/java/jingo/maps/JingoAdvancedQueryHappyDayTests.java +++ b/src/test/java/jingo/maps/JingoAdvancedQueryHappyDayTests.java @@ -1,14 +1,19 @@ package jingo.maps; +import jingo.maps.geo.Address; +import jingo.maps.geo.LocationTypeName; +import jingo.maps.geo.Point; import jingo.maps.query.AdvancedQuery; import jingo.maps.query.Query; import jingo.maps.result.JingoResult; +import jingo.maps.result.ResourceSet; import jingo.maps.result.geocode.GeocodeResource; import jingo.maps.utils.TestUtils; import org.junit.Before; import org.junit.Test; import java.io.IOException; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -29,10 +34,31 @@ public void simpleGeocodeTest() throws IOException { assertThat(result).isNotNull(); assertThat(result.getAuthenticationResultCode()).isEqualTo("ValidCredentials"); assertThat(result.getResourceSets()).isNotEmpty(); - assertThat(result.getResourceSets().get(0).getEstimatedTotal()).isNotNull(); - assertThat(result.getResourceSets().get(0).getResources()).isNotEmpty(); - assertThat(result.getResourceSets().get(0).getResources().get(0).getBbox()).isNotNull(); - assertThat(result.getResourceSets().get(0).getResources().get(0).getBbox().length).isNotZero(); + + ResourceSet resourceSet = result.getResourceSets().get(0); + + assertThat(resourceSet.getEstimatedTotal()).isNotNull(); + assertThat(resourceSet.getResources()).isNotEmpty(); + + List resourceList = resourceSet.getResources(); + + GeocodeResource firstResource = resourceList.get(0); + + assertThat(firstResource.getBbox()).isNotNull(); + assertThat(firstResource.getBbox().length).isNotZero(); + + assertThat(firstResource.getAddress()).isNotNull(); + + assertThat(firstResource.getPoint()).isNotNull(); + Point point = firstResource.getPoint(); + + assertThat(point.getCoordinates()).isNotEmpty(); + assertThat(point.getType()).isEqualTo(LocationTypeName.POINT.getName()); + + Address addr = firstResource.getAddress(); + assertThat(addr.getAddressLine()).isNotEmpty(); + + assertThat(addr.getLocality()).isNotEmpty(); } private Query givenAnAdvancedQuery() {