sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1775000 - in /sis/branches/JDK8: core/sis-utility/src/main/java/org/apache/sis/internal/util/ core/sis-utility/src/test/java/org/apache/sis/internal/util/ storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/ storage/sis-xmlstore...
Date Mon, 19 Dec 2016 08:06:38 GMT
Author: desruisseaux
Date: Mon Dec 19 08:06:38 2016
New Revision: 1775000

URL: http://svn.apache.org/viewvc?rev=1775000&view=rev
Log:
Rename StaxStream as StaxStreamIO.
Parse metadata outside the constructor for allowing 'close()' method invocation in case of
error.
More accurate date and time parsing, using LocalDate only if there is no timezone information.


Added:
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamIO.java
      - copied, changed from r1774999, sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStream.java
Removed:
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStream.java
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/package-info.java
    sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXReaderTest.java
    sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -36,6 +36,7 @@ import java.time.ZoneId;
 import java.time.ZoneOffset;
 import java.time.temporal.Temporal;
 import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalQuery;
 import java.time.temporal.TemporalAccessor;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
@@ -99,6 +100,32 @@ public final class StandardDateFormat ex
             .toFormatter(Locale.ROOT);
 
     /**
+     * The kind of objects to get from calls to {@link #parseBest(CharSequence)}, in preference
order.
+     * The time is converted to UTC timezone if possible.
+     *
+     * Tip: if we want to preserve the timezone instead than converting to UTC, we could
try replacing
+     * {@code Instant::from} by {@code ZonedDateTime::from, OffsetDateTime::from}.
+     */
+    private static TemporalQuery<?>[] QUERIES = {
+        Instant::from, LocalDateTime::from, LocalDate::from
+    };
+
+    /**
+     * Parses the given date and/or time, which may have an optional timezone. This method
applies heuristic rules
+     * for choosing if the object should be returned as a local date, or a date and time
with timezone, <i>etc</i>.
+     *
+     * @param  text  the character string to parse, or {@code null}.
+     * @return a temporal object for the given text, or {@code null} if the given text was
null.
+     * @throws DateTimeParseException if the text can not be parsed as a date.
+     *
+     * @since 0.8
+     */
+    public static Temporal parseBest(final CharSequence text) {
+        // Cast is safe if all QUERIES elements return a Temporal subtype.
+        return (text != null) ? (Temporal) FORMAT.parseBest(text, QUERIES) : null;
+    }
+
+    /**
      * The length of a day in number of milliseconds.
      */
     public static final int MILLISECONDS_PER_DAY = 24*60*60*1000;

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -23,6 +23,11 @@ import org.junit.Test;
 import static org.apache.sis.test.TestUtilities.date;
 import static org.junit.Assert.*;
 
