You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/06/25 23:41:41 UTC
svn commit: r1496644 - in /sis/branches/JDK7/core:
sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/
sis-utility/src/main/java/org/apache/sis/internal/jaxb/
sis-utility/src/test/java/org/apache/sis/internal/jaxb/
sis-utility/src/test/java/or...
Author: desruisseaux
Date: Tue Jun 25 21:41:41 2013
New Revision: 1496644
URL: http://svn.apache.org/r1496644
Log:
TimePeriodTest must fix the timezone of its test.
Added:
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java (with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
Modified: 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=1496644&r1=1496643&r2=1496644&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java [UTF-8] Tue Jun 25 21:41:41 2013
@@ -16,6 +16,7 @@
*/
package org.apache.sis.internal.jaxb.gml;
+import java.util.Locale;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.Marshaller;
@@ -24,7 +25,7 @@ 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.apache.sis.test.XMLTestCase;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
@@ -43,7 +44,7 @@ import static org.apache.sis.test.TestUt
* @version 0.3
* @module
*/
-public final strictfp class TimePeriodTest extends TestCase {
+public final strictfp class TimePeriodTest extends XMLTestCase {
/**
* The XML marshaller.
*/
@@ -90,13 +91,14 @@ public final strictfp class TimePeriodTe
}
/**
- * Tests time instant.
+ * Tests time instant. The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
* @throws DatatypeConfigurationException Should never happen.
*/
@Test
public void testTimeInstant() throws JAXBException, DatatypeConfigurationException {
+ createContext(false, Locale.FRANCE, "CET");
final String expected =
"<gml:TimeInstant>\n" +
" <gml:timePosition>1992-01-01T01:00:00.000+01:00</gml:timePosition>\n" +
@@ -111,11 +113,13 @@ public final strictfp class TimePeriodTe
/**
* Tests a time period using the GML 2 syntax.
+ * The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
*/
@Test
public void testPeriodGML2() throws JAXBException {
+ createContext(false, Locale.FRANCE, "CET");
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" +
@@ -135,12 +139,14 @@ public final strictfp class TimePeriodTe
/**
* Tests a time period using GML2 or GML3 syntax. This method is used for the
* implementation of {@link #testPeriodGML2()} and {@link #testPeriodGML3()}.
+ * The test is executed using an arbitrary locale and timezone.
*
* @param expected The expected string.
*/
private void testPeriod(final TimePeriodBound begin, final TimePeriodBound end,
final String expected, final boolean verifyValues) throws JAXBException
{
+ createContext(false, Locale.FRANCE, "CET");
final TimePeriod period = new TimePeriod();
period.begin = begin;
period.end = end;
@@ -156,11 +162,13 @@ public final strictfp class TimePeriodTe
/**
* Tests a time period using the GML 3 syntax.
+ * The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
*/
@Test
public void testPeriodGML3() throws JAXBException {
+ createContext(false, Locale.FRANCE, "CET");
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" +
@@ -170,13 +178,14 @@ public final strictfp class TimePeriodTe
}
/**
- * Same test than {@link #testPeriodGML3()}, but with simplified date format
- * (omit the hours and timezone)
+ * Same test than {@link #testPeriodGML3()}, but with simplified date format (omit the hours and timezone)
+ * The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
*/
@Test
public void testSimplifiedPeriodGML3() throws JAXBException {
+ createContext(false, Locale.FRANCE, "CET");
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" +
@@ -186,12 +195,14 @@ public final strictfp class TimePeriodTe
}
/**
- * Same test than {@link #testSimplifiedPeriodGML3()}, but without begining boundary.
+ * Same test than {@link #testSimplifiedPeriodGML3()}, but without beginning boundary.
+ * The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
*/
@Test
public void testBeforePeriodGML3() throws JAXBException {
+ createContext(false, Locale.FRANCE, "CET");
testPeriod(new TimePeriodBound.GML3(null, "before"),
new TimePeriodBound.GML3(new DummyInstant(date("2007-12-30 23:00:00")), "after"),
"<gml:TimePeriod>\n" +
@@ -202,11 +213,13 @@ public final strictfp class TimePeriodTe
/**
* Same test than {@link #testSimplifiedPeriodGML3()}, but without end boundary.
+ * The test is executed using an arbitrary locale and timezone.
*
* @throws JAXBException If an error occurred while marshalling.
*/
@Test
public void testAfterPeriodGML3() throws JAXBException {
+ createContext(false, Locale.FRANCE, "CET");
testPeriod(new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01 23:00:00")), "before"),
new TimePeriodBound.GML3(null, "after"),
"<gml:TimePeriod>\n" +
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java?rev=1496644&r1=1496643&r2=1496644&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java [UTF-8] Tue Jun 25 21:41:41 2013
@@ -137,7 +137,7 @@ public final class Context extends Marsh
* }
* }
*
- * @param bitMasks A combination of {@link #MARSHALLING}, {@code #SUBSTITUTE_*} or other bit masks.
+ * @param bitMasks A combination of {@link #MARSHALLING}, {@code SUBSTITUTE_*} or other bit masks.
* @param locale The locale, or {@code null} if unspecified.
* @param timezone The timezone, or {@code null} if unspecified.
* @param schemas The schemas root URL, or {@code null} if none.
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java?rev=1496644&r1=1496643&r2=1496644&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java [UTF-8] Tue Jun 25 21:41:41 2013
@@ -18,10 +18,9 @@ package org.apache.sis.internal.jaxb;
import java.util.Date;
import java.util.Locale;
-import java.util.TimeZone;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
-import org.apache.sis.test.TestCase;
+import org.apache.sis.test.XMLTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -36,7 +35,7 @@ import static javax.xml.datatype.Datatyp
* @version 0.3
* @module
*/
-public final strictfp class XmlUtilitiesTest extends TestCase {
+public final strictfp class XmlUtilitiesTest extends XMLTestCase {
/**
* Tests the {@link XmlUtilities#toXML} method.
* This test arbitrarily uses the CET timezone.
@@ -45,13 +44,8 @@ public final strictfp class XmlUtilities
*/
@Test
public void testToXML() throws DatatypeConfigurationException {
- final Context context = new Context(0, Locale.FRENCH, TimeZone.getTimeZone("CET"), null, null, null, null, null);
- final XMLGregorianCalendar calendar;
- try {
- calendar = XmlUtilities.toXML(context, new Date(1230786000000L));
- } finally {
- context.finish();
- }
+ createContext(false, Locale.FRANCE, "CET");
+ final XMLGregorianCalendar calendar = XmlUtilities.toXML(context, new Date(1230786000000L));
assertEquals("2009-01-01T06:00:00.000+01:00", calendar.toString());
calendar.setMillisecond(FIELD_UNDEFINED);
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java?rev=1496644&r1=1496643&r2=1496644&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java [UTF-8] Tue Jun 25 21:41:41 2013
@@ -17,13 +17,12 @@
package org.apache.sis.internal.jaxb.gco;
import java.util.UUID;
-import org.apache.sis.internal.jaxb.Context;
import org.apache.sis.util.iso.SimpleInternationalString;
import org.apache.sis.xml.XLink;
import org.apache.sis.xml.IdentifierSpace;
import org.apache.sis.xml.ReferenceResolverMock;
import org.apache.sis.test.DependsOn;
-import org.apache.sis.test.TestCase;
+import org.apache.sis.test.XMLTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -38,7 +37,7 @@ import static org.junit.Assert.*;
* @module
*/
@DependsOn(org.apache.sis.internal.jaxb.IdentifierMapAdapterTest.class)
-public final strictfp class PropertyTypeTest extends TestCase {
+public final strictfp class PropertyTypeTest extends XMLTestCase {
/**
* The pseudo-metadata object to wrap for testing purpose.
*/
@@ -108,13 +107,8 @@ public final strictfp class PropertyType
public void testWithUUID() throws Exception {
final UUID uuid = UUID.randomUUID();
metadata.getIdentifierMap().putSpecialized(IdentifierSpace.UUID, uuid);
- final Context context = ReferenceResolverMock.begin(true);
- final PropertyTypeMock property;
- try {
- property = marshal();
- } finally {
- context.finish();
- }
+ context = ReferenceResolverMock.begin(true);
+ final PropertyTypeMock property = marshal();
assertSame (metadata, property.metadata);
assertNull ("nilReason", property.getNilReason());
assertEquals(uuid.toString(), property.getUUIDREF());
@@ -146,13 +140,8 @@ public final strictfp class PropertyType
public void testWithXLink() throws Exception {
final XLink link = createXLink();
metadata.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, link);
- final Context context = ReferenceResolverMock.begin(true);
- final PropertyTypeMock property;
- try {
- property = marshal();
- } finally {
- context.finish();
- }
+ context = ReferenceResolverMock.begin(true);
+ final PropertyTypeMock property = marshal();
assertSame (metadata, property.metadata);
assertNull ("nilReason", property.getNilReason());
assertNull ("uuidref", property.getUUIDREF());
Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java?rev=1496644&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8] Tue Jun 25 21:41:41 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.test;
+
+import java.util.Locale;
+import java.util.TimeZone;
+import org.apache.sis.internal.jaxb.Context;
+import org.junit.After;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Base class of XML (un)marshalling tests. SIS (un)marshalling process can be partially controlled
+ * by a {@link Context}, which defines (among other) the locale and timezone. Some tests will need
+ * to fix the context to a particular locale and timezone before to execute the test.
+ *
+ * <p>The {@link #context} field can be initialized by subclasses either explicitely or by invoking
+ * a {@code createContext(…)} convenience method. The {@link #clearContext()} method will be invoked
+ * after each test for clearing the SIS internal {@link ThreadLocal} which was holding that context.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+public abstract strictfp class XMLTestCase extends TestCase {
+ /**
+ * The context containing locale, timezone, GML version and other information.
+ * The context is initially {@code null} and can be created either explicitely,
+ * or by invoking the {@link #createContext(boolean, Locale, String)} convenience method.
+ *
+ * @see #createContext(boolean, Locale, String)
+ * @see #clearContext()
+ */
+ protected Context context;
+
+ /**
+ * Creates a new test case.
+ */
+ protected XMLTestCase() {
+ }
+
+ /**
+ * Initializes the {@link #context} to the given locale and timezone.
+ *
+ * @param marshal {@code true} for setting the {@link Context#MARSHALLING} flag.
+ * @param locale The locale, or {@code null} for the default.
+ * @param timezone The timezone, or {@code null} for the default.
+ *
+ * @see #clearContext()
+ */
+ protected final void createContext(final boolean marshal, final Locale locale, final String timezone) {
+ context = new Context(marshal ? Context.MARSHALLING : 0, locale,
+ (timezone != null) ? TimeZone.getTimeZone(timezone) : null, null, null, null, null, null);
+ }
+
+ /**
+ * Resets {@link #context} to {@code null} and clears the {@link ThreadLocal} which was holding that context.
+ * This method is automatically invoked by JUnit after each test, but can also be invoked explicitely before
+ * to create a new context. It is safe to invoke this method more than once.
+ */
+ @After
+ public final void clearContext() {
+ assertSame("Unexpected context. Is this method invoked from the right thread?", context, Context.current());
+ if (context != null) {
+ context.finish();
+ context = null;
+ }
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8