sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1596317 - in /sis/branches/JDK8/core/sis-feature/src: main/java/org/apache/sis/feature/ test/java/org/apache/sis/feature/ test/java/org/apache/sis/test/suite/
Date Tue, 20 May 2014 17:07:27 GMT
Author: desruisseaux
Date: Tue May 20 17:07:26 2014
New Revision: 1596317

URL: http://svn.apache.org/r1596317
Log:
More tests.

Added:
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/SparseFeatureTest.java
      - copied, changed from r1595945, sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -394,6 +394,14 @@ public class DefaultFeatureType extends 
     }
 
     /**
+     * Returns {@code true} if the feature instances are expected to have lot of unset properties,
+     * or {@code false} if we expect most properties to be specified.
+     */
+    final boolean isSparse() {
+        return isSparse;
+    }
+
+    /**
      * Returns {@code true} if this feature type contains only attributes constrained to
the [1 … 1] cardinality,
      * or operations. Such feature types can be handled as a {@link org.opengis.util.Record}s.
      *

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -97,9 +97,11 @@ final class DenseFeature extends Abstrac
         ArgumentChecks.ensureNonNull("name", name);
         final int index = getIndex(name);
         if (properties instanceof Property[]) {
-            return ((Property[]) properties)[index];
-        }
-        if (properties == null) {
+            final Property property = ((Property[]) properties)[index];
+            if (property != null) {
+                return property;
+            }
+        } else if (properties == null) {
             properties = new Property[indices.size()];
         } else {
             wrapValuesInProperties();

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -191,6 +191,7 @@ public final strictfp class DefaultFeatu
         assertEquals("name", "City",     simple.getName().toString());
         assertTrue  ("superTypes",       simple.getSuperTypes().isEmpty());
         assertFalse ("isAbstract",       simple.isAbstract());
+        assertFalse ("isSparse",         simple.isSparse());
         assertTrue  ("isSimple",         simple.isSimple());
         assertTrue  ("isAssignableFrom", simple.isAssignableFrom(simple));
         assertEquals("instanceSize", 2,  simple.indices().size());
@@ -239,6 +240,7 @@ public final strictfp class DefaultFeatu
         assertTrue  ("superTypes",                                      complex.getSuperTypes().isEmpty());
         assertTrue  ("isAssignableFrom",                                complex.isAssignableFrom(complex));
         assertFalse ("isAbstract",                                      complex.isAbstract());
+        assertFalse ("isSparse",                                        complex.isSparse());
         assertEquals("isSimple",        maximumOccurs == minimumOccurs, complex.isSimple());
         assertEquals("instanceSize",    maximumOccurs == 0 ? 2 : 3,     complex.indices().size());
         assertEquals("minimumOccurs",   minimumOccurs,                  festival.getMinimumOccurs());
@@ -288,6 +290,7 @@ public final strictfp class DefaultFeatu
         assertEquals("name", "Capital", capital.getName().toString());
         assertEquals("superTypes",      city, getSingleton(capital.getSuperTypes()));
         assertFalse ("isAbstract",      capital.isAbstract());
+        assertFalse ("isSparse",        capital.isSparse());
         assertTrue  ("isSimple",        capital.isSimple());
         assertEquals("instanceSize", 3, capital.indices().size());
 
@@ -322,6 +325,7 @@ public final strictfp class DefaultFeatu
         assertEquals     ("name", "Metropolis and capital", metroCapital.getName().toString());
         assertArrayEquals("superTypes", new Object[] {metropolis, capital}, metroCapital.getSuperTypes().toArray());
         assertFalse      ("isAbstract",      metroCapital.isAbstract());
+        assertFalse      ("isSparse",        metroCapital.isSparse());
         assertTrue       ("isSimple",        metroCapital.isSimple());
         assertEquals     ("instanceSize", 6, metroCapital.indices().size());
 
@@ -363,6 +367,7 @@ public final strictfp class DefaultFeatu
         assertEquals     ("name", "World metropolis", worldMetropolis.getName().toString());
         assertArrayEquals("superTypes", new Object[] {metropolis}, worldMetropolis.getSuperTypes().toArray());
         assertFalse      ("isAbstract",      worldMetropolis.isAbstract());
+        assertFalse      ("isSparse",        worldMetropolis.isSparse());
         assertTrue       ("isSimple",        worldMetropolis.isSimple());
         assertEquals     ("instanceSize", 4, worldMetropolis.indices().size());
 

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -33,4 +33,13 @@ import org.apache.sis.test.DependsOn;
     PropertySingletonTest.class
 })
 public final strictfp class DenseFeatureTest extends FeatureTestCase {
+    /**
+     * Creates a new feature for the given type.
+     */
+    @Override
+    final AbstractFeature createFeature(final DefaultFeatureType type) {
+        return new DenseFeature(type);
+    }
+
+    // Inherit all tests from the super-class.
 }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -17,8 +17,10 @@
 package org.apache.sis.feature;
 
 import java.util.Locale;
