sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1496560 - in /sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis: internal/jaxb/ internal/jaxb/gml/ internal/jaxb/gml/DummyInstant.java internal/jaxb/gml/TimePeriodTest.java test/suite/MetadataTestSuite.java
Date Tue, 25 Jun 2013 17:52:09 GMT
Author: desruisseaux
Date: Tue Jun 25 17:52:09 2013
New Revision: 1496560

URL: http://svn.apache.org/r1496560
Log:
Added a few tests.

Added:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
  (with props)
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java?rev=1496560&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
[UTF-8] Tue Jun 25 17:52:09 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.jaxb.gml;
+
+import java.sql.Time;
+import java.util.Date;
+import java.util.Collection;
+import java.util.Collections;
+import org.opengis.temporal.Instant;
+import org.opengis.temporal.Period;
+import org.opengis.temporal.Duration;
+import org.opengis.temporal.Position;
+import org.opengis.temporal.RelativePosition;
+import org.opengis.temporal.TemporalPosition;
+import org.opengis.temporal.TemporalPrimitive;
+import org.opengis.temporal.TemporalGeometricPrimitive;
+import org.opengis.util.InternationalString;
+
+
+/**
+ * A dummy {@link Instant} implementation, for testing the JAXB elements without dependency
+ * toward the {@code sis-temporal} module.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.20)
+ * @version 0.3
+ * @module
+ */
+final class DummyInstant implements Instant, Position {
+    /**
+     * The time, in milliseconds elapsed since January 1st, 1970.
+     */
+    private final long time;
+
+    /**
+     * Creates a new instant initialized to the given value.
+     */
+    DummyInstant(final Date time) {
+        this.time = time.getTime();
+    }
+
+    /**
+     * Returns the date of this instant object.
+     */
+    @Override
+    public Date getDate() {
+        return new Date(time);
+    }
+
+    /**
+     * Returns the position, which is {@code this}.
+     */
+    @Override
+    public Position getPosition() {
+        return this;
+    }
+
+    /**
+     * Empty properties.
+     */
+    @Override public Time                getTime()     {return null;}
+    @Override public InternationalString getDateTime() {return null;}
+    @Override public TemporalPosition    anyOther()    {return null;}
+    @Override public Collection<Period>  getBegunBy()  {return Collections.emptySet();}
+    @Override public Collection<Period>  getEndedBy()  {return Collections.emptySet();}
+    @Override public Duration            length()      {return null;}
+
+    /**
+     * Unsupported operations.
+     */
+    @Override public RelativePosition relativePosition(TemporalPrimitive  other) {throw new
UnsupportedOperationException();}
+    @Override public Duration         distance(TemporalGeometricPrimitive other) {throw new
UnsupportedOperationException();}
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java?rev=1496560&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
[UTF-8] Tue Jun 25 17:52:09 2013
@@ -0,0 +1,217 @@
+/*
+ * 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.jaxb.gml;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.datatype.DatatypeConfigurationException;
+import org.apache.sis.internal.jaxb.XmlUtilities;
+import org.apache.sis.test.TestCase;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+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.format;
+
+
+/**
+ * Tests the {@link TimePeriod} class. The XML fragments used in this test cases are derived
from
+ * <a href="http://toyoda-eizi.blogspot.fr/2011/02/examples-of-gml-fragment-in-iso.html">here</a>.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.19)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class TimePeriodTest extends TestCase {
+    /**
+     * The XML marshaller.
+     */
+    private static Marshaller marshaller;
+
+    /**
+     * The XML unmarshaller.
+     */
+    private static Unmarshaller unmarshaller;
+
+    /**
+     * A buffer where to marshal.
+     */
+    private final StringWriter buffer = new StringWriter();
+
+    /**
+     * Creates the XML marshaller to be shared by all test methods.
+     *
+     * @throws JAXBException If an error occurred while creating the marshaller.
+     */
+    @BeforeClass
+    public static void createMarshallers() throws JAXBException {
+        final JAXBContext context = JAXBContext.newInstance(TimeInstant.class, TimePeriod.class);
+        marshaller   = context.createMarshaller();
+        unmarshaller = context.createUnmarshaller();
+    }
+
+    /**
+     * Allows the garbage collector to collect the marshaller and unmarshallers.
+     */
+    @AfterClass
+    public static void disposeMarshallers() {
+        marshaller   = null;
+        unmarshaller = null;
+    }
+
+    /**
+     * Creates a new time instant for the given date.
+     */
+    private static TimeInstant createTimeInstant(final String date) throws DatatypeConfigurationException
{
+        final TimeInstant instant = new TimeInstant();
+        instant.timePosition = XmlUtilities.toXML(null, date(date));
+        return instant;
+    }
+
+    /**
+     * Tests time instant.
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     * @throws DatatypeConfigurationException Should never happen.
+     */
+    @Test
+    public void testTimeInstant() throws JAXBException, DatatypeConfigurationException {
+        final String expected =
+            "<gml:TimeInstant>\n" +
+            "  <gml:timePosition>1992-01-01T01:00:00.000+01:00</gml:timePosition>\n"
+
+            "</gml:TimeInstant>\n";
+        final TimeInstant instant = createTimeInstant("1992-01-01 00:00:00");
+        marshaller.marshal(instant, buffer);
+        final String actual = buffer.toString();
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+        final TimeInstant test = (TimeInstant) unmarshaller.unmarshal(new StringReader(actual));
+        assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(test.timePosition)));
+    }
+
+    /**
+     * Tests a time period using the GML 2 syntax.
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     */
+    @Test
+    public void testPeriodGML2() throws JAXBException {
+        testPeriod(new TimePeriodBound.GML2(new DummyInstant(date("1992-01-01 00:00:00"))),
+                   new TimePeriodBound.GML2(new DummyInstant(date("2007-12-31 00:00:00"))),
+            "<gml:TimePeriod>\n" +
+            "  <gml:begin>\n" +
+            "    <gml:TimeInstant>\n" +
+            "      <gml:timePosition>1992-01-01T01:00:00+01:00</gml:timePosition>\n"
+
+            "    </gml:TimeInstant>\n" +
+            "  </gml:begin>\n" +
+            "  <gml:end>\n" +
+            "    <gml:TimeInstant>\n" +
+            "      <gml:timePosition>2007-12-31T01:00:00+01:00</gml:timePosition>\n"
+
+            "    </gml:TimeInstant>\n" +
+            "  </gml:end>\n" +
+            "</gml:TimePeriod>\n", true);
+    }
+
+    /**
+     * Tests a time period using GML2 or GML3 syntax. This method is used for the
+     * implementation of {@link #testPeriodGML2()} and {@link #testPeriodGML3()}.
+     *
+     * @param expected The expected string.
+     */
+    private void testPeriod(final TimePeriodBound begin, final TimePeriodBound end,
+            final String expected, final boolean verifyValues) throws JAXBException
+    {
+        final TimePeriod period = new TimePeriod();
+        period.begin = begin;
+        period.end   = end;
+        marshaller.marshal(period, buffer);
+        final String actual = buffer.toString();
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+        final TimePeriod test = (TimePeriod) unmarshaller.unmarshal(new StringReader(actual));
+        if (verifyValues) {
+            assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(test.begin.calendar())));
+            assertEquals("2007-12-31 00:00:00", format(XmlUtilities.toDate(test.end  .calendar())));
+        }
+    }
+
+    /**
+     * Tests a time period using the GML 3 syntax.
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     */
+    @Test
+    public void testPeriodGML3() throws JAXBException {
+        testPeriod(new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01 00:00:00")),
"before"),
+                   new TimePeriodBound.GML3(new DummyInstant(date("2007-12-31 00:00:00")),
"after"),
+            "<gml:TimePeriod>\n" +
+            "  <gml:beginPosition>1992-01-01T01:00:00+01:00</gml:beginPosition>\n"
+
+            "  <gml:endPosition>2007-12-31T01:00:00+01:00</gml:endPosition>\n"
+
+            "</gml:TimePeriod>\n", true);
+    }
+
+    /**
+     * Same test than {@link #testPeriodGML3()}, but with simplified date format
+     * (omit the hours and timezone)
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     */
+    @Test
+    public void testSimplifiedPeriodGML3() throws JAXBException {
+        testPeriod(new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01 23:00:00")),
"before"),
+                   new TimePeriodBound.GML3(new DummyInstant(date("2007-12-30 23:00:00")),
"after"),
+            "<gml:TimePeriod>\n" +
+            "  <gml:beginPosition>1992-01-02</gml:beginPosition>\n" +
+            "  <gml:endPosition>2007-12-31</gml:endPosition>\n" +
+            "</gml:TimePeriod>\n", false);
+    }
+
+    /**
+     * Same test than {@link #testSimplifiedPeriodGML3()}, but without begining boundary.
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     */
+    @Test
+    public void testBeforePeriodGML3() throws JAXBException {
+        testPeriod(new TimePeriodBound.GML3(null, "before"),
+                   new TimePeriodBound.GML3(new DummyInstant(date("2007-12-30 23:00:00")),
"after"),
+            "<gml:TimePeriod>\n" +
+            "  <gml:beginPosition indeterminatePosition=\"before\"/>\n" +
+            "  <gml:endPosition>2007-12-31</gml:endPosition>\n" +
+            "</gml:TimePeriod>\n", false);
+    }
+
+    /**
+     * Same test than {@link #testSimplifiedPeriodGML3()}, but without end boundary.
+     *
+     * @throws JAXBException If an error occurred while marshalling.
+     */
+    @Test
+    public void testAfterPeriodGML3() throws JAXBException {
+        testPeriod(new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01 23:00:00")),
"before"),
+                   new TimePeriodBound.GML3(null, "after"),
+            "<gml:TimePeriod>\n" +
+            "  <gml:beginPosition>1992-01-02</gml:beginPosition>\n" +
+            "  <gml:endPosition indeterminatePosition=\"after\"/>\n" +
+            "</gml:TimePeriod>\n", false);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1496560&r1=1496559&r2=1496560&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Tue Jun 25 17:52:09 2013
@@ -53,7 +53,10 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.MetadataStandardTest.class,
     org.apache.sis.metadata.PrunerTest.class,
     org.apache.sis.metadata.AbstractMetadataTest.class,
-    org.apache.sis.metadata.iso.AllMetadataTest.class
+    org.apache.sis.metadata.iso.AllMetadataTest.class,
+
+    // XML marshalling
+    org.apache.sis.internal.jaxb.gml.TimePeriodTest.class
 })
 public final strictfp class MetadataTestSuite extends TestSuite {
     /**



Mime
View raw message