|
17 | 17 |
|
18 | 18 | import java.io.IOException; |
19 | 19 | import java.text.ParseException; |
| 20 | +import java.util.List; |
20 | 21 |
|
21 | 22 | public class PointTests extends BaseGeometryTestCase<Point> { |
22 | 23 | @Override |
@@ -58,6 +59,52 @@ public void testWKTValidation() { |
58 | 59 | assertEquals("found Z value [100.0] but [ignore_z_value] parameter is [false]", ex.getMessage()); |
59 | 60 | } |
60 | 61 |
|
| 62 | + public void testParsePointZWithThreeCoordinates() throws IOException, ParseException { |
| 63 | + GeometryValidator validator = GeographyValidator.instance(true); |
| 64 | + assertEquals(new Point(20, 10, 100), WellKnownText.fromWKT(validator, true, "POINT Z (20.0 10.0 100.0)")); |
| 65 | + } |
| 66 | + |
| 67 | + public void testParsePointMWithThreeCoordinates() throws IOException, ParseException { |
| 68 | + GeometryValidator validator = GeographyValidator.instance(true); |
| 69 | + assertEquals(new Point(20, 10, 100), WellKnownText.fromWKT(validator, true, "POINT M (20.0 10.0 100.0)")); |
| 70 | + } |
| 71 | + |
| 72 | + public void testParsePointZWithTwoCoordinatesThrowsException() { |
| 73 | + GeometryValidator validator = GeographyValidator.instance(true); |
| 74 | + ParseException ex = expectThrows(ParseException.class, () -> WellKnownText.fromWKT(validator, true, "POINT Z (20.0 10.0)")); |
| 75 | + assertEquals("'POINT Z' or 'POINT M' must have three coordinates, but only two were found.", ex.getMessage()); |
| 76 | + } |
| 77 | + |
| 78 | + public void testParsePointMWithTwoCoordinatesThrowsException() { |
| 79 | + GeometryValidator validator = StandardValidator.instance(true); |
| 80 | + ParseException ex = expectThrows(ParseException.class, () -> WellKnownText.fromWKT(validator, true, "POINT M (20.0 10.0)")); |
| 81 | + assertEquals("'POINT Z' or 'POINT M' must have three coordinates, but only two were found.", ex.getMessage()); |
| 82 | + } |
| 83 | + |
| 84 | + public void testParsePointZMFormatNotSupported() { |
| 85 | + GeometryValidator validator = StandardValidator.instance(true); |
| 86 | + List<String> points = List.of("POINT ZM (20.0 10.0 100.0 200.0)", "POINT ZM (20.0 10.0 100.0)", "POINT ZM (20.0 10.0)"); |
| 87 | + for (String point : points) { |
| 88 | + ParseException ex = expectThrows(ParseException.class, () -> WellKnownText.fromWKT(validator, true, point)); |
| 89 | + assertEquals("expected ( or Z or M but found: ZM", ex.getMessage()); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + public void testParsePointZWithEmpty() { |
| 94 | + GeometryValidator validator = StandardValidator.instance(true); |
| 95 | + ParseException ex = expectThrows(ParseException.class, () -> WellKnownText.fromWKT(validator, true, "POINT Z EMPTY")); |
| 96 | + assertEquals("expected ( but found: EMPTY", ex.getMessage()); |
| 97 | + } |
| 98 | + |
| 99 | + public void testParsePointZOrMWithTwoCoordinates() { |
| 100 | + GeometryValidator validator = StandardValidator.instance(true); |
| 101 | + List<String> points = List.of("POINT Z (20.0 10.0)", "POINT M (20.0 10.0)"); |
| 102 | + for (String point : points) { |
| 103 | + ParseException ex = expectThrows(ParseException.class, () -> WellKnownText.fromWKT(validator, true, point)); |
| 104 | + assertEquals("'POINT Z' or 'POINT M' must have three coordinates, but only two were found.", ex.getMessage()); |
| 105 | + } |
| 106 | + } |
| 107 | + |
61 | 108 | @Override |
62 | 109 | protected Point mutateInstance(Point instance) { |
63 | 110 | return null;// TODO implement https://github.com/elastic/elasticsearch/issues/25929 |
|
0 commit comments