+import java.util.Random;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
+import org.apache.sis.test.TestUtilities;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
@@ -58,7 +60,8 @@ public final strictfp class FeatureForma
      */
     @Test
     public void testFeature() {
-        final AbstractFeature feature = FeatureTestCase.twinTown();
+        final Random random = TestUtilities.createRandomNumberGenerator();
+        final AbstractFeature feature = FeatureTestCase.twinTown(random.nextBoolean());
         final FeatureFormat format = new FeatureFormat(Locale.US, null);
         final String text = format.format(feature);
         assertMultilinesEquals("Twin town\n" +

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -16,10 +16,11 @@
  */
 package org.apache.sis.feature;
 
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.test.Assert.*;
 import static java.util.Collections.singletonMap;
 
 
@@ -31,22 +32,39 @@ import static java.util.Collections.sing
  * @version 0.5
  * @module
  */
-strictfp class FeatureTestCase extends TestCase {
+abstract strictfp class FeatureTestCase extends TestCase {
+    /**
+     * The feature being tested.
+     */
+    private AbstractFeature feature;
+
+    /**
+     * {@code true} if {@link #getAttributeValue(String)} should invoke {@link AbstractFeature#getProperty(String)},
+     * or {@code false} for invoking directly {@link AbstractFeature#getPropertyValue(String)}.
+     */
+    private boolean getValuesFromProperty;
+
+    /**
+     * For sub-class constructors only.
+     */
+    FeatureTestCase() {
+    }
+
     /**
      * Creates a feature for twin towns.
      */
-    static AbstractFeature twinTown() {
+    static AbstractFeature twinTown(final boolean isSparse) {
         final DefaultAssociationRole twinTown = DefaultAssociationRoleTest.twinTown();
         final DefaultFeatureType     city     = twinTown.getValueType();
         final DefaultFeatureType     type     = new DefaultFeatureType(
                 singletonMap(DefaultFeatureType.NAME_KEY, "Twin town"), false,
                 new DefaultFeatureType[] {city}, twinTown);
 
-        final AbstractFeature leMans = new DenseFeature(type);
+        final AbstractFeature leMans = isSparse ? new SparseFeature(type) : new DenseFeature(type);
         leMans.setPropertyValue("city", "Le Mans");
         leMans.setPropertyValue("population", 143240); // In 2011.
 
-        final AbstractFeature paderborn = new DenseFeature(type);
+        final AbstractFeature paderborn = isSparse ? new SparseFeature(type) : new DenseFeature(type);
         paderborn.setPropertyValue("city", "Paderborn");
         paderborn.setPropertyValue("population", 143174); // December 31th, 2011
         paderborn.setPropertyValue("twin town", leMans);
@@ -54,18 +72,54 @@ strictfp class FeatureTestCase extends T
     }
 
     /**
-     * Tests the construction of a simple feature without super-types.
+     * Creates a new feature for the given type.
+     */
+    abstract AbstractFeature createFeature(final DefaultFeatureType type);
+
+    /**
+     * Returns the attribute value of the current {@link #feature} for the given name.
+     */
+    private Object getAttributeValue(final String name) {
+        final Object value = feature.getPropertyValue(name);
+        if (getValuesFromProperty) {
+            final Property property = (Property) feature.getProperty(name);
+            assertInstanceOf(name, DefaultAttribute.class, property);
+
+            // The AttributeType shall be the same than the one provided by FeatureType for
the given name.
+            assertSame(name, feature.getType().getProperty(name), ((DefaultAttribute<?>)
property).getType());
+
+            // Attribute value shall be the same than the one provided by FeatureType convenience
method.
+            assertSame(name, feature.getPropertyValue(name), ((DefaultAttribute<?>)
property).getValue());
+
+            // Invoking getProperty(name) twice shall return the same Property instance.
+            assertSame(name, property, feature.getProperty(name));
+        }
+        return value;
+    }
+
+    /**
+     * Tests the {@link AbstractFeature#getPropertyValue(String)} method on a simple feature
without super-types.
      */
     @Test
-    public void testSimple() {
-        final AbstractFeature cityPopulation = new DenseFeature(DefaultFeatureTypeTest.city());
+    public void testSimpleValues() {
+        feature = createFeature(DefaultFeatureTypeTest.city());
 
-        assertEquals("Utopia", cityPopulation.getPropertyValue("city"));
-        cityPopulation.setPropertyValue("city", "Atlantide");
-        assertEquals("Atlantide", cityPopulation.getPropertyValue("city"));
-
-        assertNull(cityPopulation.getPropertyValue("population"));
-        cityPopulation.setPropertyValue("population", 1000);
-        assertEquals(1000, cityPopulation.getPropertyValue("population"));
+        assertEquals("Utopia", getAttributeValue("city"));
+        feature.setPropertyValue("city", "Atlantide");
+        assertEquals("Atlantide", feature.getPropertyValue("city"));
+
+        assertNull(getAttributeValue("population"));
+        feature.setPropertyValue("population", 1000);
+        assertEquals(1000, getAttributeValue("population"));
+    }
+
+    /**
+     * Tests the {@link AbstractFeature#getProperty(String)} method on a simple feature without
super-types.
+     */
+    @Test
+    @DependsOnMethod("testSimpleValues")
+    public void testSimpleProperties() {
+        getValuesFromProperty = true;
+        testSimpleValues();
     }
 }

Copied: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/SparseFeatureTest.java
(from r1595945, sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/SparseFeatureTest.java?p2=sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/SparseFeatureTest.java&p1=sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java&r1=1595945&r2=1596317&rev=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DenseFeatureTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/SparseFeatureTest.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -20,7 +20,7 @@ import org.apache.sis.test.DependsOn;
 
 
 /**
- * Tests {@link DenseFeature}.
+ * Tests {@link SparseFeature}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
@@ -32,5 +32,14 @@ import org.apache.sis.test.DependsOn;
     DefaultAttributeTest.class,
     PropertySingletonTest.class
 })
-public final strictfp class DenseFeatureTest extends FeatureTestCase {
+public final strictfp class SparseFeatureTest extends FeatureTestCase {
+    /**
+     * Creates a new feature for the given type.
+     */
+    @Override
+    final AbstractFeature createFeature(final DefaultFeatureType type) {
+        return new SparseFeature(type);
+    }
+
+    // Inherit all tests from the super-class.
 }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java?rev=1596317&r1=1596316&r2=1596317&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] Tue May 20 17:07:26 2014
@@ -35,6 +35,7 @@ import org.junit.BeforeClass;
     org.apache.sis.feature.DefaultAttributeTest.class,
     org.apache.sis.feature.PropertySingletonTest.class,
     org.apache.sis.feature.DenseFeatureTest.class,
+    org.apache.sis.feature.SparseFeatureTest.class,
     org.apache.sis.feature.DefaultAssociationRoleTest.class,
     org.apache.sis.feature.DefaultAssociationTest.class,
     org.apache.sis.feature.DefaultOperationTest.class,



Mime
View raw message