Skip to content

Commit

Permalink
Improving and adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandonogueira committed Mar 8, 2017
1 parent bf5e68e commit 0882dde
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.fernandonogueira'
version '0.1-SNAPSHOT'
version '0.2-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'maven'
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/jingo/maps/geo/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/jingo/maps/geo/LocationTypeName.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
2 changes: 1 addition & 1 deletion src/main/java/jingo/maps/geo/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class Point extends AbstractLocationType {
private float[] coordinates;

public Point() {
super("Point");
super(LocationTypeName.POINT.getName());
}

public float[] getCoordinates() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/jingo/maps/parser/AdvancedQueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/jingo/maps/query/AdvancedQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/main/java/jingo/maps/result/geocode/Confidence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package jingo.maps.result.geocode;

public enum Confidence {
High, Medium, Low
}
6 changes: 3 additions & 3 deletions src/main/java/jingo/maps/result/geocode/GeocodeResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
34 changes: 30 additions & 4 deletions src/test/java/jingo/maps/JingoAdvancedQueryHappyDayTests.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<GeocodeResource> resourceSet = result.getResourceSets().get(0);

assertThat(resourceSet.getEstimatedTotal()).isNotNull();
assertThat(resourceSet.getResources()).isNotEmpty();

List<GeocodeResource> 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() {
Expand Down

0 comments on commit 0882dde

Please sign in to comment.