sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1469956 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/test/java/org/apache/sis/metadata/ sis-metadata/src/test/java/org/apache/sis/test/suite/ sis-utility/src/main/java/org/apache/sis/interna...
Date Fri, 19 Apr 2013 17:16:01 GMT
Author: desruisseaux
Date: Fri Apr 19 17:16:00 2013
New Revision: 1469956

URL: http://svn.apache.org/r1469956
Log:
More metadata tests.

Added:
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
  (with props)
Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/TypeMapTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -32,6 +32,7 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.collection.TreeTable;
 import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.internal.util.SystemListener;
+import org.apache.sis.internal.simple.SimpleCitation;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
@@ -116,8 +117,8 @@ public class MetadataStandard {
         final String[] acronyms = {"CoordinateSystem", "CS", "CoordinateReferenceSystem",
"CRS"};
         ISO_19111 = new StandardImplementation("ISO 19111", "org.opengis.referencing.", "org.apache.sis.referencing.",
prefix, acronyms);
         ISO_19115 = new StandardImplementation("ISO 19115", "org.opengis.metadata.", "org.apache.sis.metadata.iso.",
prefix, null);
-        ISO_19119 = new StandardImplementation("ISO 19119", "org.opengis.service.",  null,
null, null);
-        ISO_19123 = new StandardImplementation("ISO 19123", "org.opengis.coverage.", null,
null, null);
+        ISO_19119 = new MetadataStandard      ("ISO 19119", "org.opengis.service.");
+        ISO_19123 = new MetadataStandard      ("ISO 19123", "org.opengis.coverage.");
         INSTANCES = new MetadataStandard[] {
             ISO_19111,
             ISO_19115,
@@ -179,8 +180,8 @@ public class MetadataStandard {
      * @param citation         Bibliographical reference to the international standard.
      * @param interfacePackage The root package for metadata interfaces.
      */
-    MetadataStandard(final Citation citation, final String interfacePackage) {
-        this.citation         = citation;
+    MetadataStandard(final String citation, final String interfacePackage) {
+        this.citation         = new SimpleCitation(citation);
         this.interfacePackage = interfacePackage;
         this.accessors        = new IdentityHashMap<>();
     }

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -483,7 +483,7 @@ final class PropertyAccessor {
                          * Workaround here: I though that annotation strings were interned
like any other
                          * constants, but it doesn't seem to be the case as of JDK7. To check
if a future
                          * JDK release still needs this explicit call to String.intern(),
try to remove
-                         * the ".intern()" part and run the NameMapTest.testIntern() method.
+                         * the ".intern()" part and run the NameMapTest.testStringIntern()
method.
                          */
                         return uml.identifier().intern();
                     }

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/StandardImplementation.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -20,7 +20,6 @@ import java.util.Map;
 import java.util.IdentityHashMap;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.logging.Logging;
-import org.apache.sis.internal.simple.SimpleCitation;
 
 
 /**
@@ -79,7 +78,7 @@ final class StandardImplementation exten
     StandardImplementation(final String citation, final String interfacePackage,
             final String implementationPackage, final String[] prefix, final String[] acronyms)
     {
-        super(new SimpleCitation(citation), interfacePackage);
+        super(citation, interfacePackage);
         this.implementationPackage = implementationPackage;
         this.prefix                = prefix;
         this.acronyms              = acronyms;

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/InformationMapTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -45,11 +45,11 @@ import static org.junit.Assert.*;
 @DependsOn({PropertyAccessorTest.class, PropertyInformationTest.class})
 public final strictfp class InformationMapTest extends TestCase {
     /**
-     * Tests the map on a few specific properties of the {@link Citation} type.
+     * Tests {@link InformationMap#get(Object)} on a few specific properties of the {@link
Citation} type.
      * This test duplicates {@link PropertyInformationTest}, but is done here again as an
integration test.
      */
     @Test
-    public void testSpecificProperty() {
+    public void testGet() {
         final Map<String,ExtendedElementInformation> map = MetadataStandard.ISO_19115.asInformationMap(
                 Citation.class, KeyNamePolicy.JAVABEANS_PROPERTY);
         PropertyInformationTest.validateTitle(map.get("title"));
@@ -58,7 +58,8 @@ public final strictfp class InformationM
     }
 
     /**
-     * Tests the content of the key set of {@link EnvironmentalRecord}.
+     * Tests {@code InformationMap.keySet()}.
+     * This method uses the {@link EnvironmentalRecord} metadata type.
      * There is no requirement on the properties order.
      */
     @Test

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -18,10 +18,12 @@ package org.apache.sis.metadata;
 
 import java.util.Set;
 import java.util.Map;
+import java.util.List;
 import java.util.HashSet;
 import java.util.Collection;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.quality.Completeness;
+import org.opengis.coverage.grid.RectifiedGrid;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.citation.HardCodedCitations;
 import org.apache.sis.metadata.iso.quality.AbstractCompleteness;
@@ -39,7 +41,7 @@ import static org.opengis.test.Assert.*;
  * Tests the {@link MetadataStandard} class.
  * Unless otherwise specified, all tests use the {@link MetadataStandard#ISO_19115} constant.
  *
- * <p>The following methods are not tested by this class, because they are tested by
+ * <p>The following methods are not (or few) tested by this class, because they are
tested by
  * dedicated classes named according the implementation class doing the actual work:</p>
  *
  * <ul>
@@ -53,7 +55,8 @@ import static org.opengis.test.Assert.*;
  * @version 0.3
  * @module
  */
-@DependsOn({PropertyAccessorTest.class, NameMapTest.class, TypeMapTest.class, InformationMapTest.class})
+@DependsOn({PropertyAccessorTest.class, InformationMapTest.class,
+    NameMapTest.class, TypeMapTest.class, ValueMapTest.class})
 public final strictfp class MetadataStandardTest extends TestCase {
     /**
      * Tests {@link MetadataStandard#getInterface(Class)}.
@@ -71,7 +74,7 @@ public final strictfp class MetadataStan
      */
     @Test
     public void testGetWrongInterface() {
-        final MetadataStandard std = new MetadataStandard(HardCodedCitations.ISO, "org.opengis.dummy.");
+        final MetadataStandard std = new MetadataStandard("SIS", "org.apache.sis.dummy.");
         try {
             std.getInterface(DefaultCitation.class);
             fail("No dummy interface expected.");
@@ -125,7 +128,8 @@ public final strictfp class MetadataStan
 
     /**
      * Tests the {@link MetadataStandard#asValueMap(Object, KeyNamePolicy, ValueExistencePolicy)}
implementation.
-     * Note: this test duplicates {@link ValueMapTest}, but is done here again as an integration
test.
+     * This test duplicates {@link ValueMapTest}, but is done here again as an integration
test and because many
+     * {@code MetadataStandard} methods depend on it ({@code equals}, {@code hashCode}, {@code
prune}, <i>etc.</i>).
      */
     @Test
     public void testValueMap() {
@@ -176,4 +180,35 @@ public final strictfp class MetadataStan
         assertEquals("hashCode()", new HashSet<>(map.values()).hashCode() + Citation.class.hashCode(),
                 std.hashCode(instance));
     }
+
+    /**
+     * Tests the {@link MetadataStandard#ISO_19123} constant. Getters shall
+     * be accessible even if there is no implementation on the classpath.
+     */
+    @Test
+    public void testWithoutImplementation() {
+        final MetadataStandard std = MetadataStandard.ISO_19123;
+        assertFalse("isMetadata(Citation)",        std.isMetadata(Citation.class));
+        assertFalse("isMetadata(DefaultCitation)", std.isMetadata(DefaultCitation.class));
+        assertTrue ("isMetadata(RectifiedGrid)",   std.isMetadata(RectifiedGrid.class));
+        /*
+         * Ensure that the getters have been found.
+         */
+        final Map<String,String> names = std.asNameMap(RectifiedGrid.class, KeyNamePolicy.UML_IDENTIFIER,
KeyNamePolicy.JAVABEANS_PROPERTY);
+        assertFalse("Getters should have been found even if there is no implementation.",
names.isEmpty());
+        assertEquals("dimension", names.get("dimension"));
+        assertEquals("cells", names.get("cell"));
+        /*
+         * Ensure that the type are recognized, especially RectifiedGrid.getOffsetVectors()
+         * which is of type List<double[]>.
+         */
+        Map<String,Class<?>> types;
+        types = std.asTypeMap(RectifiedGrid.class, KeyNamePolicy.UML_IDENTIFIER, TypeValuePolicy.PROPERTY_TYPE);
+        assertEquals("The return type is the int primitive type.", Integer.TYPE, types.get("dimension"));
+        assertEquals("The offset vectors are stored in a List.",   List.class,   types.get("offsetVectors"));
+
+        types = std.asTypeMap(RectifiedGrid.class, KeyNamePolicy.UML_IDENTIFIER, TypeValuePolicy.ELEMENT_TYPE);
+        assertEquals("As elements in a list of dimensions.",       Integer.class,  types.get("dimension"));
+        assertEquals("As elements in the list of offset vectors.", double[].class, types.get("offsetVectors"));
+    }
 }

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -18,7 +18,6 @@ package org.apache.sis.metadata;
 
 import java.util.Map;
 import java.util.HashMap;
-import java.util.AbstractMap;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.acquisition.EnvironmentalRecord;
 import org.apache.sis.test.DependsOn;
@@ -26,6 +25,7 @@ import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
+import static java.util.AbstractMap.SimpleEntry;
 import static org.apache.sis.metadata.KeyNamePolicy.*;
 
 
@@ -42,7 +42,7 @@ import static org.apache.sis.metadata.Ke
 @DependsOn(PropertyAccessorTest.class)
 public final strictfp class NameMapTest extends TestCase {
     /**
-     * Tests the {@link MetadataStandard#asName(Class, KeyNamePolicy, KeyNamePolicy)} implementation.
+     * Tests {@code NameMap.entrySet()} for an exact match (including iteration order).
      * The properties used in this test are listed in {@link PropertyAccessorTest#testConstructor()}.
      *
      * @see PropertyAccessorTest#testConstructor()
@@ -52,19 +52,19 @@ public final strictfp class NameMapTest 
         final Map<String,String> map = MetadataStandard.ISO_19115.asNameMap(
                 Citation.class, KeyNamePolicy.UML_IDENTIFIER, KeyNamePolicy.JAVABEANS_PROPERTY);
         assertArrayEquals(new Object[] {
-            new AbstractMap.SimpleEntry<>("title",                 "title"),
-            new AbstractMap.SimpleEntry<>("alternateTitle",        "alternateTitles"),
-            new AbstractMap.SimpleEntry<>("date",                  "dates"),
-            new AbstractMap.SimpleEntry<>("edition",               "edition"),
-            new AbstractMap.SimpleEntry<>("editionDate",           "editionDate"),
-            new AbstractMap.SimpleEntry<>("identifier",            "identifiers"),
-            new AbstractMap.SimpleEntry<>("citedResponsibleParty", "citedResponsibleParties"),
-            new AbstractMap.SimpleEntry<>("presentationForm",      "presentationForms"),
-            new AbstractMap.SimpleEntry<>("series",                "series"),
-            new AbstractMap.SimpleEntry<>("otherCitationDetails",  "otherCitationDetails"),
-            new AbstractMap.SimpleEntry<>("collectiveTitle",       "collectiveTitle"),
-            new AbstractMap.SimpleEntry<>("ISBN",                  "ISBN"),
-            new AbstractMap.SimpleEntry<>("ISSN",                  "ISSN")
+            new SimpleEntry<>("title",                 "title"),
+            new SimpleEntry<>("alternateTitle",        "alternateTitles"),
+            new SimpleEntry<>("date",                  "dates"),
+            new SimpleEntry<>("edition",               "edition"),
+            new SimpleEntry<>("editionDate",           "editionDate"),
+            new SimpleEntry<>("identifier",            "identifiers"),
+            new SimpleEntry<>("citedResponsibleParty", "citedResponsibleParties"),
+            new SimpleEntry<>("presentationForm",      "presentationForms"),
+            new SimpleEntry<>("series",                "series"),
+            new SimpleEntry<>("otherCitationDetails",  "otherCitationDetails"),
+            new SimpleEntry<>("collectiveTitle",       "collectiveTitle"),
+            new SimpleEntry<>("ISBN",                  "ISBN"),
+            new SimpleEntry<>("ISSN",                  "ISSN")
         }, map.entrySet().toArray());
 
         assertEquals("alternateTitles", map.get("alternateTitle"));
@@ -97,7 +97,7 @@ public final strictfp class NameMapTest 
      * {@link PropertyAccessor#name(int, KeyNamePolicy)} method and run this test again.
      */
     @Test
-    public void testIntern() {
+    public void testStringIntern() {
         String name;
         Map<String,String> map;
         /*

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -143,11 +143,12 @@ public final strictfp class PropertyAcce
      * Tests the constructor with the {@link DefaultCitation} implementation.
      * The order of properties shall be the order declared in the {@code XmlType.propOrder}
annotation.
      * This test may need to be updated if a future GeoAPI release modifies the {@link Citation}
interface.
-     * Other tests that depends on {@link Citation} property order are {@link NameMapTest#testEntrySet()}
-     * and {@link TypeMapTest#testEntrySet()}</p>
+     * Other tests that depends on {@link Citation} property order are {@link NameMapTest#testEntrySet()},
+     * {@link TypeMapTest#testEntrySet()} and most tests in {@link ValueMapTest}.
      *
      * @see NameMapTest#testEntrySet()
      * @see TypeMapTest#testEntrySet()
+     * @see ValueMapTest
      */
     @Test
     public void testConstructor() {

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/TypeMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/TypeMapTest.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/TypeMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/TypeMapTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -17,7 +17,7 @@
 package org.apache.sis.metadata;
 
 import java.util.Map;
-import java.util.AbstractMap;
+import java.util.Collection;
 import java.util.Date;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
@@ -25,12 +25,18 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.metadata.citation.PresentationForm;
 import org.opengis.metadata.citation.ResponsibleParty;
 import org.opengis.metadata.citation.Series;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.metadata.extent.GeographicDescription;
 import org.opengis.util.InternationalString;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.extent.AbstractGeographicExtent;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicDescription;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
+import static java.util.AbstractMap.SimpleEntry;
 
 
 /**
@@ -39,14 +45,14 @@ import static org.junit.Assert.*;
  * Unless otherwise specified, all tests use the {@link MetadataStandard#ISO_19115} constant.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @since   0.3
+ * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
  */
 @DependsOn(PropertyAccessorTest.class)
 public final strictfp class TypeMapTest extends TestCase {
     /**
-     * Tests the {@link MetadataStandard#asType(Class, KeyNamePolicy, TypeValuePolicy)} implementation.
+     * Tests {@code TypeMap.entrySet()} for an exact match (including iteration order).
      * The properties used in this test are listed in {@link PropertyAccessorTest#testConstructor()}.
      *
      * @see PropertyAccessorTest#testConstructor()
@@ -56,22 +62,59 @@ public final strictfp class TypeMapTest 
         final Map<String,Class<?>> map = MetadataStandard.ISO_19115.asTypeMap(
                 Citation.class, KeyNamePolicy.UML_IDENTIFIER, TypeValuePolicy.ELEMENT_TYPE);
         assertArrayEquals(new Object[] {
-            new AbstractMap.SimpleEntry<>("title",                 InternationalString.class),
-            new AbstractMap.SimpleEntry<>("alternateTitle",        InternationalString.class),
-            new AbstractMap.SimpleEntry<>("date",                  CitationDate.class),
-            new AbstractMap.SimpleEntry<>("edition",               InternationalString.class),
-            new AbstractMap.SimpleEntry<>("editionDate",           Date.class),
-            new AbstractMap.SimpleEntry<>("identifier",            Identifier.class),
-            new AbstractMap.SimpleEntry<>("citedResponsibleParty", ResponsibleParty.class),
-            new AbstractMap.SimpleEntry<>("presentationForm",      PresentationForm.class),
-            new AbstractMap.SimpleEntry<>("series",                Series.class),
-            new AbstractMap.SimpleEntry<>("otherCitationDetails",  InternationalString.class),
-            new AbstractMap.SimpleEntry<>("collectiveTitle",       InternationalString.class),
-            new AbstractMap.SimpleEntry<>("ISBN",                  String.class),
-            new AbstractMap.SimpleEntry<>("ISSN",                  String.class)
+            new SimpleEntry<>("title",                 InternationalString.class),
+            new SimpleEntry<>("alternateTitle",        InternationalString.class),
+            new SimpleEntry<>("date",                  CitationDate.class),
+            new SimpleEntry<>("edition",               InternationalString.class),
+            new SimpleEntry<>("editionDate",           Date.class),
+            new SimpleEntry<>("identifier",            Identifier.class),
+            new SimpleEntry<>("citedResponsibleParty", ResponsibleParty.class),
+            new SimpleEntry<>("presentationForm",      PresentationForm.class),
+            new SimpleEntry<>("series",                Series.class),
+            new SimpleEntry<>("otherCitationDetails",  InternationalString.class),
+            new SimpleEntry<>("collectiveTitle",       InternationalString.class),
+            new SimpleEntry<>("ISBN",                  String.class),
+            new SimpleEntry<>("ISSN",                  String.class)
         }, map.entrySet().toArray());
 
         assertEquals(InternationalString.class, map.get("alternateTitle"));
         assertNull("Shall not exists.", map.get("dummy"));
     }
+
+    /**
+     * Tests {@link TypeMap#get(Object)} on a well known metadata type for various {@link
TypeValuePolicy}.
+     */
+    @Test
+    public void testGet() {
+        final MetadataStandard standard = MetadataStandard.ISO_19115;
+        final KeyNamePolicy keyPolicy = KeyNamePolicy.JAVABEANS_PROPERTY;
+        Map<String, Class<?>> types;
+
+        types = standard.asTypeMap(DefaultCitation.class, keyPolicy, TypeValuePolicy.PROPERTY_TYPE);
+        assertEquals(InternationalString.class, types.get("title"));
+        assertEquals(Collection.class,          types.get("alternateTitles"));
+
+        types = standard.asTypeMap(DefaultCitation.class, keyPolicy, TypeValuePolicy.ELEMENT_TYPE);
+        assertEquals(InternationalString.class, types.get("title"));
+        assertEquals(InternationalString.class, types.get("alternateTitles"));
+
+        types = standard.asTypeMap(DefaultCitation.class, keyPolicy, TypeValuePolicy.DECLARING_INTERFACE);
+        assertEquals(Citation.class, types.get("title"));
+        assertEquals(Citation.class, types.get("alternateTitles"));
+
+        types = standard.asTypeMap(DefaultCitation.class, keyPolicy, TypeValuePolicy.DECLARING_CLASS);
+        assertEquals(DefaultCitation.class, types.get("title"));
+        assertEquals(DefaultCitation.class, types.get("alternateTitles"));
+
+        /*
+         * Tests declaring classes/interfaces again, now with metadata having a class hierarchy.
+         */
+        types = standard.asTypeMap(DefaultGeographicDescription.class, keyPolicy, TypeValuePolicy.DECLARING_INTERFACE);
+        assertEquals(GeographicDescription.class, types.get("geographicIdentifier"));
+        assertEquals(GeographicExtent.class,      types.get("inclusion"));
+
+        types = standard.asTypeMap(DefaultGeographicDescription.class, keyPolicy, TypeValuePolicy.DECLARING_CLASS);
+        assertEquals(DefaultGeographicDescription.class, types.get("geographicIdentifier"));
+        assertEquals(AbstractGeographicExtent.class,     types.get("inclusion"));
+    }
 }

Added: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java?rev=1469956&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -0,0 +1,264 @@
+/*
+ * 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.metadata;
+
+import java.util.Map;
+import java.util.Collection;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.Identifier;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.citation.DefaultResponsibleParty;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.opengis.test.Assert.*;
+import static java.util.AbstractMap.SimpleEntry;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
+import static org.opengis.metadata.citation.PresentationForm.DOCUMENT_HARDCOPY;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+
+
+/**
+ * Tests the {@link ValueMap} class on instances created by
+ * {@link MetadataStandard#asValueMap(Object, KeyNamePolicy, ValueExistencePolicy)}.
+ * Unless otherwise specified, all tests use the {@link MetadataStandard#ISO_19115} constant.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ *
+ * @see MetadataStandardTest#testValueMap()
+ */
+@DependsOn(PropertyAccessorTest.class)
+public final strictfp class ValueMapTest extends TestCase {
+    /**
+     * The citation instance created by {@link #createCitation()}.
+     */
+    private DefaultCitation citation;
+
+    /**
+     * The title of the metadata instance created by {@link #createCitation()}.
+     */
+    private InternationalString title;
+
+    /**
+     * The author of the metadata instance created by {@link #createCitation()}.
+     */
+    private DefaultResponsibleParty author;
+
+    /**
+     * Creates the metadata instance to be used for testing purpose.
+     * This method creates the following metadata
+     * (ignoring identifiers, which will be inferred from the ISBN value):
+     *
+     * {@preformat text
+     *     Citation
+     *     ├───Title……………………………………………………
Undercurrent
+     *     ├───Cited Responsible Parties
+     *     │   └───Individual Name……………… Testsuya Toyoda
+     *     └───ISBN………………………………………………………
9782505004509
+     * }
+     *
+     * The citation instance is stored in the {@link #citation} field.
+     * The title and author instances are stored in the {@link #title} and {@link #author}
fields.
+     *
+     * @return The map view of the citation create by this method.
+     */
+    private Map<String,Object> createCitation() {
+        title    = new SimpleInternationalString("Undercurrent");
+        author   = new DefaultResponsibleParty();
+        citation = new DefaultCitation(title);
+        author.setIndividualName("Testsuya Toyoda");
+        citation.getCitedResponsibleParties().add(author);
+        citation.setISBN("9782505004509");
+        return MetadataStandard.ISO_19115.asValueMap(citation, KeyNamePolicy.JAVABEANS_PROPERTY,
ValueExistencePolicy.NON_EMPTY);
+    }
+
+    /**
+     * Tests the {@link ValueMap#get(Object)} method.
+     */
+    @Test
+    public void testGet() {
+        final Map<String,Object> map = createCitation();
+        assertEquals("Undercurrent",        map.get("title").toString());
+        assertEquals(singletonList(author), map.get("citedResponsibleParties"));
+        assertEquals("9782505004509",       map.get("ISBN"));
+        /*
+         * The ISBN shall also be visible as an identifier.
+         */
+        final Object identifiers = map.get("identifiers");
+        assertInstanceOf("identifiers", Collection.class, identifiers);
+        final Object identifier = getSingleton((Collection<?>) identifiers);
+        assertInstanceOf("identifier", Identifier.class, identifier);
+        assertEquals("9782505004509", ((Identifier) identifier).getCode());
+    }
+
+    /**
+     * Tests the {@link ValueMap#entrySet()} method.
+     * The metadata to be tested is:
+     *
+     * {@preformat text
+     *     Citation
+     *     ├───Title……………………………………………………
Undercurrent
+     *     ├───Identifiers…………………………………… 9782505004509
+     *     ├───Cited Responsible Parties
+     *     │   └───Individual Name……………… Testsuya Toyoda
+     *     └───ISBN………………………………………………………
9782505004509
+     * }
+     *
+     * Note that this test is intentionally sensitive to iteration order.
+     * That order shall be fixed by the {@code XmlType} annotation.
+     */
+    @Test
+    @DependsOnMethod("testGet")
+    public void testEntrySet() {
+        final Map<String,Object> map = createCitation();
+        assertEquals(1, citation.getIdentifiers().size());
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("identifiers",             citation.getIdentifiers()),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
+            new SimpleEntry<>("ISBN",                    "9782505004509")
+        }, map.entrySet().toArray());
+    }
+
+    /**
+     * Tests the {@link ValueMap#entrySet()} method for the same metadata than {@link #testEntrySet()},
+     * but asking for all non-null entries including the empty collections.
+     */
+    @Test
+    @DependsOnMethod("testEntrySet")
+    public void testEntrySetForNonNull() {
+        final Map<String,Object> map = createCitation();
+        final Map<String,Object> all = MetadataStandard.ISO_19115.asValueMap(citation,
+                KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_NULL);
+        assertFalse("Null values should be excluded.", map.containsKey("alternateTitles"));
+        assertTrue ("Null values should be included.", all.containsKey("alternateTitles"));
+        assertTrue ("'all' should be a larger map than 'map'.", all.entrySet().containsAll(map.entrySet()));
+        assertFalse("'all' should be a larger map than 'map'.", map.entrySet().containsAll(all.entrySet()));
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("alternateTitles",         emptyList()),
+            new SimpleEntry<>("dates",                   emptyList()),
+            new SimpleEntry<>("identifiers",             citation.getIdentifiers()),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
+            new SimpleEntry<>("presentationForms",       emptySet()),
+            new SimpleEntry<>("ISBN",                    "9782505004509")
+        }, all.entrySet().toArray());
+    }
+
+    /**
+     * Tests the {@link ValueMap#entrySet()} method for the same metadata than {@link #testEntrySet()},
+     * but asking for all entries including null and empty values.
+     */
+    @Test
+    @DependsOnMethod("testEntrySet")
+    public void testEntrySetForAll() {
+        final Map<String,Object> map = createCitation();
+        final Map<String,Object> all = MetadataStandard.ISO_19115.asValueMap(citation,
+                KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.ALL);
+        assertFalse("Null values should be excluded.", map.containsKey("alternateTitles"));
+        assertTrue ("Null values should be included.", all.containsKey("alternateTitles"));
+        assertTrue ("'all' should be a larger map than 'map'.", all.entrySet().containsAll(map.entrySet()));
+        assertFalse("'all' should be a larger map than 'map'.", map.entrySet().containsAll(all.entrySet()));
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("alternateTitles",         emptyList()),
+            new SimpleEntry<>("dates",                   emptyList()),
+            new SimpleEntry<>("edition",                 null),
+            new SimpleEntry<>("editionDate",             null),
+            new SimpleEntry<>("identifiers",             citation.getIdentifiers()),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
+            new SimpleEntry<>("presentationForms",       emptySet()),
+            new SimpleEntry<>("series",                  null),
+            new SimpleEntry<>("otherCitationDetails",    null),
+            new SimpleEntry<>("collectiveTitle",         null),
+            new SimpleEntry<>("ISBN",                    "9782505004509"),
+            new SimpleEntry<>("ISSN",                    null)
+        }, all.entrySet().toArray());
+    }
+
+    /**
+     * Tests the {@link ValueMap#add(String,Object)} and {@link ValueMap#remove(Object)}
methods.
+     * Note that this test is intentionally sensitive to iteration order.
+     * That order shall be fixed by the {@code XmlType} annotation.
+     */
+    @Test
+    @DependsOnMethod("testEntrySet")
+    public void testAddAndRemove() {
+        final Map<String,Object> map = createCitation();
+        /*
+         * Remove the ISBN value. Result shall be:
+         *
+         * Citation
+         * ├───Title……………………………………………………
Undercurrent
+         * └───Cited Responsible Parties
+         *     └───Individual Name……………… Testsuya Toyoda
+         */
+        assertEquals("9782505004509", map.remove("ISBN"));
+        assertNull("ISBN shall have been removed.", citation.getISBN());
+        assertTrue("ISBN shall have been removed.", citation.getIdentifiers().isEmpty());
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author))
+        }, map.entrySet().toArray());
+        /*
+         * Add a value. Result shall be:
+         *
+         * Citation
+         * ├───Title……………………………………………………
Undercurrent
+         * ├───Cited Responsible Parties
+         * │   └───Individual Name……………… Testsuya Toyoda
+         * └───Presentation Forms………………… document hardcopy
+         */
+        assertNull(map.put("presentationForm", DOCUMENT_HARDCOPY));
+        assertEquals(DOCUMENT_HARDCOPY, getSingleton(citation.getPresentationForms()));
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
+            new SimpleEntry<>("presentationForms",       singleton(DOCUMENT_HARDCOPY))
+        }, map.entrySet().toArray());
+        /*
+         * Add back the ISBN value. Result shall be:
+         *
+         * Citation
+         * ├───Title……………………………………………………
Undercurrent
+         * ├───Identifiers…………………………………… 9782505004509
+         * ├───Cited Responsible Parties
+         * │   └───Individual Name……………… Testsuya Toyoda
+         * ├───Presentation Forms………………… document hardcopy
+         * └───ISBN………………………………………………………
9782505004509
+         */
+        assertNull(map.put("ISBN", "9782505004509"));
+        assertEquals("9782505004509", citation.getISBN());
+        assertEquals("ISBN shall appears in the identifier list.", 1, citation.getIdentifiers().size());
+        assertArrayEquals(new SimpleEntry<?,?>[] {
+            new SimpleEntry<>("title",                   title),
+            new SimpleEntry<>("identifiers",             citation.getIdentifiers()),
+            new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
+            new SimpleEntry<>("presentationForms",       singleton(DOCUMENT_HARDCOPY)),
+            new SimpleEntry<>("ISBN",                    "9782505004509")
+        }, map.entrySet().toArray());
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -36,6 +36,7 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.NameMapTest.class,
     org.apache.sis.metadata.TypeMapTest.class,
     org.apache.sis.metadata.InformationMapTest.class,
+    org.apache.sis.metadata.ValueMapTest.class,
     org.apache.sis.metadata.MetadataStandardTest.class
 })
 public final strictfp class MetadataTestSuite extends TestSuite {

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1469956&r1=1469955&r2=1469956&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] Fri Apr 19 17:16:00 2013
@@ -18,6 +18,7 @@ package org.apache.sis.internal.util;
 
 import java.util.*;
 import org.apache.sis.util.Static;
