From commits-return-13474-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Wed Apr 15 10:03:30 2020 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 425671967F for ; Wed, 15 Apr 2020 10:03:30 +0000 (UTC) Received: (qmail 52143 invoked by uid 500); 15 Apr 2020 10:03:29 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 52114 invoked by uid 500); 15 Apr 2020 10:03:29 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 52105 invoked by uid 99); 15 Apr 2020 10:03:29 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2020 10:03:29 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 60E7C8B6AA; Wed, 15 Apr 2020 10:03:29 +0000 (UTC) Date: Wed, 15 Apr 2020 10:03:29 +0000 To: "commits@sis.apache.org" Subject: [sis] branch feat/geojson updated: GeoJson : reuse FeatureComparator in tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <158694500934.17258.3784192411342890222@gitbox.apache.org> From: jsorel@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sis X-Git-Refname: refs/heads/feat/geojson X-Git-Reftype: branch X-Git-Oldrev: 979f433ebed7399206021223f43716418f06bb6f X-Git-Newrev: 6c65e3d846a24cc3e170c0312f2c2548cc6c2971 X-Git-Rev: 6c65e3d846a24cc3e170c0312f2c2548cc6c2971 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. jsorel pushed a commit to branch feat/geojson in repository https://gitbox.apache.org/repos/asf/sis.git The following commit(s) were added to refs/heads/feat/geojson by this push: new 6c65e3d GeoJson : reuse FeatureComparator in tests 6c65e3d is described below commit 6c65e3d846a24cc3e170c0312f2c2548cc6c2971 Author: jsorel AuthorDate: Wed Apr 15 12:02:54 2020 +0200 GeoJson : reuse FeatureComparator in tests --- .../apache/sis/storage/geojson/GeoJSONStore.java | 6 +- .../storage/geojson/FeatureTypeUtilsTest.java | 109 +++------------------ .../internal/storage/geojson/GeoJSONReadTest.java | 24 ++--- 3 files changed, 25 insertions(+), 114 deletions(-) diff --git a/storage/sis-geojson/src/main/java/org/apache/sis/storage/geojson/GeoJSONStore.java b/storage/sis-geojson/src/main/java/org/apache/sis/storage/geojson/GeoJSONStore.java index 515b7c2..b8a5ed7 100644 --- a/storage/sis-geojson/src/main/java/org/apache/sis/storage/geojson/GeoJSONStore.java +++ b/storage/sis-geojson/src/main/java/org/apache/sis/storage/geojson/GeoJSONStore.java @@ -34,6 +34,9 @@ import java.util.stream.StreamSupport; import org.apache.sis.feature.builder.AttributeRole; import org.apache.sis.feature.builder.AttributeTypeBuilder; import org.apache.sis.feature.builder.FeatureTypeBuilder; +import org.apache.sis.internal.geojson.FeatureTypeUtils; +import org.apache.sis.internal.geojson.GeoJSONParser; +import org.apache.sis.internal.geojson.GeoJSONUtils; import org.apache.sis.internal.geojson.binding.GeoJSONFeature; import org.apache.sis.internal.geojson.binding.GeoJSONFeatureCollection; import org.apache.sis.internal.geojson.binding.GeoJSONGeometry; @@ -53,9 +56,6 @@ import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.DataStoreProvider; import org.apache.sis.storage.WritableFeatureSet; import static org.apache.sis.storage.geojson.GeoJSONProvider.*; -import org.apache.sis.internal.geojson.FeatureTypeUtils; -import org.apache.sis.internal.geojson.GeoJSONParser; -import org.apache.sis.internal.geojson.GeoJSONUtils; import org.apache.sis.util.iso.Names; import org.apache.sis.util.logging.Logging; import org.locationtech.jts.geom.*; diff --git a/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/FeatureTypeUtilsTest.java b/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/FeatureTypeUtilsTest.java index 61fe1c7..a2c2255 100644 --- a/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/FeatureTypeUtilsTest.java +++ b/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/FeatureTypeUtilsTest.java @@ -16,32 +16,25 @@ */ package org.apache.sis.internal.storage.geojson; -import org.locationtech.jts.geom.Point; -import org.locationtech.jts.geom.Polygon; -import org.apache.sis.referencing.CommonCRS; -import org.apache.sis.util.iso.SimpleInternationalString; -import org.junit.Test; -import org.opengis.util.FactoryException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Objects; -import java.util.Set; +import org.apache.sis.feature.FeatureComparator; import org.apache.sis.feature.builder.AttributeRole; import org.apache.sis.feature.builder.FeatureTypeBuilder; import org.apache.sis.internal.feature.AttributeConvention; import org.apache.sis.internal.geojson.FeatureTypeUtils; import org.apache.sis.internal.geojson.GeoJSONUtils; +import org.apache.sis.referencing.CommonCRS; import org.apache.sis.test.TestCase; - +import org.apache.sis.util.iso.SimpleInternationalString; import static org.junit.Assert.*; -import org.opengis.feature.FeatureAssociationRole; +import org.junit.Test; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.Polygon; import org.opengis.feature.FeatureType; -import org.opengis.feature.PropertyNotFoundException; import org.opengis.feature.PropertyType; -import org.opengis.util.GenericName; +import org.opengis.util.FactoryException; /** * @author Quentin Boileau (Geomatys) @@ -168,7 +161,7 @@ public class FeatureTypeUtilsTest extends TestCase { * @param type * @return true if type has a geometry. */ - public static boolean hasAGeometry(FeatureType type){ + public static boolean hasAGeometry(FeatureType type) { for (PropertyType pt : type.getProperties(true)){ if (AttributeConvention.isGeometryAttribute(pt)) return true; } @@ -179,87 +172,11 @@ public class FeatureTypeUtilsTest extends TestCase { /** * Test field equality ignoring convention properties. */ - public static boolean equalsIgnoreConvention(FeatureType type1, FeatureType type2){ - - if (type1 == type2) { - return true; - } - - //check base properties - if (!Objects.equals(type1.getName(), type2.getName()) || - !Objects.equals(type1.getDefinition(), type2.getDefinition()) || - !Objects.equals(type1.getDesignation(), type2.getDesignation()) || - !Objects.equals(type1.getDesignation(), type2.getDesignation()) || - !Objects.equals(type1.isAbstract(), type2.isAbstract())){ - return false; - } - - //check super types - final Set super1 = type1.getSuperTypes(); - final Set super2 = type2.getSuperTypes(); - if(super1.size() != super2.size()) return false; - final Iterator site1 = super1.iterator(); - final Iterator site2 = super2.iterator(); - while(site1.hasNext()){ - if(!equalsIgnoreConvention(site1.next(), site2.next())) return false; - } - - //check properties - final Set visited = new HashSet<>(); - for (PropertyType pt1 : type1.getProperties(true)) { - visited.add(pt1.getName()); - if (AttributeConvention.contains(pt1.getName())) continue; - try { - final PropertyType pt2 = type2.getProperty(pt1.getName().toString()); - if (!equalsIgnoreConvention(pt1, pt2)) return false; - } catch (PropertyNotFoundException ex) { - return false; - } - } - - for (PropertyType pt2 : type2.getProperties(true)) { - if (AttributeConvention.contains(pt2.getName()) || visited.contains(pt2.getName())) continue; - try { - final PropertyType pt1 = type1.getProperty(pt2.getName().toString()); - if (!equalsIgnoreConvention(pt1, pt2)) return false; - } catch (PropertyNotFoundException ex) { - return false; - } - } - - return true; - } - - private static boolean equalsIgnoreConvention(PropertyType pt1, PropertyType pt2){ - if(pt1 instanceof FeatureAssociationRole){ - if(pt2 instanceof FeatureAssociationRole){ - final FeatureAssociationRole far1 = (FeatureAssociationRole) pt1; - final FeatureAssociationRole far2 = (FeatureAssociationRole) pt2; - - //check base properties - if (!Objects.equals(far1.getName(), far2.getName()) || - !Objects.equals(far1.getDefinition(), far2.getDefinition()) || - !Objects.equals(far1.getDesignation(), far2.getDesignation()) || - !Objects.equals(far1.getDesignation(), far2.getDesignation())){ - return false; - } - - if(far1.getMinimumOccurs()!=far2.getMinimumOccurs()|| - far1.getMaximumOccurs()!=far2.getMaximumOccurs()){ - return false; - } - - if(!equalsIgnoreConvention(far1.getValueType(), far2.getValueType())){ - return false; - } - - }else{ - return false; - } - }else if(!pt1.equals(pt2)){ - return false; - } - return true; + public static void equalsIgnoreConvention(FeatureType type1, FeatureType type2) { + final FeatureComparator comparator = new FeatureComparator(type1, type2); + comparator.ignoredProperties.add(AttributeConvention.IDENTIFIER); + comparator.ignoredProperties.add("identifier"); + comparator.compare(); } } diff --git a/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/GeoJSONReadTest.java b/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/GeoJSONReadTest.java index ee65118..8868e52 100644 --- a/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/GeoJSONReadTest.java +++ b/storage/sis-geojson/src/test/java/org/apache/sis/internal/storage/geojson/GeoJSONReadTest.java @@ -22,25 +22,23 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Iterator; +import org.apache.sis.feature.FeatureComparator; import org.apache.sis.feature.builder.AttributeRole; import org.apache.sis.feature.builder.FeatureTypeBuilder; -import org.apache.sis.internal.feature.AttributeConvention; +import org.apache.sis.internal.geojson.GeoJSONParser; +import org.apache.sis.internal.geojson.binding.GeoJSONFeatureCollection; +import org.apache.sis.internal.geojson.binding.GeoJSONObject; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.DataStores; -import org.apache.sis.internal.geojson.binding.GeoJSONFeatureCollection; -import org.apache.sis.internal.geojson.binding.GeoJSONObject; -import org.apache.sis.internal.geojson.GeoJSONParser; import org.apache.sis.storage.WritableFeatureSet; import org.apache.sis.test.TestCase; import org.apache.sis.util.iso.Names; import static org.junit.Assert.*; import org.junit.Test; import org.locationtech.jts.geom.*; -import org.opengis.feature.AttributeType; import org.opengis.feature.Feature; import org.opengis.feature.FeatureType; -import org.opengis.feature.PropertyType; import org.opengis.util.GenericName; /** @@ -310,14 +308,15 @@ public class GeoJSONReadTest extends TestCase { final FeatureTypeBuilder ftb = new FeatureTypeBuilder(); ftb.setName(name); ftb.addAttribute(Double[][].class).setName("array"); - ftb.addAttribute(geomClass).setName(AttributeConvention.GEOMETRY_PROPERTY).setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY); + ftb.addAttribute(geomClass).setName("geometry").setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY); return ftb.build(); } private FeatureType buildGeometryFeatureType(String name, Class geomClass) { final FeatureTypeBuilder ftb = new FeatureTypeBuilder(); ftb.setName(name); - ftb.addAttribute(geomClass).setName(AttributeConvention.GEOMETRY_PROPERTY).setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY); + ftb.addAttribute(String.class).setName("fid").addRole(AttributeRole.IDENTIFIER_COMPONENT); + ftb.addAttribute(geomClass).setName("geometry").setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY); return ftb.build(); } @@ -339,12 +338,7 @@ public class GeoJSONReadTest extends TestCase { } private void testFeatureTypes(FeatureType expected, FeatureType result) { - for(PropertyType desc : expected.getProperties(true)){ - PropertyType td = result.getProperty(desc.getName().toString()); - assertNotNull(td); - if(td instanceof AttributeType){ - assertEquals(((AttributeType) td).getValueClass(), ((AttributeType)desc).getValueClass()); - } - } + final FeatureComparator comparator = new FeatureComparator(expected, result); + comparator.compare(); } }