This is an automated email from the ASF dual-hosted git repository. amanin pushed a commit to branch refactor/sql-store in repository https://gitbox.apache.org/repos/asf/sis.git
commit 4ac566ee6df7d47425b9971d385f4e667ba07216 Author: Alexis Manin <[email protected]> AuthorDate: Wed Nov 13 15:02:40 2019 +0100 fix(SQLStore): add tests for EWKB decoding. Fix multi-polygon reading. --- pom.xml | 26 +++++++++-- storage/sis-sqlstore/pom.xml | 25 +++++++++++ .../sis/internal/sql/feature/EWKBReader.java | 16 ++----- .../apache/sis/internal/sql/feature/EWKBTest.java | 50 ++++++++++++++++++++++ .../org/apache/sis/test/suite/SQLTestSuite.java | 41 ------------------ .../org/apache/sis/test/suite/package-info.txt | 3 -- .../sis/internal/sql/feature/hexa_ewkb_4326.csv | 8 ++++ .../sis/internal/sql/feature/hexa_ewkb_4326.sql | 34 +++++++++++++++ 8 files changed, 143 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index 178c211..eb9792a 100644 --- a/pom.xml +++ b/pom.xml @@ -436,6 +436,12 @@ <artifactId>geoapi-conformance</artifactId> <version>${geoapi.version}</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> </dependency> <!-- Libraries (language, XML, network) --> @@ -523,11 +529,22 @@ Dependencies to be inherited by all modules. =========================================================== --> <dependencies> + <!-- + Unit test declaration. Embed aggregator dependency + retrocompatibility artifact ('vintage'). + The later won't be needed anymore once all JUnit tests have been upgraded to new JUnit version. + --> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>${junit.jupiter.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <version>${junit.jupiter.version}</version> + <scope>test</scope> + </dependency> </dependencies> @@ -548,6 +565,7 @@ <sis.plugin.version>${project.version}</sis.plugin.version> <sis.non-free.version>1.0-M1</sis.non-free.version> <!-- Used only if "non-free" profile is enabled. --> <geoapi.version>4.0-M11</geoapi.version> + <junit.jupiter.version>5.5.2</junit.jupiter.version> </properties> <profiles> diff --git a/storage/sis-sqlstore/pom.xml b/storage/sis-sqlstore/pom.xml index 1e905f2..22bb00f 100644 --- a/storage/sis-sqlstore/pom.xml +++ b/storage/sis-sqlstore/pom.xml @@ -92,6 +92,26 @@ </archive> </configuration> </plugin> + + + <!-- Execute individual tests instead of test suites, to allow JUnit 5 use. --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.2</version> + <configuration> + <includes> + <include>**/*Test.java</include> + </includes> + <systemProperties> + <property> + <name>derby.stream.error.file</name> + <value>${project.build.directory}/derby.log</value> + </property> + </systemProperties> + </configuration> + </plugin> + </plugins> </build> @@ -132,6 +152,11 @@ <artifactId>postgresql</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.locationtech.jts</groupId> + <artifactId>jts-core</artifactId> + <scope>compile</scope> + </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/EWKBReader.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/EWKBReader.java index 8f4bc1f..db30be2 100644 --- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/EWKBReader.java +++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/EWKBReader.java @@ -24,9 +24,8 @@ import static org.apache.sis.util.ArgumentChecks.ensureNonEmpty; * This format is the natural form returned by a query selection a geometry field * whithout using any ST_X method. * - * TODO: This format is almost equivalent to standard WKB, except that it includes SRID information. If needed, adding - * minor tweaks and flags should suffice to make it compatible with both formats. See {@link #MASK_SRID } usage for - * details. + * @implNote This format is almost equivalent to standard WKB. In fact, it should already be compatible with standard + * WKB, as the only added component by EWKB is srid, and it's hidden in geometry type using bitmask. * * @author Johann Sorel (Geomatys) * @author Alexis Manin (Geomatys) @@ -148,19 +147,12 @@ class EWKBReader { .iterator(); if (it.hasNext()) { final Object first = it.next(); - if (it.hasNext()) return factory.tryMergePolylines(first, it); - else return first; + return factory.tryMergePolylines(first, it); } throw new IllegalStateException("No geometry decoded"); } private Object readMultiPolygon() { - final int count = readCount(); - final Object[] polygons = new Object[count]; - for (int i = 0 ; i < count ; i++) { - polygons[i] = new Reader(factory, buffer).read(); - } - return factory.createMultiPolygon( IntStream.range(0, readCount()) .mapToObj(i -> new Reader(factory, buffer).read()) @@ -183,7 +175,7 @@ class EWKBReader { } private Object readPolygon() { - final int nbRings=buffer.getInt(); + final int nbRings=readCount(); final Vector outerShell = Vector.create(readCoordinateSequence()); final double[] nans = new double[dimension]; diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java new file mode 100644 index 0000000..dd27bb3 --- /dev/null +++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java @@ -0,0 +1,50 @@ +package org.apache.sis.internal.sql.feature; + +import java.nio.ByteBuffer; + +import org.opengis.referencing.crs.GeographicCRS; + +import org.apache.sis.internal.feature.Geometries; +import org.apache.sis.referencing.CommonCRS; +import org.apache.sis.setup.GeometryLibrary; +import org.apache.sis.test.TestCase; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvFileSource; + + +public class EWKBTest extends TestCase { + + public static final Geometries<?> GF = Geometries.implementation(GeometryLibrary.JTS); + + @ParameterizedTest + @CsvFileSource(resources = "hexa_ewkb_4326.csv", numLinesToSkip = 1, delimiter = '\t') + public void decodeHexadecimal(String wkt, String hexEWKB) throws Exception { + final GeographicCRS expectedCrs = CommonCRS.defaultGeographic(); + final EWKBReader reader = new EWKBReader(GF).forCrs(expectedCrs); + Assert.assertEquals("WKT and hexadecimal EWKB representation don't match", GF.parseWKT(wkt), reader.readHexa(hexEWKB)); + } + + /** + * The purpose of this test is not to check complex geometries, which is validated by above one. We just want to + * ensure that decoding directly a byte stream behaves in the same way than through hexadecimal. + */ + @Test + public void testBinary() { + final ByteBuffer point = ByteBuffer.allocate(163); + // Skip first byte: XDR mode + point.position(1); + // Create a 2D point + point.putInt(1); + point.putDouble(42.2); + point.putDouble(43.3); + + // Prepare for reading + point.position(0); + + final Object read = new EWKBReader(GeometryLibrary.JTS).read(point); + Assert.assertEquals(GF.createPoint(42.2, 43.3), read); + } +} diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/SQLTestSuite.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/SQLTestSuite.java deleted file mode 100644 index 3a24e21..0000000 --- a/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/SQLTestSuite.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.sis.test.suite; - -import org.apache.sis.test.TestSuite; -import org.junit.runners.Suite; -import org.junit.BeforeClass; - - -/** - * All tests from the {@code sis-sqlstore} module, in rough dependency order. - */ [email protected]({ - org.apache.sis.storage.sql.SQLStoreTest.class, - org.apache.sis.internal.sql.feature.FilterInterpreterTest.class -}) -public final strictfp class SQLTestSuite extends TestSuite { - /** - * Verifies the list of tests before to run the suite. - * See {@link #verifyTestList(Class, Class[])} for more information. - */ - @BeforeClass - public static void verifyTestList() { - assertNoMissingTest(SQLTestSuite.class); - verifyTestList(SQLTestSuite.class); - } -} diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/package-info.txt b/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/package-info.txt deleted file mode 100644 index ac895b5..0000000 --- a/storage/sis-sqlstore/src/test/java/org/apache/sis/test/suite/package-info.txt +++ /dev/null @@ -1,3 +0,0 @@ -Different modules provide classes in this package - be careful about collisions. -This package is initially defined by the sis-utility module, which also provides -the package-info.java file. diff --git a/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.csv b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.csv new file mode 100644 index 0000000..8593250 --- /dev/null +++ b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.csv @@ -0,0 +1,8 @@ +# This dataset has been generated using SQL script given in 'hexa_ewkb_4326.sql' in this folder, against a PostGIS 2.5.2 +wkt hexadecimal_ewkb +POINT(0 0) 0101000020E610000000000000000000000000000000000000 +LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932) 0102000020E610000003000000E44A3D0B42CA51C06EC328081E21454027BF45274BCA51C0F67B629D2A214540957CEC2E50CA51C07099D36531214540 +POLYGON((0 0,0 1,1 1,1 0,0 0)) 0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000 +POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571)) 0103000020E610000001000000050000006285C7C15ECB51C0ED88FC0DF531454028A46F245FCB51C009075EA6F731454047DED1E65DCB51C0781C510EF83145404871A7835DCB51C0EBDAEE75F53145406285C7C15ECB51C0ED88FC0DF5314540 +MULTILINESTRING((-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932),(-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307)) 0105000020E610000002000000010200000003000000E44A3D0B42CA51C06EC328081E21454027BF45274BCA51C0F67B629D2A214540957CEC2E50CA51C07099D36531214540010200000002000000FEFCFB379AC651C0C0503E9F5B284540FFDDDD4D96C651C033AC3B284F284540 +MULTIPOLYGON(((-71.1031880899493 42.3152774590236,-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307,-71.1023097974109 42.3151969047397,-71.1019285062273 42.3147384934248,-71.102505233663 42.3144722937587,-71.10277487471 42.3141658254797,-71.103113945163 42.3142739188902,-71.10324876416 42.31402489987,-71.1033002961013 42.3140393340215,-71.1033488797549 42.3139495090772,-71.103396240451 42.3138632439557,-71.1041521907712 42.3141153348029,-71.1041411411543 42.31415450145 [...] diff --git a/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.sql b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.sql new file mode 100644 index 0000000..515d76a --- /dev/null +++ b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/feature/hexa_ewkb_4326.sql @@ -0,0 +1,34 @@ +SELECT wkt, ST_GeomFromText(wkt, 4326) AS hexadecimal_ewkb +FROM ( + VALUES ('POINT(0 0)'), + ('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)'), + ('POLYGON((0 0,0 1,1 1,1 0,0 0))'), + ('POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,' || + '-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,' || + '-71.1776585052917 42.3902909739571))'), + ('MULTILINESTRING((-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932),' || + '(-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307))'), + ('MULTIPOLYGON(((-71.1031880899493 42.3152774590236,' || + '-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307,' || + '-71.1023097974109 42.3151969047397,-71.1019285062273 42.3147384934248,' || + '-71.102505233663 42.3144722937587,-71.10277487471 42.3141658254797,' || + '-71.103113945163 42.3142739188902,-71.10324876416 42.31402489987,' || + '-71.1033002961013 42.3140393340215,-71.1033488797549 42.3139495090772,' || + '-71.103396240451 42.3138632439557,-71.1041521907712 42.3141153348029,' || + '-71.1041411411543 42.3141545014533,-71.1041287795912 42.3142114839058,' || + '-71.1041188134329 42.3142693656241,-71.1041112482575 42.3143272556118,' || + '-71.1041072845732 42.3143851580048,-71.1041057218871 42.3144430686681,' || + '-71.1041065602059 42.3145009876017,-71.1041097995362 42.3145589148055,' || + '-71.1041166403905 42.3146168544148,-71.1041258822717 42.3146748022936,' || + '-71.1041375307579 42.3147318674446,-71.1041492906949 42.3147711126569,' || + '-71.1041598612795 42.314808571739,-71.1042515013869 42.3151287620809,' || + '-71.1041173835118 42.3150739481917,-71.1040809891419 42.3151344119048,' || + '-71.1040438678912 42.3151191367447,-71.1040194562988 42.3151832057859,' || + '-71.1038734225584 42.3151140942995,-71.1038446938243 42.3151006300338,' || + '-71.1038315271889 42.315094347535,-71.1037393329282 42.315054824985,' || + '-71.1035447555574 42.3152608696313,-71.1033436658644 42.3151648370544,' || + '-71.1032580383161 42.3152269126061,-71.103223066939 42.3152517403219,' || + '-71.1031880899493 42.3152774590236)),' || + '((-71.1043632495873 42.315113108546,-71.1043583974082 42.3151211109857,' || + '-71.1043443253471 42.3150676015829,-71.1043850704575 42.3150793250568,-71.1043632495873 42.315113108546)))') + ) AS WKTS (wkt) \ No newline at end of file
