@Test public void testEvaluateCastFromInvalidString() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cannot convert \"POINTE ()\" to geo_shape"); ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.STRING); fn.evaluate(Literal.newLiteral(DataTypes.STRING, INVALID_STR)); }
@Test public void testEvaluateCastFromInvalidObject() throws Exception { ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.OBJECT); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(allOf(startsWith("Cannot convert"), endsWith("to geo_shape"))); fn.evaluate(Literal.newLiteral(DataTypes.OBJECT, INVALID_OBJECT)); }
@Test public void testEvaluateCastFromString() throws Exception { ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.STRING); Object val = fn.evaluate(Literal.newLiteral(DataTypes.STRING, VALID_STR)); assertThat(val, instanceOf(Map.class)); assertThat( (Map<String, Object>) val, allOf( hasEntry("type", (Object) "Point"), hasEntry("coordinates", (Object) new double[] {0.0, 0.1}))); }
@Test public void testEvaluateCastFromObject() throws Exception { ToGeoFunction fn = getFunction(FUNCTION_NAME, DataTypes.OBJECT); Object val = fn.evaluate(Literal.newLiteral(DataTypes.OBJECT, VALID_OBJECT)); assertThat(val, instanceOf(Map.class)); Map<String, Object> valMap = (Map<String, Object>) val; assertThat(valMap.size(), is(2)); assertThat( valMap, Matchers.allOf( Matchers.<String, Object>hasEntry("type", "Polygon"), Matchers.hasEntry("coordinates", VALID_OBJECT.get("coordinates")))); }