sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1593858 - 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 Sun, 11 May 2014 20:44:21 GMT
Author: desruisseaux
Date: Sun May 11 20:44:20 2014
New Revision: 1593858

URL: http://svn.apache.org/r1593858
Log:
Added basic tests for Feature Associations.

Added:
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
  (with props)
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.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/test/suite/FeatureTestSuite.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java?rev=1593858&r1=1593857&r2=1593858&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
[UTF-8] Sun May 11 20:44:20 2014
@@ -19,6 +19,7 @@ package org.apache.sis.feature;
 import java.io.Serializable;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.resources.Errors;
 
 // Related to JDK7
 import java.util.Objects;
@@ -106,15 +107,41 @@ public class DefaultAssociation extends 
      * <div class="warning"><b>Warning:</b> In a future SIS version, the
argument type may be changed
      * to {@code org.opengis.feature.Feature}. This change is pending GeoAPI revision.</div>
      *
-     * @param  value The new value.
+     * @param  value The new value, or {@code null}.
+     * @throws RuntimeException If this method performs validation and the given value does
not meet the conditions.
+     *         <span style="color:firebrick">This exception may be changed to {@code
IllegalPropertyException} in a
+     *         future SIS version.</span>
      *
      * @see DefaultFeature#setPropertyValue(String, Object)
      */
     public void setValue(final DefaultFeature value) {
+        if (value != null) {
+            final DefaultFeatureType base = role.getValueType();
+            final DefaultFeatureType type = value.getType();
+            if (!base.equals(type) && !isAssignableFrom(base, type.superTypes()))
{
+                throw new RuntimeException( // TODO: IllegalPropertyException, pending GeoAPI
revision.
+                        Errors.format(Errors.Keys.IllegalArgumentClass_3, role.getName(),
base.getName(), type.getName()));
+            }
+        }
         this.value = value;
     }
 
     /**
+     * Returns {@code true} if the given {@code base} is assignable from any of the given
types.
+     */
+    private static boolean isAssignableFrom(final DefaultFeatureType base, final Iterable<DefaultFeatureType>
types) {
+        for (final DefaultFeatureType type : types) {
+            if (base.equals(type)) {
+                return true;
+            }
+            if (isAssignableFrom(base, type.superTypes())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
      * Returns a shallow copy of this association.
      * The association {@linkplain #getValue() value} is <strong>not</strong>
cloned.
      *

Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java?rev=1593858&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
[UTF-8] Sun May 11 20:44:20 2014
@@ -0,0 +1,52 @@
+/*
+ * 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.feature;
+
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static java.util.Collections.singletonMap;
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultAssociationRole}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+@DependsOn(DefaultFeatureTypeTest.class)
+public final strictfp class DefaultAssociationRoleTest extends TestCase {
+    /**
+     * Creates an association.
+     */
+    static DefaultAssociationRole twinTown() {
+        return new DefaultAssociationRole(singletonMap(DefaultAssociationRole.NAME_KEY, "Twin
town"),
+                DefaultFeatureTypeTest.cityPopulation(), 0, Integer.MAX_VALUE);
+    }
+
+    /**
+     * Tests serialization of an {@link DefaultAssociationRole} instance.
+     */
+    @Test
+    public void testSerialization() {
+        assertSerializedEquals(twinTown());
+    }
+}

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java?rev=1593858&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
[UTF-8] Sun May 11 20:44:20 2014
@@ -0,0 +1,81 @@
+/*
+ * 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.feature;
+
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static java.util.Collections.singletonMap;
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultAssociation}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+@DependsOn({
+    DefaultAssociationRoleTest.class,
+    DefaultFeatureTest.class
+})
+public final strictfp class DefaultAssociationTest extends TestCase {
+    /**
+     * Returns an association to use for testing purpose.
+     *
+     * <blockquote>“The earliest known town twinning in Europe was between Paderborn,
Germany
+     * and Le Mans, France in 836.” — source: Wikipedia</blockquote>
+     */
+    static DefaultAssociation twinTown() {
+        final DefaultFeature twinTown = new DefaultFeature(DefaultFeatureTypeTest.cityPopulation());
+        twinTown.setPropertyValue("city", "Le Mans");
+        twinTown.setPropertyValue("population", 148169);
+        final DefaultAssociation association = new DefaultAssociation(DefaultAssociationRoleTest.twinTown());
+        association.setValue(twinTown);
+        return association;
+    }
+
+    /**
+     * Tests attempt to set a value of the wrong type.
+     */
+    @Test
+    public void testWrongValue() {
+        final DefaultAssociation association  = twinTown();
+        final PropertyType       population   = association.getRole().getValueType().getProperty("population");
+        final DefaultFeature     otherFeature = new DefaultFeature(new DefaultFeatureType(
+                singletonMap(DefaultFeatureType.NAME_KEY, "Population"), false, null, population));
+        try {
+            association.setValue(otherFeature);
+        } catch (RuntimeException e) { // TODO: IllegalPropertyException after we upgraded
GeoAPI.
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("Twin town"));
+            assertTrue(message, message.contains("Population"));
+            assertTrue(message, message.contains("City population"));
+        }
+    }
+
+    /**
+     * Tests serialization.
+     */
+    @Test
+    public void testSerialization() {
+        assertSerializedEquals(twinTown());
+    }
+}

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

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=1593858&r1=1593857&r2=1593858&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] Sun May 11 20:44:20 2014
@@ -47,7 +47,7 @@ public final strictfp class DefaultFeatu
         final DefaultAttributeType<Integer> population = DefaultAttributeTypeTest.population(properties);
 
         properties.clear();
-        assertNull(properties.put(DefaultAttributeType.NAME_KEY, "City population"));
+        assertNull(properties.put(DefaultFeatureType.NAME_KEY, "City population"));
         return new DefaultFeatureType(properties, false, null, city, population);
     }
 

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=1593858&r1=1593857&r2=1593858&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] Sun May 11 20:44:20 2014
@@ -34,7 +34,9 @@ import org.junit.BeforeClass;
     org.apache.sis.feature.DefaultFeatureTypeTest.class,
     org.apache.sis.feature.DefaultAttributeTest.class,
     org.apache.sis.feature.PropertySingletonTest.class,
-    org.apache.sis.feature.DefaultFeatureTest.class
+    org.apache.sis.feature.DefaultFeatureTest.class,
+    org.apache.sis.feature.DefaultAssociationRoleTest.class,
+    org.apache.sis.feature.DefaultAssociationTest.class
 })
 public final strictfp class FeatureTestSuite extends TestSuite {
     /**



Mime
View raw message