sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] branch feat/geojson updated: GeoJson : reuse FeatureComparator in tests
Date Wed, 15 Apr 2020 10:03:29 GMT
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 <johann.sorel@geomatys.com>
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<? extends FeatureType> super1 = type1.getSuperTypes();
-        final Set<? extends FeatureType> super2 = type2.getSuperTypes();
-        if(super1.size() != super2.size()) return false;
-        final Iterator<? extends FeatureType> site1 = super1.iterator();
-        final Iterator<? extends FeatureType> site2 = super2.iterator();
-        while(site1.hasNext()){
-            if(!equalsIgnoreConvention(site1.next(), site2.next())) return false;
-        }
-
-        //check properties
-        final Set<GenericName> 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();
     }
 }


Mime
View raw message