+// Branch-dependent imports
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
 
 /**
  * Tests the {@link StandardDateFormat} class.
@@ -58,4 +63,20 @@ public final strictfp class StandardDate
         assertEquals(date("2005-09-22 00:00:00"), f.parse("2005-9-22"));
         assertEquals(date("1992-01-01 00:00:00"), f.parse("1992-1-1"));
     }
+
+    /**
+     * Tests parsing a temporal object.
+     *
+     * @since 0.8
+     */
+    @Test
+    public void testParseBest() {
+        final long day = 1466985600000L;
+        assertEquals(Instant.ofEpochMilli(day + ((16*60 + 48)*60     )*1000),      StandardDateFormat.parseBest("2016-06-27T16:48Z"));
+        assertEquals(Instant.ofEpochMilli(day + ((16*60 + 48)*60 + 12)*1000),      StandardDateFormat.parseBest("2016-06-27T16:48:12Z"));
+        assertEquals(Instant.ofEpochMilli(day + (( 3*60 +  2)*60 +  1)*1000 + 90), StandardDateFormat.parseBest("2016-06-27T03:02:01.09Z"));
+        assertEquals(LocalDateTime.of(2016, 6, 27, 16, 48, 12),                    StandardDateFormat.parseBest("2016-06-27T16:48:12"));
+        assertEquals(LocalDateTime.of(2016, 6, 27, 16, 48),                        StandardDateFormat.parseBest("2016-06-27T16:48"));
+        assertEquals(LocalDate.of(2016, 6, 27),                                    StandardDateFormat.parseBest("2016-06-27"));
+    }
 }

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -68,19 +68,19 @@ public class GPXReader extends StaxStrea
      * The namespace, which should be either {@link Tags#NAMESPACE_V10} or {@link Tags#NAMESPACE_V11}.
      * We store this information for identifying the closing {@code <gpx>} tag.
      */
-    private final String namespace;
+    private String namespace;
 
     /**
      * Version of the GPX file, or {@code null} if unspecified.
      * Can be {@link GPXStore#V1_0} or {@link GPXStore#V1_1}.
      */
-    private final Version version;
+    private Version version;
 
     /**
      * Convenience flag set to {@code true} if the {@link #version} field is {@link GPXStore#V1_0},
      * or {@code false} if the version is {@link GPXStore#V1_1}.
      */
-    private final boolean isLegacy;
+    private boolean isLegacy;
 
     /**
      * The metadata (ISO 19115 compatible), or {@code null} if none.
@@ -118,22 +118,34 @@ public class GPXReader extends StaxStrea
 
     /**
      * Creates a new GPX reader from the given file, URL, stream or reader object.
+     * The {@link #initialize()} method must be invoked after this constructor.
      *
      * @param  owner      the data store for which this reader is created.
      * @param  connector  information about the storage (URL, stream, <i>etc</i>).
      * @throws DataStoreException if the input type is not recognized.
      * @throws XMLStreamException if an error occurred while opening the XML file.
+     */
+    public GPXReader(final GPXStore owner, final StorageConnector connector)
+            throws DataStoreException, XMLStreamException
+    {
+        super(owner, connector);
+        types = Types.DEFAULT;
+    }
+
+    /**
+     * Reads the metadata. This method should be invoked exactly once after construction.
+     * This work is performed outside the constructor for allowing {@link #close()} method
+     * invocation no matter if this {@code initialize()} method fails.
+     *
+     * @throws DataStoreContentException if the root element is not the expected one.
+     * @throws XMLStreamException if an error occurred while reading the XML file.
      * @throws URISyntaxException if an error occurred while parsing URI in GPX 1.0 metadata.
      * @throws JAXBException if an error occurred while parsing GPX 1.1 metadata.
      * @throws ClassCastException if an object unmarshalled by JAXB was not of the expected
type.
      * @throws DateTimeParseException if a text can not be parsed as a date.
      * @throws EOFException if the file seems to be truncated.
      */
-    public GPXReader(final GPXStore owner, final StorageConnector connector)
-            throws DataStoreException, XMLStreamException, JAXBException, URISyntaxException,
EOFException
-    {
-        super(owner, connector);
-        types = Types.DEFAULT;
+    public void initialize() throws DataStoreException, XMLStreamException, JAXBException,
URISyntaxException, EOFException {
         /*
          * Skip comments, characters, entity declarations, etc. until we find the root element.
          * If that root is anything other than <gpx>, we consider that this is not
a GPX file.
@@ -147,16 +159,14 @@ public class GPXReader extends StaxStrea
         final XMLStreamReader reader = getReader();
         namespace = reader.getNamespaceURI();
         String ver = reader.getAttributeValue(null, Attributes.VERSION);
-        if (ver == null) {
-            version  = null;
-            isLegacy = false;
-        } else {
-            version  = new Version(ver);
-            isLegacy = version.compareTo(GPXStore.V1_0, 2) <= 0;
-            if (version.compareTo(GPXStore.V1_1, 2) > 0) {
+        if (ver != null) {
+            version = new Version(ver);
+            final int c = version.compareTo(GPXStore.V1_0, 2);
+            if (c < 0 || version.compareTo(GPXStore.V1_1, 2) > 0) {
                 throw new DataStoreContentException(errors().getString(
                         Errors.Keys.UnsupportedFormatVersion_2, owner.getFormatName(), version));
             }
+            isLegacy = (c == 0);
         }
         /*
          * Read metadata immediately, from current position until the beginning of way points,
tracks or routes.
@@ -166,7 +176,7 @@ public class GPXReader extends StaxStrea
          *     Those elements are parsed in the switch statement below.
          *
          *   - In GPX 1.1, they are declared in a <metadata> sub-element and their
structure is a little bit
-         *     more elaborated than it was in the previous version. We will use JAXB for
parsing them.
+         *     more elaborated than what it was in the previous version. We will use JAXB
for parsing them.
          */
         while (reader.hasNext()) {
             switch (reader.next()) {

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -119,7 +119,7 @@ public abstract class StaxDataStore exte
      *
      * @param  target  the object for which we are creating (un)marshaller configuration.
      */
-    final Map<String,Object> configuration(final StaxStream target) {
+    final Map<String,Object> configuration(final StaxStreamIO target) {
         final Map<String,Object> properties = new HashMap<>(4);
         if (locale   != null) properties.put(XML.LOCALE,   locale);
         if (timezone != null) properties.put(XML.TIMEZONE, timezone);
@@ -128,7 +128,7 @@ public abstract class StaxDataStore exte
     }
 
     /**
-     * Gives to {@link StaxStream} an access to the {@link #listeners} field.
+     * Gives to {@link StaxStreamIO} an access to the {@link #listeners} field.
      */
     final WarningListeners<DataStore> listeners() {
         return listeners;

Copied: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamIO.java
(from r1774999, sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStream.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamIO.java?p2=sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamIO.java&p1=sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStream.java&r1=1774999&r2=1775000&rev=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStream.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamIO.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -27,14 +27,14 @@ import org.apache.sis.util.resources.Err
 
 /**
  * Common base class for {@code StaxStreamReader} and {@code StaxStreamWriter}.
- * {@code StaxStream} subclasses are not used directly (they are Apache SIS internal mechanic);
+ * {@code StaxStreamIO} subclasses are not used directly (they are Apache SIS internal mechanic);
  * they are rather used as helper classes for {@link org.apache.sis.storage.DataStore} implementations.
  * Those {@code DataStore}s will typically manage {@code StaxStreamReader} and {@code StaxStreamWriter}
  * instances on which they delegate their read and write operations.
  *
  * <div class="section">Multi-threading</div>
  * This class and subclasses are not tread-safe. Synchronization shall be done by the {@code
DataStore}
- * that contains the {@code StaxStream} instances.
+ * that contains the {@code StaxStreamIO} instances.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -42,14 +42,14 @@ import org.apache.sis.util.resources.Err
  * @version 0.8
  * @module
  */
-abstract class StaxStream implements AutoCloseable, WarningListener<Object> {
+abstract class StaxStreamIO implements AutoCloseable, WarningListener<Object> {
     /**
      * The data store for which this reader or writer has been created.
      */
-    final StaxDataStore owner;
+    protected final StaxDataStore owner;
 
     /**
-     * The underlying stream to close when this {@code StaxStream} reader or writer is closed,
+     * The underlying stream to close when this {@code StaxStreamIO} reader or writer is
closed,
      * or {@code null} if none.
      */
     private Closeable stream;
@@ -59,13 +59,13 @@ abstract class StaxStream implements Aut
      *
      * @param owner  the data store for which this reader or writer is created.
      */
-    StaxStream(final StaxDataStore owner) {
+    StaxStreamIO(final StaxDataStore owner) {
         ArgumentChecks.ensureNonNull("owner", owner);
         this.owner = owner;
     }
 
     /**
-     * Notifies this {@code StaxStream} that the given stream will need to be closed by the
{@link #close()} method.
+     * Notifies this {@code StaxStreamIO} that the given stream will need to be closed by
the {@link #close()} method.
      * This method can be invoked at most once. This method does nothing if the given object
does not implement the
      * {@link Closeable} interface.
      *

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -27,7 +27,6 @@ import java.io.InputStream;
 import java.io.IOException;
 import java.io.EOFException;
 import java.net.URISyntaxException;
-import java.time.LocalDate;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLInputFactory;
@@ -54,7 +53,6 @@ import org.apache.sis.util.Classes;
 
 // Branch-dependent imports
 import java.time.temporal.Temporal;
-import java.time.temporal.TemporalAccessor;
 import java.time.format.DateTimeParseException;
 
 
@@ -92,7 +90,7 @@ import java.time.format.DateTimeParseExc
  * @version 0.8
  * @module
  */
-public abstract class StaxStreamReader extends StaxStream implements XMLStreamConstants {
+public abstract class StaxStreamReader extends StaxStreamIO implements XMLStreamConstants
{
     /**
      * The XML stream reader.
      */
@@ -126,12 +124,12 @@ public abstract class StaxStreamReader e
         else if (input instanceof Node)            reader = factory().createXMLStreamReader(new
DOMSource((Node) input));
         else {
             final InputStream in = connector.getStorageAs(InputStream.class);
+            connector.closeAllExcept(in);
             if (in == null) {
                 throw new UnsupportedStorageException(errors().getString(Errors.Keys.IllegalInputTypeForReader_2,
-                                                      owner.getFormatName(), Classes.getClass(input)));
+                        owner.getFormatName(), Classes.getClass(input)));
             }
             reader = factory().createXMLStreamReader(in);
-            connector.closeAllExcept(in);
             initCloseable(in);
             return;
         }
@@ -306,16 +304,7 @@ public abstract class StaxStreamReader e
      * @throws DateTimeParseException if the text can not be parsed as a date.
      */
     protected final Temporal getElementAsTemporal() throws XMLStreamException {
-        final String text = getElementText();
-        if (text != null) {
-            final TemporalAccessor accessor = StandardDateFormat.FORMAT.parse(text);
-            if (accessor instanceof Temporal) {
-                return (Temporal) accessor;
-            }
-            return LocalDate.from(accessor);
-            // TODO: need more extensive check.
-        }
-        return null;
+        return StandardDateFormat.parseBest(getElementText());
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -70,7 +70,7 @@ import org.apache.sis.xml.Namespaces;
  *
  * <div class="section">Multi-threading</div>
  * This class and subclasses are not tread-safe. Synchronization shall be done by the {@code
DataStore}
- * that contains the {@code StaxStream} instances.
+ * that contains the {@code StaxStreamIO} instances.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -78,7 +78,7 @@ import org.apache.sis.xml.Namespaces;
  * @version 0.8
  * @module
  */
-public abstract class StaxStreamWriter extends StaxStream {
+public abstract class StaxStreamWriter extends StaxStreamIO {
     /**
      * The XML stream writer.
      */

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/package-info.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/package-info.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -16,9 +16,10 @@
  */
 
 /**
- * Helper classes for reading and writing XML documents using STAX.
+ * Helper classes for reading and writing XML documents using STAX (Streaming API for XML).
  *
  * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
  * @since   0.8
  * @version 0.8
  * @module

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXReaderTest.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXReaderTest.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import com.esri.core.geometry.Point;
+import java.time.Instant;
 import org.opengis.geometry.Envelope;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.test.TestCase;
@@ -29,7 +30,6 @@ import static org.junit.Assert.*;
 import static org.apache.sis.test.TestUtilities.date;
 
 // Branch-dependent imports
-import java.time.LocalDate;
 import org.opengis.feature.Feature;
 
 
@@ -71,6 +71,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testMetadataRead100() throws Exception {
         try (final GPXReader reader = create("1.0/metadata.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertEquals("Sample", data.name);
@@ -98,6 +99,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testMetadataRead110() throws Exception {
         try (final GPXReader reader = create("1.1/metadata.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertEquals("Sample", data.name);
@@ -130,6 +132,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testWayPointRead100() throws Exception {
         try (final GPXReader reader = create("1.0/waypoint.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -159,6 +162,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testWayPointRead110() throws Exception {
         try (final GPXReader reader = create("1.1/waypoint.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -189,6 +193,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testRouteRead100() throws Exception {
         try (final GPXReader reader = create("1.0/route.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -254,6 +259,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testRouteRead110() throws Exception {
         try (final GPXReader reader = create("1.1/route.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -321,6 +327,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testTrackRead100() throws Exception {
         try (final GPXReader reader = create("1.0/track.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -391,6 +398,7 @@ public final strictfp class GPXReaderTes
     @Test
     public void testTrackRead110() throws Exception {
         try (final GPXReader reader = create("1.1/track.xml")) {
+            reader.initialize();
             final Metadata data = reader.getMetadata();
 
             assertNull(data.name);
@@ -462,7 +470,7 @@ public final strictfp class GPXReaderTes
             assertEquals(15.0,                  ((Point)f.getPropertyValue("@geometry")).getX(),
DELTA);
             assertEquals(10.0,                  ((Point)f.getPropertyValue("@geometry")).getY(),
DELTA);
             assertEquals(140.0,                 f.getPropertyValue("ele"));
-            assertEquals(LocalDate.parse("2010-01-10"),f.getPropertyValue("time"));
+            assertEquals(Instant.parse("2010-01-10T00:00:00Z"), f.getPropertyValue("time"));
             assertEquals(35.0,                  f.getPropertyValue("magvar"));
             assertEquals(112.32,                f.getPropertyValue("geoidheight"));
             assertEquals("first point",         f.getPropertyValue("name"));
@@ -532,7 +540,7 @@ public final strictfp class GPXReaderTes
             assertEquals(35.0,                  ((Point) f.getPropertyValue("@geometry")).getX(),
DELTA);
             assertEquals(30.0,                  ((Point) f.getPropertyValue("@geometry")).getY(),
DELTA);
             assertEquals(150.0,                 f.getPropertyValue("ele"));
-            assertEquals(LocalDate.parse("2010-01-30"),f.getPropertyValue("time"));
+            assertEquals(Instant.parse("2010-01-30T00:00:00Z"), f.getPropertyValue("time"));
             assertEquals(25.0,                  f.getPropertyValue("magvar"));
             assertEquals(142.32,                f.getPropertyValue("geoidheight"));
             assertEquals("third point",         f.getPropertyValue("name"));

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java?rev=1775000&r1=1774999&r2=1775000&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java
[UTF-8] Mon Dec 19 08:06:38 2016
@@ -101,6 +101,7 @@ public final strictfp class GPXWriterTes
         writer.close();
 
         try (GPXReader reader = reader(f)) {
+            reader.initialize();
             assertEquals(metaData, reader.getMetadata());
         }
 
@@ -260,22 +261,19 @@ public final strictfp class GPXWriterTes
         writer.writeEndDocument();
         writer.close();
 
-        final GPXReader reader = reader(f);
-
-        //testing on toString since JTS geometry always fail on equals method.
-        assertEquals(point1.toString(), reader.next().toString());
-        assertEquals(point2.toString(), reader.next().toString());
-        assertEquals(point3.toString(), reader.next().toString());
-        assertEquals(route1.toString(), reader.next().toString());
-        assertEquals(route2.toString(), reader.next().toString());
-        assertEquals(track1.toString(), reader.next().toString());
-        assertEquals(track2.toString(), reader.next().toString());
-        assertFalse(reader.hasNext());
-
-        reader.close();
+        try (final GPXReader reader = reader(f)) {
+            reader.initialize();
 
+            //testing on toString since JTS geometry always fail on equals method.
+            assertEquals(point1.toString(), reader.next().toString());
+            assertEquals(point2.toString(), reader.next().toString());
+            assertEquals(point3.toString(), reader.next().toString());
+            assertEquals(route1.toString(), reader.next().toString());
+            assertEquals(route2.toString(), reader.next().toString());
+            assertEquals(track1.toString(), reader.next().toString());
+            assertEquals(track2.toString(), reader.next().toString());
+            assertFalse(reader.hasNext());
+        }
         if (f.exists()) f.delete();
     }
-
-
 }



Mime
View raw message