Author: desruisseaux Date: Mon Jan 1 20:06:53 2018 New Revision: 1819783 URL: http://svn.apache.org/viewvc?rev=1819783&view=rev Log: Commit d06b69194a9e3a35062212c1a4530f84088c9cad from Image Matter (update XMLTestCase class) The project at this revision can be built but is known to have test failure. Tests will pass only after we completed the port of all ISO 19115-3 work. Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java?rev=1819783&r1=1819782&r2=1819783&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java [UTF-8] Mon Jan 1 20:06:53 2018 @@ -31,6 +31,7 @@ import org.opengis.metadata.citation.Rol import org.opengis.metadata.citation.Responsibility; import org.opengis.metadata.citation.PresentationForm; import org.apache.sis.internal.util.CollectionsExt; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.xml.IdentifierMap; import org.apache.sis.xml.IdentifierSpace; import org.apache.sis.metadata.iso.extent.Extents; @@ -192,7 +193,7 @@ public final strictfp class DefaultCitat new DefaultResponsibility(Role.FUNDER, null, new DefaultIndividual("Robin Hood", null, contact)) )); c.getDates().add(new DefaultCitationDate(TestUtilities.date("2015-10-17 00:00:00"), DateType.ADOPTED)); - assertMarshalEqualsFile(XML_FILE, c, "xlmns:*", "xsi:schemaLocation"); + assertMarshalEqualsFile(XML_FILE, c, LegacyNamespaces.ISO_19139, "xlmns:*", "xsi:schemaLocation"); } /** Modified: sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java?rev=1819783&r1=1819782&r2=1819783&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8] Mon Jan 1 20:06:53 2018 @@ -32,6 +32,7 @@ import javax.xml.bind.Unmarshaller; import javax.xml.bind.JAXBException; import org.apache.sis.internal.jaxb.Context; import org.apache.sis.util.ArgumentChecks; +import org.apache.sis.util.Version; import org.apache.sis.xml.MarshallerPool; import org.apache.sis.xml.XML; import org.junit.After; @@ -52,7 +53,8 @@ import static org.apache.sis.test.Assert * after each test for clearing the SIS internal {@link ThreadLocal} which was holding that context. * * @author Martin Desruisseaux (Geomatys) - * @version 0.7 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * * @see XMLComparator * @@ -198,6 +200,24 @@ public abstract strictfp class XMLTestCa } /** + * Marshals the given object and ensure that the result is equals to the content of the given file. + * + * @param filename the name of the XML file in the package of the final subclass of {@code this}. + * @param object the object to marshal. + * @param metadataVersion whether to marshall legacy 19139:2007 or newer ISO 19115-3 document. + * @param ignoredAttributes the fully-qualified names of attributes to ignore + * (typically {@code "xmlns:*"} and {@code "xsi:schemaLocation"}). + * @throws JAXBException if an error occurred during marshalling. + * + * @since 1.0 + */ + protected final void assertMarshalEqualsFile(final String filename, final Object object, + final Version metadataVersion, final String... ignoredAttributes) throws JAXBException + { + assertXmlEquals(getResource(filename), marshal(object, metadataVersion), ignoredAttributes); + } + + /** * Marshals the given object and ensure that the result is equals to the content of the given file, * within a tolerance threshold for numerical values. * @@ -221,6 +241,7 @@ public abstract strictfp class XMLTestCa /** * Marshals the given object using the {@linkplain #getMarshallerPool() test marshaller pool}. + * The default XML schema is used (usually the most recent one). * * @param object the object to marshal. * @return the marshalled object. @@ -237,6 +258,26 @@ public abstract strictfp class XMLTestCa } /** + * Marshals the given object using the {@linkplain #getMarshallerPool() test marshaller pool}. + * The XML schema identified by the given version is used. + * + * @param object the object to marshal. + * @param metadataVersion whether to marshall legacy 19139:2007 or newer ISO 19115-3 document. + * @return the marshalled object. + * @throws JAXBException if an error occurred while marshalling the object. + * + * @since 1.0 + */ + protected final String marshal(final Object object, final Version metadataVersion) throws JAXBException { + final MarshallerPool pool = getMarshallerPool(); + final Marshaller marshaller = pool.acquireMarshaller(); + marshaller.setProperty(XML.METADATA_VERSION, metadataVersion); + final String xml = marshal(marshaller, object); + pool.recycle(marshaller); + return xml; + } + + /** * Marshals the given object using the given marshaler. * * @param marshaller the marshaller to use. @@ -300,7 +341,7 @@ public abstract strictfp class XMLTestCa } /** - * Unmarshals the given XML using the given unmarshaler. + * Unmarshals the given XML using the given unmarshaller. * * @param unmarshaller the unmarshaller to use. * @param xml the XML representation of the object to unmarshal.