Author: desruisseaux
Date: Fri Jun 28 21:18:43 2013
New Revision: 1497927
URL: http://svn.apache.org/r1497927
Log:
Added more tests.
Added:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
(with props)
sis/branches/JDK7/core/sis-metadata/src/test/resources/
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
(with props)
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
(with props)
sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml (with
props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
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=1497927&r1=1497926&r2=1497927&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] Fri Jun 28 21:18:43 2013
@@ -63,7 +63,8 @@ import org.junit.BeforeClass;
org.apache.sis.xml.NilReasonMarshallingTest.class,
org.apache.sis.xml.AnchorMarshallingTest.class,
org.apache.sis.xml.ObjectReferenceMarshallingTest.class,
- org.apache.sis.xml.CustomMetadataTest.class
+ org.apache.sis.xml.CustomMetadataTest.class,
+ org.apache.sis.xml.MetadataMarshallingTest.class
})
public final strictfp class MetadataTestSuite extends TestSuite {
/**
Added:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java?rev=1497927&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
(added)
+++
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
[UTF-8] Fri Jun 28 21:18:43 2013
@@ -0,0 +1,171 @@
+/*
+ * 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.xml;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+import java.net.URL;
+import java.io.IOException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.JAXBException;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.lineage.DefaultProcessing;
+import org.apache.sis.metadata.iso.lineage.DefaultProcessStep;
+import org.apache.sis.metadata.iso.quality.AbstractElement;
+import org.apache.sis.metadata.iso.quality.DefaultConformanceResult;
+import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
+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.getSingleton;
+
+
+/**
+ * Tests XML (un)marshalling of various metadata objects.
+ * For every metadata objects tested by this class, the expected XML
representation
+ * is provided by {@code *.xml} files in the <a href="{@scmUrl
gmd-data}/">here</a>.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(FreeTextMarshallingTest.class)
+public final strictfp class MetadataMarshallingTest extends XMLTestCase {
+ /**
+ * A poll of configured {@link Marshaller} and {@link Unmarshaller},
created when first needed.
+ */
+ private static MarshallerPool pool;
+
+ /**
+ * Creates the XML (un)marshaller pool to be shared by all test methods.
+ * The (un)marshallers locale and timezone will be set to fixed values.
+ *
+ * @throws JAXBException If an error occurred while creating the pool.
+ *
+ * @see #disposeMarshallerPool()
+ */
+ @BeforeClass
+ public static void createMarshallerPool() throws JAXBException {
+ final Map<String,Object> properties = new HashMap<>(4);
+ assertNull(properties.put(XML.LOCALE, Locale.ENGLISH));
+ assertNull(properties.put(XML.TIMEZONE, "CET"));
+ pool = new MarshallerPool(properties);
+ }
+
+ /**
+ * Invoked by JUnit after the execution of every tests in order to dispose
+ * the {@link MarshallerPool} instance used internally by this class.
+ */
+ @AfterClass
+ public static void disposeMarshallerPool() {
+ pool = null;
+ }
+
+ /**
+ * Returns the URL to the XML file of the given name.
+ *
+ * @param filename The name of the XML file.
+ * @return The URL to the given XML file.
+ */
+ private URL getResource(final String filename) {
+ final URL resource =
MetadataMarshallingTest.class.getResource(filename);
+ assertNotNull(filename, resource);
+ return resource;
+ }
+
+ /**
+ * Tests the (un)marshalling of a text group with a default {@code
<gco:CharacterString>} element.
+ * This test is somewhat a duplicate of {@link FreeTextMarshallingTest},
but the context is more
+ * elaborated.
+ *
+ * <p><b>XML test file:</b>
+ * <a href="{@scmUrl
gmd-data}/PositionalAccuracy.xml">PositionalAccuracy.xml</a></p>
+ *
+ * @throws IOException If an error occurred while reading the XML file.
+ * @throws JAXBException If an error occurred during the during
marshalling / unmarshalling processes.
+ *
+ * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-107">GEOTK-107</a>
+ * @see FreeTextMarshallingTest
+ */
+ @Test
+ public void testPositionalAccuracy() throws IOException, JAXBException {
+ final Marshaller marshaller = pool.acquireMarshaller();
+ final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+ final URL resource =
getResource("PositionalAccuracy.xml");
+ final Object metadata = XML.unmarshal(resource);
+ assertInstanceOf("PositionalAccuracy.xml", AbstractElement.class,
metadata);
+ final InternationalString nameOfMeasure =
getSingleton(((AbstractElement) metadata).getNamesOfMeasure());
+ /*
+ * Programmatic verification of the text group.
+ */
+ assertEquals("Quantitative quality measure focusing on the effective
class percent "
+ + "regarded to the total surface size",
nameOfMeasure.toString(Locale.ENGLISH));
+ assertEquals("Mesure qualité quantitative de type pourcentage de
représentation de la "
+ + "classe par rapport à la surface totale",
nameOfMeasure.toString(Locale.FRENCH));
+ /*
+ * Opportunist test. While it was not the purpose of this test, the
above metadata
+ * needs to contain a "result" element in order to pass XML validation
test.
+ */
+ assertInstanceOf("Wrong value for <gmd:result>",
DefaultConformanceResult.class,
+ getSingleton(((AbstractElement) metadata).getResults()));
+ /*
+ * Final comparison: ensure that we didn't lost any information, then
release.
+ */
+ assertXmlEquals(resource, marshal(marshaller, metadata), "xmlns:*",
"xsi:schemaLocation", "xsi:type");
+ pool.recycle(unmarshaller);
+ pool.recycle(marshaller);
+ }
+
+ /**
+ * Tests the (un)marshalling of a metadata mixing elements from ISO 19115
and ISO 19115-2 standards.
+ *
+ * <p><b>XML test file:</b>
+ * <a href="{@scmUrl gmd-data}/ProcessStep.xml">ProcessStep.xml</a></p>
+ *
+ * @throws IOException If an error occurred while reading the XML file.
+ * @throws JAXBException If an error occurred during the during
marshalling / unmarshalling processes.
+ */
+ @Test
+ public void testProcessStep() throws IOException, JAXBException {
+ final Marshaller marshaller = pool.acquireMarshaller();
+ final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+ final DefaultProcessing processing = new DefaultProcessing();
+ final DefaultProcessStep processStep = new DefaultProcessStep("Some
process step.");
+ processing.setProcedureDescription(new SimpleInternationalString("Some
procedure."));
+ processStep.setProcessingInformation(processing);
+ /*
+ * XML marshalling, and compare with the content of "ProcessStep.xml"
file.
+ */
+ final String xml = marshal(marshaller, processStep);
+ assertTrue(xml.startsWith("<?xml"));
+ assertXmlEquals(getResource("ProcessStep.xml"), xml, "xmlns:*",
"xsi:schemaLocation");
+ /*
+ * Final comparison: ensure that we didn't lost any information, then
release.
+ */
+ assertEquals(processStep, unmarshal(unmarshaller, xml));
+ pool.recycle(unmarshaller);
+ pool.recycle(marshaller);
+ }
+}
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml?rev=1497927&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
(added)
+++
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
Fri Jun 28 21:18:43 2013
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ 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.
+-->
+
+<gmd:DQ_RelativeInternalPositionalAccuracy
+ xmlns:gmd = "http://www.isotc211.org/2005/gmd"
+ xmlns:gco = "http://www.isotc211.org/2005/gco"
+ xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation = "http://www.isotc211.org/2005/gmd
http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
+
+ <!-- The <nameOfMeasure> element below is the main purpose of
MetadataMarshallingTest.testPositionalAccuracy().
+ The <result> element was added only in order to allow validation of
this XML file, with the addition of an
+ opportunist check of xsi:type declaration. -->
+
+ <gmd:nameOfMeasure xsi:type="gmd:PT_FreeText_PropertyType">
+ <gco:CharacterString>Quantitative quality measure focusing on the
effective class percent regarded to the total surface size</gco:CharacterString>
+ <gmd:PT_FreeText>
+ <gmd:textGroup>
+ <gmd:LocalisedCharacterString locale="#locale-fra">Mesure qualité
quantitative de type pourcentage de représentation de la classe par rapport Ã
la surface totale</gmd:LocalisedCharacterString>
+ </gmd:textGroup>
+ </gmd:PT_FreeText>
+ </gmd:nameOfMeasure>
+ <gmd:result>
+ <!-- The xsi:type declaration below is useless, but we put it
+ in order to test that it does not break unmarshalling. -->
+ <gmd:DQ_ConformanceResult xsi:type="gmd:DQ_ConformanceResult_Type">
+ <gmd:specification>
+ <gmd:CI_Citation>
+ <gmd:title>
+ <gco:CharacterString>Some documentation for a conformance
test.</gco:CharacterString>
+ </gmd:title>
+ <gmd:date>
+ <gmd:CI_Date>
+ <gmd:date>
+ <!-- Dummy date for the purpose of this test. -->
+ <gco:DateTime>2009-08-12T19:40:17.653+02:00</gco:DateTime>
+ </gmd:date>
+ <gmd:dateType>
+ <gmd:CI_DateTypeCode
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="creation">Creation</gmd:CI_DateTypeCode>
+ </gmd:dateType>
+ </gmd:CI_Date>
+ </gmd:date>
+ </gmd:CI_Citation>
+ </gmd:specification>
+ <gmd:explanation>
+ <gco:CharacterString>We should explain here what a test conformance
means.</gco:CharacterString>
+ </gmd:explanation>
+ <gmd:pass>
+ <gco:Boolean>true</gco:Boolean>
+ </gmd:pass>
+ </gmd:DQ_ConformanceResult>
+ </gmd:result>
+</gmd:DQ_RelativeInternalPositionalAccuracy>
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml?rev=1497927&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
(added)
+++
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
Fri Jun 28 21:18:43 2013
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ 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.
+-->
+
+<gmd:LI_ProcessStep
+ xmlns:gmd = "http://www.isotc211.org/2005/gmd"
+ xmlns:gco = "http://www.isotc211.org/2005/gco"
+ xmlns:gmi = "http://www.isotc211.org/2005/gmi"
+ xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation = "http://www.isotc211.org/2005/gmd
http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
+
+ <!-- As of February 2011, there is not yet any XSD schema for the "gmi"
namespace on the
+ OGC web site. Consequently the validation of this file does not work
fully yet. -->
+
+ <gmd:description>
+ <gco:CharacterString>Some process step.</gco:CharacterString>
+ </gmd:description>
+ <gmi:processingInformation>
+ <gmi:LE_Processing>
+ <gmi:procedureDescription>
+ <gco:CharacterString>Some procedure.</gco:CharacterString>
+ </gmi:procedureDescription>
+ </gmi:LE_Processing>
+ </gmi:processingInformation>
+</gmd:LI_ProcessStep>
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java?rev=1497927&r1=1497926&r2=1497927&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
[UTF-8] Fri Jun 28 21:18:43 2013
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Locale;
import java.util.TimeZone;
import java.util.logging.LogRecord; // For javadoc
+import java.net.URL;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
@@ -35,6 +36,8 @@ import org.apache.sis.internal.system.Mo
import org.apache.sis.internal.system.SystemListener;
import org.apache.sis.internal.jaxb.TypeRegistration;
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+
/**
* Provides convenience methods for marshalling and unmarshalling SIS objects.
@@ -331,6 +334,7 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the marshalling.
*/
public static String marshal(final Object object) throws JAXBException {
+ ensureNonNull("object", object);
final StringWriter output = new StringWriter();
final MarshallerPool pool = getPool();
final Marshaller marshaller = pool.acquireMarshaller();
@@ -347,6 +351,8 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the marshalling.
*/
public static void marshal(final Object object, final OutputStream output)
throws JAXBException {
+ ensureNonNull("object", object);
+ ensureNonNull("output", output);
final MarshallerPool pool = getPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.marshal(object, output);
@@ -361,6 +367,8 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the marshalling.
*/
public static void marshal(final Object object, final File output) throws
JAXBException {
+ ensureNonNull("object", object);
+ ensureNonNull("output", output);
final MarshallerPool pool = getPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.marshal(object, output);
@@ -375,6 +383,7 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the unmarshalling.
*/
public static Object unmarshal(final String input) throws JAXBException {
+ ensureNonNull("input", input);
final StringReader in = new StringReader(input);
final MarshallerPool pool = getPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
@@ -391,6 +400,23 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the unmarshalling.
*/
public static Object unmarshal(final InputStream input) throws
JAXBException {
+ ensureNonNull("input", input);
+ final MarshallerPool pool = getPool();
+ final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+ final Object object = unmarshaller.unmarshal(input);
+ pool.recycle(unmarshaller);
+ return object;
+ }
+
+ /**
+ * Unmarshall an object from the given URL.
+ *
+ * @param input The URL from which to read a XML representation.
+ * @return The object unmarshalled from the given input.
+ * @throws JAXBException If an error occurred during the unmarshalling.
+ */
+ public static Object unmarshal(final URL input) throws JAXBException {
+ ensureNonNull("input", input);
final MarshallerPool pool = getPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
final Object object = unmarshaller.unmarshal(input);
@@ -406,6 +432,7 @@ public final class XML extends Static {
* @throws JAXBException If an error occurred during the unmarshalling.
*/
public static Object unmarshal(final File input) throws JAXBException {
+ ensureNonNull("input", input);
final MarshallerPool pool = getPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
final Object object = unmarshaller.unmarshal(input);
Added: sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml?rev=1497927&view=auto
==============================================================================
--- sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml (added)
+++ sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml Fri Jun 28
21:18:43 2013
@@ -0,0 +1 @@
+link ../../../../../core/sis-metadata/src/test/resources/org/apache/sis/xml/
\ No newline at end of file
Propchange: sis/branches/JDK7/ide-project/resources-links/org/apache/sis/xml
------------------------------------------------------------------------------
svn:special = *