sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1631330 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/internal/metadata/ test/java/org/apache/sis/internal/metadata/ test/java/org/apache/sis/metadata/iso/ test/java/org/apache/sis/test/suite/
Date Mon, 13 Oct 2014 10:21:19 GMT
Author: desruisseaux
Date: Mon Oct 13 10:21:18 2014
New Revision: 1631330

URL: http://svn.apache.org/r1631330
Log:
Added more tests.

Added:
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java?rev=1631330&r1=1631329&r2=1631330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java
[UTF-8] Mon Oct 13 10:21:18 2014
@@ -193,6 +193,7 @@ public final class OtherLocales extends 
         if (newValue == null) {
             final Iterator<T> it = values.iterator();
             if (it.hasNext()) {
+                it.next();
                 it.remove();
             }
         } else if (values.isEmpty()) {

Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java?rev=1631330&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
(added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
[UTF-8] Mon Oct 13 10:21:18 2014
@@ -0,0 +1,129 @@
+/*
+ * 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.internal.metadata;
+
+import java.util.Locale;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import org.junit.Test;
+import org.apache.sis.test.TestCase;
+
+import static java.util.Locale.*;
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link OtherLocales} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public final strictfp class OtherLocalesTest extends TestCase {
+    /**
+     * Tests {@link OtherLocales#filter(Collection)}.
+     */
+    @Test
+    public void testFilter() {
+        final Collection<Locale> languages = new LinkedHashSet<>();
+        final Collection<Locale> otherLocales = OtherLocales.filter(languages);
+        assertEquals("size", 0, otherLocales.size());
+        /*
+         * The first locale in the 'languages' list is taken as the default locale.
+         * It shall not appears in the 'other locales' collection.
+         */
+        assertTrue(languages.add(ENGLISH));
+        assertEquals("size", 0, otherLocales.size());
+        /*
+         * All elements after the first one in the 'language' list are "other locales".
+         */
+        assertTrue(languages.add(FRENCH));
+        assertEquals("size", 1, otherLocales.size());
+        assertArrayEquals(new Locale[] {FRENCH}, otherLocales.toArray());
+        /*
+         * Adding to the "other locales" collection shall delegate to the 'languages' list.
+         */
+        assertTrue(otherLocales.add(JAPANESE));
+        assertEquals("size", 2, otherLocales.size());
+        assertArrayEquals(new Locale[] {FRENCH, JAPANESE}, otherLocales.toArray());
+        assertArrayEquals(new Locale[] {ENGLISH, FRENCH, JAPANESE}, languages.toArray());
+        /*
+         * Clearing the "other locales" list shall not remove the default locale.
+         */
+        otherLocales.clear();
+        assertEquals("size", 0, otherLocales.size());
+        assertArrayEquals(new Locale[] {ENGLISH}, languages.toArray());
+        /*
+         * The first 'add' operation on an empty 'languages' list generates a default locale.
+         * Note that we can not test the first element of 'languages', since it is system-dependent.
+         */
+        languages.clear();
+        assertTrue(otherLocales.add(FRENCH));
+        assertArrayEquals(new Locale[] {FRENCH}, otherLocales.toArray());
+        assertEquals("size", 2, languages.size());
+    }
+
+    /**
+     * Tests {@link OtherLocales#merge(Locale, Collection)}.
+     */
+    @Test
+    public void testMerge() {
+        Collection<Locale> merged = OtherLocales.merge(null, null);
+        assertTrue(merged.isEmpty());
+
+        merged = OtherLocales.merge(ENGLISH, null);
+        assertArrayEquals(new Locale[] {ENGLISH}, merged.toArray());
+
+        merged = OtherLocales.merge(ENGLISH, Arrays.asList(FRENCH, JAPANESE));
+        assertArrayEquals(new Locale[] {ENGLISH, FRENCH, JAPANESE}, merged.toArray());
+        /*
+         * The tricky case: a default locale will be generated. That locale is system-dependent.
+         */
+        merged = OtherLocales.merge(null, Arrays.asList(FRENCH, JAPANESE));
+        final Iterator<Locale> it = merged.iterator();
+        assertNotNull(it.next()); // System-dependent value.
+        assertEquals(FRENCH,   it.next());
+        assertEquals(JAPANESE, it.next());
+        assertFalse(it.hasNext());
+    }
+
+    /**
+     * Tests the {@link OtherLocales#setFirst(Collection, Object)} method.
+     */
+    @Test
+    public void testSetFirst() {
+        Collection<Locale> locales = OtherLocales.setFirst(null, null);
+        assertTrue(locales.isEmpty());
+
+        locales = OtherLocales.setFirst(null, GERMAN);
+        assertArrayEquals(new Locale[] {GERMAN}, locales.toArray());
+
+        locales = Arrays.asList(ENGLISH, JAPANESE, FRENCH);
+        assertSame("Shall set value in-place.", locales, OtherLocales.setFirst(locales, GERMAN));
+        assertArrayEquals(new Locale[] {GERMAN, JAPANESE, FRENCH}, locales.toArray());
+
+        locales = new LinkedHashSet<>(Arrays.asList(ENGLISH, JAPANESE, FRENCH));
+        locales = OtherLocales.setFirst(locales, ITALIAN);
+        assertArrayEquals(new Locale[] {ITALIAN, JAPANESE, FRENCH}, locales.toArray());
+
+        locales = OtherLocales.setFirst(locales, null);
+        assertArrayEquals(new Locale[] {JAPANESE, FRENCH}, locales.toArray());
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/OtherLocalesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1631330&r1=1631329&r2=1631330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] Mon Oct 13 10:21:18 2014
@@ -16,20 +16,33 @@
  */
 package org.apache.sis.metadata.iso;
 
+import java.util.Date;
 import java.util.Locale;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.Collection;
 import java.util.logging.LogRecord;
+import java.net.URISyntaxException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
+import org.opengis.metadata.MetadataScope;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.citation.DateType;
+import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
 import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.date;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
@@ -51,6 +64,7 @@ import static org.apache.sis.test.Assert
  * @version 0.5
  * @module
  */
+@DependsOn(org.apache.sis.internal.metadata.OtherLocalesTest.class)
 public final strictfp class DefaultMetadataTest extends XMLTestCase implements WarningListener<Object>
{
     /**
      * The resource key for the message of the warning that occurred while unmarshalling
a XML fragment,
@@ -136,10 +150,10 @@ public final strictfp class DefaultMetad
     @SuppressWarnings("deprecation")
     public void testFileIdentifier() {
         final DefaultMetadata metadata = new DefaultMetadata();
-        assertNull("getFileIdentifier", metadata.getFileIdentifier());
+        assertNull("fileIdentifier", metadata.getFileIdentifier());
         metadata.setFileIdentifier("Apache SIS/Metadata test");
-        assertEquals("getMetadataIdentifier", "Apache SIS/Metadata test", metadata.getMetadataIdentifier().getCode());
-        assertEquals("getFileIdentifier",     "Apache SIS/Metadata test", metadata.getFileIdentifier());
+        assertEquals("metadataIdentifier", "Apache SIS/Metadata test", metadata.getMetadataIdentifier().getCode());
+        assertEquals("fileIdentifier",     "Apache SIS/Metadata test", metadata.getFileIdentifier());
     }
 
     /**
@@ -153,7 +167,7 @@ public final strictfp class DefaultMetad
     @SuppressWarnings("deprecation")
     public void testLocales() {
         final DefaultMetadata metadata = new DefaultMetadata();
-        assertNull("getLanguage", metadata.getLanguage());
+        assertNull("language", metadata.getLanguage());
         /*
          * Set the default language, which shall be the first entry in the collection.
          * The "other locales" property shall be unmodified by the "language" one.
@@ -188,8 +202,134 @@ public final strictfp class DefaultMetad
      */
     @SuppressWarnings("deprecation")
     private static void assertLanguagesEquals(final DefaultMetadata metadata, final Locale...
expected) {
-        assertArrayEquals("getLanguages", expected,    metadata.getLanguages().toArray());
-        assertEquals     ("getLanguage",  expected[0], metadata.getLanguage());
-        assertArrayEquals("getLocales",   Arrays.copyOfRange(expected, 1, expected.length),
metadata.getLocales().toArray());
+        assertArrayEquals("languages", expected,    metadata.getLanguages().toArray());
+        assertEquals     ("language",  expected[0], metadata.getLanguage());
+        assertArrayEquals("locales",   Arrays.copyOfRange(expected, 1, expected.length),
metadata.getLocales().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getParentIdentifier()} and {@link DefaultMetadata#setParentIdentifier(String)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testParentIdentifier() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("parentIdentifier", metadata.getParentIdentifier());
+        metadata.setParentIdentifier("ParentID");
+        assertEquals("parentIdentifier", "ParentID", metadata.getParentIdentifier());
+
+        DefaultCitation c = (DefaultCitation) metadata.getParentMetadata();
+        assertEquals("parentMetadata", "ParentID", c.getTitle().toString());
+        c.setTitle(new SimpleInternationalString("New parent"));
+        assertEquals("parentIdentifier", "New parent", metadata.getParentIdentifier());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getHierarchyLevels()}, {@link DefaultMetadata#getHierarchyLevelNames()},
+     * {@link DefaultMetadata#setHierarchyLevel(Collection)} and {@link DefaultMetadata#setHierarchyLevelNames(Collection)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testHierarchyLevels() {
+        final String[]    names  = new String[] {"Bridges", "Golden Gate Bridge"};
+        final ScopeCode[] levels = new ScopeCode[] {ScopeCode.FEATURE_TYPE, ScopeCode.FEATURE};
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertTrue("hierarchyLevelNames", metadata.getHierarchyLevelNames().isEmpty());
+        assertTrue("hierarchyLevels",     metadata.getHierarchyLevels().isEmpty());
+
+        metadata.setHierarchyLevelNames(Arrays.asList(names));
+        metadata.setHierarchyLevels(Arrays.asList(levels));
+        assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
+        assertArrayEquals("hierarchyLevels",     levels, metadata.getHierarchyLevels().toArray());
+        /*
+         * The above deprecated methods shall have created MetadataScope object. Verify that.
+         */
+        final Collection<MetadataScope> scopes = metadata.getMetadataScopes();
+        final Iterator<MetadataScope> it = scopes.iterator();
+        MetadataScope scope = it.next();
+        assertEquals("metadataScopes[0].name", "Bridges", scope.getName().toString());
+        assertEquals("metadataScopes[0].resourceScope", ScopeCode.FEATURE_TYPE, scope.getResourceScope());
+        scope = it.next();
+        assertEquals("metadataScopes[1].name", "Golden Gate Bridge", scope.getName().toString());
+        assertEquals("metadataScopes[1].resourceScope", ScopeCode.FEATURE, scope.getResourceScope());
+        /*
+         * Changes in the MetadataScope object shall be relfected immediately on the scope
collection.
+         * Verify that.
+         */
+        it.remove();
+        assertFalse(it.hasNext());
+        final DefaultMetadataScope c = new DefaultMetadataScope(levels[1] = ScopeCode.ATTRIBUTE_TYPE);
+        c.setName(new SimpleInternationalString(names[1] = "Clearance"));
+        assertTrue(scopes.add(c));
+        assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
+        assertArrayEquals("hierarchyLevels",     levels, metadata.getHierarchyLevels().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getDateStamp()} and {@link DefaultMetadata#setDateStamp(Date)}
methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testDateStamp() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("dateStamp", metadata.getDateStamp());
+        /*
+         * Verifies that the deprecated method get its value from the CitationDate objects.
+         */
+        Date creation = date("2014-10-07 00:00:00");
+        final DefaultCitationDate[] dates = new DefaultCitationDate[] {
+                new DefaultCitationDate(date("2014-10-09 00:00:00"), DateType.LAST_UPDATE),
+                new DefaultCitationDate(creation, DateType.CREATION)
+        };
+        metadata.setDates(Arrays.asList(dates));
+        assertEquals("dateStamp", creation, metadata.getDateStamp());
+        /*
+         * Invoking the deprecated setters shall modify the CitationDate object
+         * associated to DateType.CREATION.
+         */
+        creation = date("2014-10-06 00:00:00");
+        metadata.setDateStamp(creation);
+        assertEquals("citationDates[1].date", creation, dates[1].getDate());
+        assertArrayEquals("dates", dates, metadata.getDates().toArray());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getMetadataStandardName()}, {@link DefaultMetadata#getMetadataStandardVersion()},
+     * {@link DefaultMetadata#setMetadataStandardName(String)} and {@link DefaultMetadata#setMetadataStandardVersion(String)}
+     * methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testMetadataStandard() {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        assertNull("metadataStandardName",    metadata.getMetadataStandardName());
+        assertNull("metadataStandardVersion", metadata.getMetadataStandardVersion());
+
+        String name = "ISO 19115-2 Geographic Information - Metadata Part 2 Extensions for
imagery and gridded data";
+        String version = "ISO 19115-2:2009(E)";
+        metadata.setMetadataStandardName(name);
+        metadata.setMetadataStandardVersion(version);
+        assertEquals("metadataStandardName",    name,    metadata.getMetadataStandardName());
+        assertEquals("metadataStandardVersion", version, metadata.getMetadataStandardVersion());
+        final Citation standard = getSingleton(metadata.getMetadataStandards());
+        assertEquals(name,    standard.getTitle()  .toString());
+        assertEquals(version, standard.getEdition().toString());
+    }
+
+    /**
+     * Tests {@link DefaultMetadata#getDataSetUri()}.
+     *
+     * @throws URISyntaxException Should not happen.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testDataSetUri() throws URISyntaxException {
+        final DefaultMetadata metadata = new DefaultMetadata();
+        metadata.setDataSetUri("file:/tmp/myfile.txt");
+        assertEquals("file:/tmp/myfile.txt", metadata.getDataSetUri());
+        assertEquals("file:/tmp/myfile.txt", getSingleton(getSingleton(metadata.getIdentificationInfo())
+                .getCitation().getOnlineResources()).getLinkage().toString());
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1631330&r1=1631329&r2=1631330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Mon Oct 13 10:21:18 2014
@@ -32,6 +32,7 @@ import org.junit.BeforeClass;
 @Suite.SuiteClasses({
     org.apache.sis.internal.metadata.MetadataUtilitiesTest.class,
     org.apache.sis.internal.metadata.ReferencingUtilitiesTest.class,
+    org.apache.sis.internal.metadata.OtherLocalesTest.class,
 
     // Classes using Java reflection.
     org.apache.sis.metadata.PropertyInformationTest.class,



Mime
View raw message