cleaned up location map processing - added exceptions + REST tests to verify success and exceptions
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bd0a1e97 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bd0a1e97 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bd0a1e97 Branch: refs/heads/index-alias Commit: bd0a1e97b56639f93b1260ff7fe4abd1e510f2f4 Parents: 3e21011 Author: Rod Simpson <[email protected]> Authored: Fri Nov 21 17:42:35 2014 -0700 Committer: Rod Simpson <[email protected]> Committed: Fri Nov 21 17:42:35 2014 -0700 ---------------------------------------------------------------------- .../corepersistence/util/CpEntityMapUtils.java | 62 ++++--- .../persistence/model/field/LocationField.java | 3 - .../index/impl/EntityIndexMapUtils.java | 4 +- .../collection/groups/GroupResourceIT.java | 182 +----------------- .../applications/queries/GeoPagingTest.java | 41 +++-- .../applications/queries/basicGeoTests.java | 184 +++++++++++++++++++ 6 files changed, 251 insertions(+), 225 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java index c110509..ba59154 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java @@ -137,37 +137,45 @@ public class CpEntityMapUtils { private static void processMapValue( Object value, String fieldName, Entity entity, String entityType) { - Field field = null; - // is the map really a location element? - Map<String, Object> m = (Map<String, Object>)value; - if ( m.size() == 2) { - Double lat = null; - Double lon = null; - try { - if ( m.get("latitude") != null && m.get("longitude") != null ) { - lat = Double.parseDouble( m.get("latitude").toString() ); - lon = Double.parseDouble( m.get("longitude").toString() ); - - } else if ( m.get("lat") != null && m.get("lon") != null ) { - lat = Double.parseDouble( m.get("lat").toString() ); - lon = Double.parseDouble( m.get("lon").toString() ); + if ("location" .equals(fieldName.toString().toLowerCase()) ) { + // get the object to inspect + Map<String, Object> m = (Map<String, Object>) value; + // should have two elements + if (m.size() == 2) { + Double lat = null; + Double lon = null; + // check the properties to make sure they are set and are doubles + if (m.get("latitude") != null && m.get("longitude") != null) { + try { + lat = Double.parseDouble(m.get("latitude").toString()); + lon = Double.parseDouble(m.get("longitude").toString()); + } catch (NumberFormatException ignored) { + throw new IllegalArgumentException("Latitude and longitude must be doubles (e.g. 32.1234)."); + } + } else if (m.get("lat") != null && m.get("lon") != null) { + try { + lat = Double.parseDouble(m.get("lat").toString()); + lon = Double.parseDouble(m.get("lon").toString()); + } catch (NumberFormatException ignored) { + throw new IllegalArgumentException("Latitude and longitude must be doubles (e.g. 32.1234)."); + } + } else { + throw new IllegalArgumentException("Location properties require two fields - latitude and longitude, or lat and lon"); } - } catch ( NumberFormatException ignored ) {} - - if ( lat != null && lon != null ) { - field = new LocationField( fieldName, new Location( lat, lon )); + + if (lat != null && lon != null) { + entity.setField( new LocationField(fieldName, new Location(lat, lon))); + } else { + throw new IllegalArgumentException("Unable to parse location field properties - make sure they conform - lat and lon, and should be doubles."); + } + } else { + throw new IllegalArgumentException("Location properties require two fields - latitude and longitude, or lat and lon."); } - } - - if ( field == null ) { - - // not a location element, process it as map - entity.setField( new EntityObjectField( fieldName, - fromMap( (Map<String, Object>)value, entityType, false ))); // recursion - } else { - entity.setField( field ); + // not a location element, process it as map + entity.setField(new EntityObjectField(fieldName, + fromMap((Map<String, Object>) value, entityType, false))); // recursion } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java index e220099..407fd44 100644 --- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java +++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java @@ -32,9 +32,6 @@ public class LocationField extends AbstractField<Location> { super( name, value ); } - public LocationField() { - - } @Override http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java index af3c7ea..6701a7c 100644 --- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java +++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java @@ -99,8 +99,10 @@ class EntityIndexMapUtils { } else if ( value instanceof Map ) { - Field field = null; + // CpEntityMapUtils.processMapValue(value); + Field field = null; +//TODO remove this and use the code in CpEntityMapUtils.java // is the map really a location element? Map<String, Object> m = (Map<String, Object>)value; if ( m.size() == 2) { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java index 5d21eb9..704ca17 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java @@ -143,9 +143,9 @@ public class GroupResourceIT extends AbstractRestIT { * Verify that we cannot create a group with a space in the path */ @Test - public void postGroupActivity() { + public void postGroupActivity() throws IOException { + -/* //1. create a group GroupsCollection groups = context.groups(); @@ -157,184 +157,17 @@ public class GroupResourceIT extends AbstractRestIT { assertNull(testGroup.get("errors")); assertEquals(testGroup.get("path").asText(), groupPath); - //2. - /* - UUID id = UUIDUtils.newTimeUUID(); - - String groupPath = "groupPath" + id; - String groupTitle = "groupTitle " + id; - String groupName = "groupName" + id; - - ApiResponse response = client.createGroup( groupPath, groupTitle, groupName ); - - assertNull( "Error was: " + response.getErrorDescription(), response.getError() ); - - refreshIndex("test-organization", "test-app"); - - UUID newId = response.getEntities().get( 0 ).getUuid(); - - Query results = client.queryGroups( String.format( "name='%s'", groupName ) ); - - response = results.getResponse(); - - UUID entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - - results = client.queryGroups( String.format( "title='%s'", groupTitle ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - - results = client.queryGroups( String.format( "title contains '%s'", id ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); + //2. post group activity - results = client.queryGroups( String.format( "path='%s'", groupPath ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - */ + //TODO: actually post a group activity } -} - -/* - @Test(expected = IllegalArgumentException.class) - public void failGroupNameValidation() throws IOException{ - - - - //context.application().groups().group("mygroup").connection("likes").collection("users").entity("bob").post(); - - - /* - Map user1 = - hashMap( "username", "user1" ).map( "email", "[email protected]" ).map( "fullname", "Bob Smith" ); - - users.create( user1 ); - - GroupsCollection groups = context.groups(); - - /* - // set up context - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String path = "/"+orgName+"/"+appName+"/groups/"; - - //----------------------------------------------- - // 1. test for group path with slash - //----------------------------------------------- - String groupPath = "grouppath/slash" + UUIDUtils.newTimeUUID(); - - String json = "{\"path\":\""+ groupPath +"\"}"; - JsonNode node = mapper.readTree( resource().path( path ) - .queryParam( "access_token", context.getActiveUser().getToken() ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, json )); - - //verify - assertNull( node.get( "errors" ) ); - assertEquals( node.get( "entities" ).get(0).get("path").asText(), groupPath); - //----------------------------------------------- - //2. test for group path with space - //----------------------------------------------- - groupPath = "grouppath space" + UUIDUtils.newTimeUUID(); - try { - json = "{\"path\":\"" + groupPath + "\"}"; - node = mapper.readTree(resource().path(path) - .queryParam("access_token", context.getActiveUser().getToken()).accept(MediaType.APPLICATION_JSON) - .type(MediaType.APPLICATION_JSON_TYPE).post(String.class, json)); - } catch (Exception e) { - - //verify - //assertNull( node.get( "errors" ) ); - String doug = node.get("error").asText(); - assertEquals( node.get("error").asText(), "illegal_argument"); - } - - - refreshIndex("test-organization", "test-app"); - - { - boolean failed = false; - try { - ApiResponse groupResponse = client.createGroup( "groupName withspace" ); - failed = groupResponse.getError() != null; - } catch ( Exception e ) { - failed = true; - } - assertTrue( failed ); - } - - } - -/* @Test - public void postGroupActivity() { - - // don't populate the user, it will use the currently authenticated - // user. - - UUID id = UUIDUtils.newTimeUUID(); - - String groupPath = "groupPath" + id; - String groupTitle = "groupTitle " + id; - String groupName = "groupName" + id; - - ApiResponse response = client.createGroup( groupPath, groupTitle, groupName ); - - assertNull( "Error was: " + response.getErrorDescription(), response.getError() ); - - refreshIndex("test-organization", "test-app"); - - UUID newId = response.getEntities().get( 0 ).getUuid(); - - Query results = client.queryGroups( String.format( "name='%s'", groupName ) ); - - response = results.getResponse(); - - UUID entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - - results = client.queryGroups( String.format( "title='%s'", groupTitle ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - - results = client.queryGroups( String.format( "title contains '%s'", id ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); - - assertEquals( newId, entityId ); - - results = client.queryGroups( String.format( "path='%s'", groupPath ) ); - - response = results.getResponse(); - - entityId = response.getEntities().get( 0 ).getUuid(); + public void addRemovePermission() throws IOException { - assertEquals( newId, entityId ); - } + GroupsCollection groups = context.groups(); - @Test - public void addRemovePermission() throws IOException { UUID id = UUIDUtils.newTimeUUID(); @@ -389,7 +222,7 @@ public class GroupResourceIT extends AbstractRestIT { assertTrue( node.get( "data" ).size() == 0 ); } - +/* @Test public void addRemoveRole() throws IOException { @@ -481,3 +314,4 @@ public class GroupResourceIT extends AbstractRestIT { } */ +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java index a3b4a93..2944fce 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java @@ -151,25 +151,25 @@ public class GeoPagingTest extends AbstractRestIT { public void testFarAwayLocationFromCenter() throws IOException { JsonNode node = null; - String collectionName = "testFarAwayLocation" + UUIDUtils.newTimeUUID(); + String collectionType = "testFarAwayLocation" + UUIDUtils.newTimeUUID(); Point center = new Point( 37.776753, -122.407846 ); String queryClose = locationQuery( 10000, center ); - String queryFar = locationQuery( 40000000, center ); + String queryFar = locationQuery(40000000, center); //TODO: move test setup out of the test. /*Create */ - createGeoUser( "usergrid", collectionName, -33.746369, 150.952183 ); + createGeoUser( "usergrid", collectionType, -33.746369, 150.952183 ); - createGeoUser( "usergrid2", collectionName, -33.889058, 151.124024 ); + createGeoUser( "usergrid2", collectionType, -33.889058, 151.124024 ); /* run queries */ - node = queryCollection( collectionName, queryClose ); + node = queryCollection( collectionType, queryClose ); assertEquals( "Results from nearby, should return nothing", 0, node.get( "entities" ).size() ); - node = queryCollection( collectionName, queryFar ); + node = queryCollection( collectionType, queryFar ); assertEquals( "Results from center point to ridiculously far", 2, node.get( "entities" ).size() ); } @@ -182,26 +182,26 @@ public class GeoPagingTest extends AbstractRestIT { @Test public void testFarAwayLocationWithOneResultCloser() throws IOException { JsonNode node = null; - String collectionName = "testFarAwayLocation" + UUIDUtils.newTimeUUID(); + String collectionType = "testFarAwayLocation" + UUIDUtils.newTimeUUID(); Point center = new Point( -33.746369, 150.952183 ); String queryClose = locationQuery( 10000, center ); String queryFar = locationQuery( 40000000, center ); /*Create */ - createGeoUser( "usergrid", collectionName, -33.746369, 150.952183 ); + createGeoUser( "usergrid", collectionType, -33.746369, 150.952183 ); - createGeoUser( "usergrid2", collectionName, -33.889058, 151.124024 ); + createGeoUser("usergrid2", collectionType, -33.889058, 151.124024); /* run queries */ - node = queryCollection( collectionName, queryClose ); + node = queryCollection( collectionType, queryClose ); - assertEquals( "Results from nearby, should return 1 store", 1, node.get( "entities" ).size() ); + assertEquals("Results from nearby, should return 1 store", 1, node.get("entities").size()); - node = queryCollection( collectionName, queryFar ); + node = queryCollection( collectionType, queryFar ); - assertEquals( "Results from center point to ridiculously far", 2, node.get( "entities" ).size() ); + assertEquals("Results from center point to ridiculously far", 2, node.get("entities").size()); } @@ -261,7 +261,7 @@ public class GeoPagingTest extends AbstractRestIT { } catch ( UniformInterfaceException e ) { JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) ); - fail( node.get( "error" ).textValue() ); + fail( nodeError.get( "error" ).textValue() ); } /* @@ -282,14 +282,14 @@ public class GeoPagingTest extends AbstractRestIT { } - private JsonNode queryCollection( String collectionName, String query ) throws IOException { + private JsonNode queryCollection( String collectionType, String query ) throws IOException { JsonNode node = null; try { - node = context.collection( collectionName ).withQuery( query ).get(); + node = context.collection( collectionType ).withQuery( query ).get(); } catch ( UniformInterfaceException e ) { JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) ); - fail( node.get( "error" ).textValue() ); + fail( nodeError.get( "error" ).textValue() ); } assertNotNull( node ); @@ -297,7 +297,7 @@ public class GeoPagingTest extends AbstractRestIT { } - private void createGeoUser( String username, String collectionName, Double lat, Double lon ) throws IOException { + private void createGeoUser( String username, String collectionType, Double lat, Double lon ) throws IOException { JsonNode node = null; @@ -306,11 +306,11 @@ public class GeoPagingTest extends AbstractRestIT { user.put( "name", username ); try { - node = context.collection( collectionName ).post( user ); + node = context.collection( collectionType ).post( user ); } catch ( UniformInterfaceException e ) { JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) ); - fail( node.get( "error" ).textValue() ); + fail( nodeError.get( "error" ).textValue() ); } assertNotNull( node ); @@ -330,6 +330,7 @@ public class GeoPagingTest extends AbstractRestIT { } + private String locationQuery( int metersAway, Point startingPoint ) { return "select * where location within " + String.valueOf( metersAway ) + " of " + startingPoint.getLat() + "," + startingPoint.getLon(); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd0a1e97/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/basicGeoTests.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/basicGeoTests.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/basicGeoTests.java new file mode 100644 index 0000000..e921b37 --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/basicGeoTests.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.usergrid.rest.applications.queries; + + +import java.util.*; + +import com.fasterxml.jackson.databind.JsonNode; +import com.sun.jersey.api.client.UniformInterfaceException; + +import java.io.IOException; + +import org.apache.usergrid.persistence.Entity; +import org.apache.usergrid.persistence.EntityManager; +import org.apache.usergrid.persistence.Results; + +import org.jclouds.json.Json; +import org.junit.Rule; +import org.junit.Test; + +import org.apache.usergrid.persistence.geo.model.Point; +import org.apache.usergrid.persistence.index.query.Query; +import org.apache.usergrid.persistence.index.utils.UUIDUtils; +import org.apache.usergrid.rest.AbstractRestIT; +import org.apache.usergrid.rest.TestContextSetup; +import org.apache.usergrid.rest.test.resource.CustomCollection; + +import static org.junit.Assert.assertEquals; +import static org.apache.usergrid.utils.MapUtils.hashMap; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + + +/** + * Basic Geo Tests - CRUD entities with geo points, exceptions for malformed calls + * + * @author rockerston + */ +public class basicGeoTests extends AbstractRestIT { + + @Rule + public TestContextSetup context = new TestContextSetup( this ); + + public final String latitude = "latitude"; + + /** + * Create a entity with a geo location point in it + */ + @Test + public void createEntityWithGeoLocationPoint() throws IOException { + + String collectionType = "stores"; + JsonNode node = null; + Double lat = 37.776753; + Double lon = -122.407846; + Map<String, Double> latLon = hashMap("latitude", lat); + latLon.put( "longitude", lon ); + Map<String, Object> entityData = new HashMap<String, Object>(); + entityData.put( "location", latLon ); + + try { + node = context.collection( collectionType ).post( entityData ); + } + catch ( UniformInterfaceException e ) { + JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) ); + fail( node.get( "error" ).textValue() ); + } + + assertNotNull( node ); + assertEquals(lat.toString(), node.get("location").get("latitude").asText() ); + assertEquals( lon.toString(), node.get( "location" ).get("longitude").asText() ); + + } + + /** + * Test exceptions for entities with poorly created geo points + * 1. misspell latitude + * 2. misspell longitude + */ + @Test + public void createEntitiesWithBadSpelling() throws IOException { + + String collectionType = "stores"; + JsonNode node = null; + Double lat = 37.776753; + Double lon = -122.407846; + + // 1. misspell latitude + Map<String, Double> misspelledLatitude = hashMap("latitudee", lat); + misspelledLatitude.put( "longitude", lon ); + Map<String, Object> misspelledLatitudeEntityData = new HashMap<String, Object>(); + misspelledLatitudeEntityData.put( "location", misspelledLatitude ); + + try { + node = context.collection( collectionType ).post( misspelledLatitudeEntityData ); + fail("System allowed misspelled location property - latitudee, which it should not"); + } + catch ( UniformInterfaceException e ) { + //verify the correct error was returned + JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class )); + assertEquals( "illegal_argument", nodeError.get( "error" ).textValue() ); + } + + // 2. misspell longitude + Map<String, Double> misspelledLongitude = hashMap("latitude", lat); + misspelledLongitude.put( "longitudee", lon ); + Map<String, Object> misspelledLongitudeEntityData = new HashMap<String, Object>(); + misspelledLongitudeEntityData.put( "location", misspelledLongitude ); + + try { + node = context.collection( collectionType ).post( misspelledLongitudeEntityData ); + fail("System allowed misspelled location property - longitudee, which it should not"); + } + catch ( UniformInterfaceException e ) { + //verify the correct error was returned + JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class )); + assertEquals( "illegal_argument", nodeError.get( "error" ).textValue() ); + } + + } + + + /** + * Test exceptions for entities with poorly created geo points + * 1. pass only one point instead of two + * 2. pass a values that are not doubles + */ + @Test + public void createEntitiesWithBadPoints() throws IOException { + + String collectionType = "stores"; + JsonNode node = null; + Double lat = 37.776753; + Double lon = -122.407846; + + // 1. pass only one point instead of two + Map<String, Double> latitudeOnly = hashMap("latitude", lat); + Map<String, Object> latitudeOnlyEntityData = new HashMap<String, Object>(); + latitudeOnlyEntityData.put( "location", latitudeOnly ); + + try { + node = context.collection( collectionType ).post( latitudeOnlyEntityData ); + fail("System allowed location with only one point, latitude, which it should not"); + } + catch ( UniformInterfaceException e ) { + //verify the correct error was returned + JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class )); + assertEquals( "illegal_argument", nodeError.get( "error" ).textValue() ); + } + + // 2. pass a values that are not doubles + Map<String, String> notDoubleLatLon = hashMap("latitude", "fred"); + notDoubleLatLon.put( "longitude", "barney" ); + Map<String, Object> notDoubleLatLonEntityData = new HashMap<String, Object>(); + notDoubleLatLonEntityData.put( "location", notDoubleLatLon ); + + try { + node = context.collection( collectionType ).post( notDoubleLatLonEntityData ); + fail("System allowed misspelled location values that are not doubles for latitude and longitude, which it should not"); + } + catch ( UniformInterfaceException e ) { + //verify the correct error was returned + JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class )); + assertEquals( "illegal_argument", nodeError.get( "error" ).textValue() ); + } + + + } + +}
