Ngsi2ParsingHelper { public static GeoQuery parseGeoQuery(String georel, String geometry, String coords) { String[] georelFields = georel.split(";"); GeoQuery.Relation relation; try { relation = GeoQuery.Relation.valueOf(georelFields[0]); } catch (IllegalArgumentException e) { throw new InvalidatedSyntaxException(georelFields[0]); } if (relation == GeoQuery.Relation.near && georelFields.length > 1) { String[] modifierFields = georelFields[1].split(":"); if (modifierFields.length != 2) { throw new InvalidatedSyntaxException(georelFields[1]); } try { return new GeoQuery(GeoQuery.Modifier.valueOf(modifierFields[0]), Float.parseFloat(modifierFields[1]), parseGeometry(geometry), parseCoordinates(coords)); } catch (IllegalArgumentException e) { throw new InvalidatedSyntaxException(georelFields[1]); } } return new GeoQuery(relation, parseGeometry(geometry), parseCoordinates(coords)); }  static Object parseTextValue(String value); static GeoQuery parseGeoQuery(String georel, String geometry, String coords); static GeoQuery.Geometry parseGeometry(String geometry); static List<Coordinate> parseCoordinates(String stringCoord);  }
@Test public void testParseGeoQuery() { GeoQuery geoQuery = Ngsi2ParsingHelper.parseGeoQuery("near;minDistance:23.3", "point", "12.3,14.2"); assertEquals(GeoQuery.Relation.near, geoQuery.getRelation()); assertEquals(GeoQuery.Modifier.minDistance, geoQuery.getModifier()); assertEquals(23.3, geoQuery.getDistance(), 0.1); assertEquals(GeoQuery.Geometry.point, geoQuery.getGeometry()); assertEquals(1, geoQuery.getCoordinates().size()); assertEquals(12.3, geoQuery.getCoordinates().get(0).getLatitude(), 0.1); assertEquals(14.2, geoQuery.getCoordinates().get(0).getLongitude(), 0.1); }
@Test public void testParseGeometryRelations() { assertEquals(GeoQuery.Relation.disjoint, Ngsi2ParsingHelper.parseGeoQuery("disjoint", "point", "12.3,14.2").getRelation()); assertEquals(GeoQuery.Relation.coveredBy, Ngsi2ParsingHelper.parseGeoQuery("coveredBy", "point", "12.3,14.2").getRelation()); assertEquals(GeoQuery.Relation.intersects, Ngsi2ParsingHelper.parseGeoQuery("intersects", "point", "12.3,14.2").getRelation()); assertEquals(GeoQuery.Relation.equals, Ngsi2ParsingHelper.parseGeoQuery("equals", "point", "12.3,14.2").getRelation()); }
@Test public void testParseGeometryModifiers() { assertEquals(GeoQuery.Modifier.maxDistance, Ngsi2ParsingHelper.parseGeoQuery("near;maxDistance:23.3", "point", "12.3,14.2").getModifier()); assertEquals(GeoQuery.Modifier.minDistance, Ngsi2ParsingHelper.parseGeoQuery("near;minDistance:23.3", "point", "12.3,14.2").getModifier()); }
@Test(expected = InvalidatedSyntaxException.class) public void testParseGeometryBadModifier() { Ngsi2ParsingHelper.parseGeoQuery("near;badModifier:23.3", "point", "12.3,14.2"); }