+import org.apache.sis.util.collection.CodeListSet;
 
 
 /**
@@ -28,7 +29,7 @@ import org.apache.sis.util.Static;
  * <ul>
  *   <li>{@link #toCollection(Object) toCollection} for wrapping or copying arbitrary
objects to
  *       list or collection.</li>
- *   <li>{@link #modifiableCopy(Collection) modifiableCopy} method for taking a snapshot
of an arbitrary
+ *   <li>{@link #copy(Collection, boolean) copy} method for taking a snapshot of an
arbitrary
  *       implementation into an unsynchronized, modifiable, in-memory object.</li>
  *   <li>{@link #unmodifiableOrCopy(Set) unmodifiableOrCopy} methods, which may be
slightly more
  *       compact than the standard {@link Collections#unmodifiableSet(Set)} equivalent
@@ -194,6 +195,8 @@ public final class CollectionsExt extend
      * <tr><td>{@link List} or other {@link Collection}</td><td class="sep">{@link
ArrayList}</td></tr>
      * </table>
      *
+     * This method may not preserve the {@link org.apache.sis.util.collection.CheckedContainer}
interface.
+     *
      * @param  <E> The type of elements in the collection.
      * @param  collection The collection to copy, or {@code null}.
      * @return A copy of the given collection, or {@code null} if the given collection was
null.
@@ -218,6 +221,12 @@ public final class CollectionsExt extend
             if (type == HashSet.class || type == LinkedHashSet.class) {
                 return (Collection<E>) ((HashSet<E>) collection).clone();
             }
+            if (collection instanceof EnumSet<?>) {
+                return ((EnumSet) collection).clone();
+            }
+            if (collection instanceof CodeListSet<?>) {
+                return ((CodeListSet) collection).clone();
+            }
             return new LinkedHashSet<>(collection);
         }
         if (collection instanceof Queue<?>) {



Mime
View raw message