Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -24,6 +24,7 @@ import org.apache.sis.xml.XML; import org.apache.sis.xml.Namespaces; import org.apache.sis.xml.MarshallerPool; import org.apache.sis.util.logging.WarningListener; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.test.XMLTestCase; import org.junit.Test; @@ -36,7 +37,8 @@ import static org.apache.sis.test.TestUt * Tests {@link DefaultLegalConstraints}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.5 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.4 * @module */ @@ -79,7 +81,7 @@ public final strictfp class DefaultLegal } /** - * Unmarshalls the given XML fragment. + * Unmarshals the given XML fragment. */ private DefaultLegalConstraints unmarshal(final String xml) throws JAXBException { final MarshallerPool pool = getMarshallerPool(); @@ -101,14 +103,14 @@ public final strictfp class DefaultLegal @Test public void testUnmarshallEmptyCodeListValue() throws JAXBException { final DefaultLegalConstraints c = unmarshal( - "<gmd:MD_LegalConstraints xmlns:gmd=\"" + Namespaces.GMD + "\">\n" + - " <gmd:accessConstraints>\n" + - " <gmd:MD_RestrictionCode codeListValue=\"intellectualPropertyRights\" codeList=\"http://www.isotc211.org/2005/resources/codeList.xml#MD_RestrictionCode\"/>\n" + - " </gmd:accessConstraints>\n" + - " <gmd:useConstraints>\n" + // Below is an intentionally empty code list value (SIS-157) - " <gmd:MD_RestrictionCode codeListValue=\"\" codeList=\"http://www.isotc211.org/2005/resources/codeList.xml#MD_RestrictionCode\"/>\n" + - " </gmd:useConstraints>\n" + - "</gmd:MD_LegalConstraints>"); + "<mco:MD_LegalConstraints xmlns:mco=\"" + Namespaces.MCO + "\">\n" + + " <mco:accessConstraints>\n" + + " <mco:MD_RestrictionCode codeListValue=\"intellectualPropertyRights\" codeList=\"http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#MD_RestrictionCode\"/>\n" + + " </mco:accessConstraints>\n" + + " <mco:useConstraints>\n" + // Below is an intentionally empty code list value (SIS-157) + " <mco:MD_RestrictionCode codeListValue=\"\" codeList=\"http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#MD_RestrictionCode\"/>\n" + + " </mco:useConstraints>\n" + + "</mco:MD_LegalConstraints>"); /* * Verify metadata property. */ @@ -130,8 +132,28 @@ public final strictfp class DefaultLegal */ @Test public void testLicenceCode() throws JAXBException { - final String xml = - "<gmd:MD_LegalConstraints xmlns:gmd=\"" + Namespaces.GMD + "\">\n" + + String xml = + "<mco:MD_LegalConstraints xmlns:mco=\"" + Namespaces.MCO + "\">\n" + + " <mco:useConstraints>\n" + + " <mco:MD_RestrictionCode" + + " codeList=\"http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#MD_RestrictionCode\"" + + " codeListValue=\"licence\"" + + " codeSpace=\"eng\">Licence</mco:MD_RestrictionCode>\n" + + " </mco:useConstraints>\n" + + "</mco:MD_LegalConstraints>\n"; + + final DefaultLegalConstraints c = new DefaultLegalConstraints(); + c.setUseConstraints(singleton(Restriction.LICENCE)); + assertXmlEquals(xml, marshal(c), "xmlns:*"); + DefaultLegalConstraints actual = unmarshal(xml); + assertSame(Restriction.LICENCE, getSingleton(actual.getUseConstraints())); + assertEquals(c, actual); + /* + * Above code tested ISO 19115-3 (un)marshalling. Code below test legacy ISO 19139:2007 (un)marshalling. + * This is where the spelling difference appears. At unmarshalling, verify that we got back the original + * LICENCE code, not a new "LICENSE" code. + */ + xml = "<gmd:MD_LegalConstraints xmlns:gmd=\"" + LegacyNamespaces.GMD + "\">\n" + " <gmd:useConstraints>\n" + " <gmd:MD_RestrictionCode" + " codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode\"" @@ -140,13 +162,8 @@ public final strictfp class DefaultLegal " </gmd:useConstraints>\n" + "</gmd:MD_LegalConstraints>\n"; - final DefaultLegalConstraints c = new DefaultLegalConstraints(); - c.setUseConstraints(singleton(Restriction.LICENCE)); - assertXmlEquals(xml, marshal(c), "xmlns:*"); - /* - * Unmarshall and ensure that we got back the original LICENCE code, not a new "LICENSE" code. - */ - final DefaultLegalConstraints actual = unmarshal(xml); + assertXmlEquals(xml, marshal(c, VERSION_2007), "xmlns:*"); + actual = unmarshal(xml); assertSame(Restriction.LICENCE, getSingleton(actual.getUseConstraints())); assertEquals(c, actual); }
Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -18,9 +18,9 @@ package org.apache.sis.metadata.iso.exte import java.net.URL; import java.util.Arrays; -import java.io.IOException; import javax.xml.bind.JAXBException; import org.opengis.metadata.extent.Extent; +import org.apache.sis.util.Version; import org.apache.sis.util.iso.SimpleInternationalString; import org.apache.sis.xml.IdentifierSpace; import org.apache.sis.xml.Namespaces; @@ -38,24 +38,22 @@ import static org.apache.sis.test.TestUt * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.3 * @module */ @DependsOn(DefaultGeographicBoundingBoxTest.class) public final strictfp class DefaultExtentTest extends XMLTestCase { /** - * Returns the URL to the XML file of the given name. - * The argument shall be one of the files listed in the following directory: + * Returns the URL to a test file in XML. + * This is used for test methods outside this {@code DefaultExtentTest} file. * - * <ul> - * <li>{@code "core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/extent"}</li> - * </ul> - * - * @param filename the name of the XML file. - * @return the URL to the given XML file. + * @param legacy {@code true} for legacy ISO 19139:2007 format, or {@code false} for ISO 19115-3 format. + * @return URL to a test file in XML. */ - public static URL getResource(final String filename) { + public static URL getTestFile(final boolean legacy) { + final String filename = legacy ? "Extent (legacy).xml" : "Extent.xml"; final URL resource = DefaultExtentTest.class.getResource(filename); assertNotNull(filename, resource); return resource; @@ -102,11 +100,27 @@ public final strictfp class DefaultExten * <p><b>XML test file:</b> * {@code "core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/extent/Extent.xml"}</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 testXML() throws IOException, JAXBException { + public void testXML() throws JAXBException { + roundtrip("Extent.xml", VERSION_2014); + } + + /** + * Tests the (un)marshalling of a {@code <gmd:EX_Extent>} object using the legacy ISO 19139:2007 schema. + * + * @throws JAXBException if an error occurred during the during marshalling / unmarshalling processes. + */ + @Test + public void testLegacyXML() throws JAXBException { + roundtrip("Extent (legacy).xml", VERSION_2007); + } + + /** + * Compares the marshalling and unmarshalling of a {@link DefaultExtent} with XML in the given file. + */ + private void roundtrip(final String filename, final Version version) throws JAXBException { final DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox(-99, -79, 14.9844, 31); bbox.getIdentifierMap().put(IdentifierSpace.ID, "bbox"); final DefaultTemporalExtent temporal = new DefaultTemporalExtent(); @@ -115,44 +129,34 @@ public final strictfp class DefaultExten temporal.setBounds(date("2010-01-27 13:26:10"), date("2010-08-27 13:26:10")); } final DefaultExtent extent = new DefaultExtent(null, bbox, null, temporal); - /* - * XML marshalling, and compare with the content of "ProcessStep.xml" file. - */ - final String xml = marshal(extent); - assertTrue(xml.startsWith("<?xml")); - assertXmlEquals(getResource("Extent.xml"), xml, "xmlns:*", "xsi:schemaLocation"); - /* - * Final comparison: ensure that we didn't lost any information. - */ - assertEquals(extent, unmarshal(DefaultExtent.class, xml)); + assertMarshalEqualsFile(filename, extent, version, "xmlns:*", "xsi:schemaLocation"); + assertEquals(extent, unmarshalFile(DefaultExtent.class, filename)); } /** * Tests XML marshalling of the {@link Extents#WORLD} constant, which is a {@code DefaultExtent} instance. * * @throws JAXBException if an error occurred during the during marshalling / unmarshalling processes. - * - * @since 0.6 */ @Test public void testWorldConstant() throws JAXBException { final String xml = marshal(Extents.WORLD); - assertXmlEquals("<gmd:EX_Extent" + - " xmlns:gco=\"" + Namespaces.GCO + '"' + - " xmlns:gmd=\"" + Namespaces.GMD + "\">\n" + - " <gmd:description>\n" + + assertXmlEquals("<gex:EX_Extent" + + " xmlns:gex=\"" + Namespaces.GEX + '"' + + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + + " <gex:description>\n" + " <gco:CharacterString>World</gco:CharacterString>\n" + - " </gmd:description>\n" + - " <gmd:geographicElement>\n" + - " <gmd:EX_GeographicBoundingBox>\n" + - " <gmd:extentTypeCode> <gco:Boolean> true </gco:Boolean></gmd:extentTypeCode>\n" + - " <gmd:westBoundLongitude><gco:Decimal> -180 </gco:Decimal></gmd:westBoundLongitude>\n" + - " <gmd:eastBoundLongitude><gco:Decimal> 180 </gco:Decimal></gmd:eastBoundLongitude>\n" + - " <gmd:southBoundLatitude><gco:Decimal> -90 </gco:Decimal></gmd:southBoundLatitude>\n" + - " <gmd:northBoundLatitude><gco:Decimal> 90 </gco:Decimal></gmd:northBoundLatitude>\n" + - " </gmd:EX_GeographicBoundingBox>\n" + - " </gmd:geographicElement>\n" + - "</gmd:EX_Extent>", + " </gex:description>\n" + + " <gex:geographicElement>\n" + + " <gex:EX_GeographicBoundingBox>\n" + + " <gex:extentTypeCode> <gco:Boolean> true </gco:Boolean></gex:extentTypeCode>\n" + + " <gex:westBoundLongitude><gco:Decimal> -180 </gco:Decimal></gex:westBoundLongitude>\n" + + " <gex:eastBoundLongitude><gco:Decimal> 180 </gco:Decimal></gex:eastBoundLongitude>\n" + + " <gex:southBoundLatitude><gco:Decimal> -90 </gco:Decimal></gex:southBoundLatitude>\n" + + " <gex:northBoundLatitude><gco:Decimal> 90 </gco:Decimal></gex:northBoundLatitude>\n" + + " </gex:EX_GeographicBoundingBox>\n" + + " </gex:geographicElement>\n" + + "</gex:EX_Extent>", xml, "xmlns:*", "xsi:schemaLocation"); } } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultBrowseGraphicTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -18,17 +18,19 @@ package org.apache.sis.metadata.iso.iden import java.net.URI; import java.io.StringReader; -import java.io.StringWriter; import java.util.logging.LogRecord; +import javax.xml.bind.Marshaller; import javax.xml.bind.JAXBException; import javax.xml.transform.stream.StreamSource; -import javax.xml.transform.stream.StreamResult; +import org.opengis.metadata.identification.BrowseGraphic; import org.apache.sis.util.logging.WarningListener; import org.apache.sis.util.logging.Logging; -import org.apache.sis.test.DependsOnMethod; -import org.apache.sis.test.TestCase; +import org.apache.sis.util.Version; +import org.apache.sis.xml.MarshallerPool; import org.apache.sis.xml.Namespaces; import org.apache.sis.xml.XML; +import org.apache.sis.test.XMLTestCase; +import org.apache.sis.test.DependsOnMethod; import org.junit.Test; import static org.apache.sis.test.Assert.*; @@ -39,13 +41,39 @@ import static java.util.Collections.sing * Tests {@link DefaultBrowseGraphic}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.4 * @module */ -public final strictfp class DefaultBrowseGraphicTest extends TestCase { +public final strictfp class DefaultBrowseGraphicTest extends XMLTestCase { /** - * Tests XML marshalling of {@code <gmx:MimeFileType>} inside {@code <gmd:MD_BrowseGraphic>}. + * {@code false} if testing ISO 19115-3 document, or {@code true} if testing ISO 19139:2007 document. + */ + private boolean legacy; + + /** + * Verifies that marshalling the given metadata produces the expected XML document, + * then verifies that unmarshalling that document gives back the original metadata object. + * If {@link #legacy} is {@code true}, then this method will use ISO 19139:2007 schema. + */ + private void roundtrip(final BrowseGraphic browse, String expected) throws JAXBException { + final String actual; + final Version version; + if (legacy) { + expected = toLegacyXML(expected); + version = VERSION_2007; + } else { + version = VERSION_2014; + } + actual = marshal(browse, version); + assertXmlEquals(expected, actual, "xmlns:*"); + assertEquals(browse, unmarshal(BrowseGraphic.class, actual)); + } + + /** + * Tests XML marshalling of {@code <gcx:MimeFileType>} inside {@code <mcc:MD_BrowseGraphic>}. + * This method uses the XML schema defined by ISO 19115-3. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @@ -53,124 +81,149 @@ public final strictfp class DefaultBrows public void testMimeFileType() throws JAXBException { final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(); browse.setFileType("image/tiff"); - final String xml = XML.marshal(browse); - assertXmlEquals( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + "\">\n" + - " <gmd:fileType>\n" + - " <gmx:MimeFileType type=\"image/tiff\">image/tiff</gmx:MimeFileType>\n" + - " </gmd:fileType>\n" + - "</gmd:MD_BrowseGraphic>", xml, "xmlns:*"); - /* - * Unmarshal the element back to a Java object and compare to the original. - */ - assertEquals(browse, XML.unmarshal(xml)); + roundtrip(browse, + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + "\">\n" + + " <mcc:fileType>\n" + + " <gcx:MimeFileType type=\"image/tiff\">image/tiff</gcx:MimeFileType>\n" + + " </mcc:fileType>\n" + + "</mcc:MD_BrowseGraphic>"); } /** - * Tests XML marshalling of {@code <gmx:FileName>} inside {@code <gmd:MD_BrowseGraphic>}. + * Tests XML marshalling of {@code <gmx:MimeFileType>} inside {@code <gmd:MD_BrowseGraphic>}. + * This method uses the XML schema defined by ISO 19139:2007. + * + * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. + */ + @Test + @DependsOnMethod("testMimeFileType") + public void testMimeFileType_Legacy() throws JAXBException { + legacy = true; + testMimeFileType(); + } + + /** + * Tests XML marshalling of {@code <gcx:FileName>} inside {@code <mcc:MD_BrowseGraphic>}. + * This method uses the XML schema defined by ISO 19115-3. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @Test public void testFileName() throws JAXBException { - final URI uri = URI.create("file:/catalog/image.png"); - final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(uri); - final String xml = XML.marshal(browse); - assertXmlEquals( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + "\">\n" + - " <gmd:fileName>\n" + - " <gmx:FileName src=\"file:/catalog/image.png\">image.png</gmx:FileName>\n" + - " </gmd:fileName>\n" + - "</gmd:MD_BrowseGraphic>", xml, "xmlns:*"); - /* - * Unmarshal the element back to a Java object and compare to the original. - */ - assertEquals(browse, XML.unmarshal(xml)); + roundtrip(new DefaultBrowseGraphic(URI.create("file:/catalog/image.png")), + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + "\">\n" + + " <mcc:fileName>\n" + + " <gcx:FileName src=\"file:/catalog/image.png\">image.png</gcx:FileName>\n" + + " </mcc:fileName>\n" + + "</mcc:MD_BrowseGraphic>"); } /** - * Tests unmarshalling of {@code <gmx:FileName>} without {@code src} attribute. + * Tests XML marshalling of {@code <gmx:FileName>} inside {@code <gmd:MD_BrowseGraphic>}. + * This method uses the XML schema defined by ISO 19139:2007. + * + * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. + */ + @Test + @DependsOnMethod("testFileName") + public void testFileName_Legacy() throws JAXBException { + legacy = true; + testFileName(); + } + + /** + * Tests unmarshalling of {@code <gcx:FileName>} without {@code src} attribute. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @Test @DependsOnMethod("testFileName") public void testFileNameWithoutSrc() throws JAXBException { - final DefaultBrowseGraphic browse = (DefaultBrowseGraphic) XML.unmarshal( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + "\">\n" + - " <gmd:fileName>\n" + - " <gmx:FileName>file:/catalog/image.png</gmx:FileName>\n" + - " </gmd:fileName>\n" + - "</gmd:MD_BrowseGraphic>"); + final DefaultBrowseGraphic browse = unmarshal(DefaultBrowseGraphic.class, + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + "\">\n" + + " <mcc:fileName>\n" + + " <gcx:FileName>file:/catalog/image.png</gcx:FileName>\n" + + " </mcc:fileName>\n" + + "</mcc:MD_BrowseGraphic>"); assertEquals(URI.create("file:/catalog/image.png"), browse.getFileName()); } /** - * Tests XML marshalling of {@code <gmx:FileName>} and {@code <gmx:MimeFileType>} together. + * Tests XML marshalling of {@code <gcx:FileName>} and {@code <gcx:MimeFileType>} together. + * This method uses the XML schema defined by ISO 19115-3. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @Test @DependsOnMethod({"testFileName", "testMimeFileType"}) public void testFileNameAndType() throws JAXBException { - final URI uri = URI.create("file:/catalog/image.png"); - final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(uri); + final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(URI.create("file:/catalog/image.png")); browse.setFileType("image/tiff"); - final String xml = XML.marshal(browse); - assertXmlEquals( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + "\">\n" + - " <gmd:fileName>\n" + - " <gmx:FileName src=\"file:/catalog/image.png\">image.png</gmx:FileName>\n" + - " </gmd:fileName>\n" + - " <gmd:fileType>\n" + - " <gmx:MimeFileType type=\"image/tiff\">image/tiff</gmx:MimeFileType>\n" + - " </gmd:fileType>\n" + - "</gmd:MD_BrowseGraphic>", xml, "xmlns:*"); - /* - * Unmarshal the element back to a Java object and compare to the original. - */ - assertEquals(browse, XML.unmarshal(xml)); + roundtrip(browse, + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + "\">\n" + + " <mcc:fileName>\n" + + " <gcx:FileName src=\"file:/catalog/image.png\">image.png</gcx:FileName>\n" + + " </mcc:fileName>\n" + + " <mcc:fileType>\n" + + " <gcx:MimeFileType type=\"image/tiff\">image/tiff</gcx:MimeFileType>\n" + + " </mcc:fileType>\n" + + "</mcc:MD_BrowseGraphic>"); + } + + /** + * Tests XML marshalling of {@code <gmx:FileName>} and {@code <gmx:MimeFileType>} together. + * This method uses the XML schema defined by ISO 19139:2007. + * + * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. + */ + @Test + @DependsOnMethod({"testFileName_Legacy", "testMimeFileType_Legacy"}) + public void testFileNameAndType_Legacy() throws JAXBException { + legacy = true; + testFileNameAndType(); } /** * Tests XML marshalling of filename substituted by {@code <gco:CharacterString>} - * inside {@code <gmd:MD_BrowseGraphic>}. + * inside {@code <mcc:MD_BrowseGraphic>}. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @Test @DependsOnMethod("testFileNameAndType") public void testStringSubstitution() throws JAXBException { - final URI uri = URI.create("file:/catalog/image.png"); - final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(uri); + final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(URI.create("file:/catalog/image.png")); browse.setFileType("image/tiff"); - final StringWriter buffer = new StringWriter(); - XML.marshal(browse, new StreamResult(buffer), - singletonMap(XML.STRING_SUBSTITUTES, new String[] {"filename", "mimetype"})); - final String xml = buffer.toString(); + + final MarshallerPool pool = getMarshallerPool(); + final Marshaller marshaller = pool.acquireMarshaller(); + marshaller.setProperty(XML.STRING_SUBSTITUTES, new String[] {"filename", "mimetype"}); + final String xml = marshal(marshaller, browse); + pool.recycle(marshaller); + assertXmlEquals( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + - " <gmd:fileName>\n" + + " <mcc:fileName>\n" + " <gco:CharacterString>file:/catalog/image.png</gco:CharacterString>\n" + - " </gmd:fileName>\n" + - " <gmd:fileType>\n" + + " </mcc:fileName>\n" + + " <mcc:fileType>\n" + " <gco:CharacterString>image/tiff</gco:CharacterString>\n" + - " </gmd:fileType>\n" + - "</gmd:MD_BrowseGraphic>", xml, "xmlns:*"); + " </mcc:fileType>\n" + + "</mcc:MD_BrowseGraphic>", xml, "xmlns:*"); /* * Unmarshal the element back to a Java object and compare to the original. */ - assertEquals(browse, XML.unmarshal(xml)); + assertEquals(browse, unmarshal(BrowseGraphic.class, xml)); } /** - * Tests the unmarshaller with the same URI in both {@code <gco:CharacterString>} and {@code <gmx:FileName>}. + * Tests the unmarshaller with the same URI in both {@code <gco:CharacterString>} and {@code <gcx:FileName>}. * Since the URI is the same, the unmarshaller should not produce any warning since there is no ambiguity. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. @@ -180,14 +233,14 @@ public final strictfp class DefaultBrows public void testDuplicatedValues() throws JAXBException { final Warning listener = new Warning(); final DefaultBrowseGraphic browse = listener.unmarshal( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + '"' + + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + - " <gmd:fileName>\n" + - " <gmx:FileName src=\"file:/catalog/image.png\">image.png</gmx:FileName>\n" + + " <mcc:fileName>\n" + + " <gcx:FileName src=\"file:/catalog/image.png\">image.png</gcx:FileName>\n" + " <gco:CharacterString>file:/catalog/image.png</gco:CharacterString>\n" + - " </gmd:fileName>\n" + - "</gmd:MD_BrowseGraphic>"); + " </mcc:fileName>\n" + + "</mcc:MD_BrowseGraphic>"); assertEquals(URI.create("file:/catalog/image.png"), browse.getFileName()); assertFalse("Expected no warning.", listener.receivedWarning); @@ -195,21 +248,21 @@ public final strictfp class DefaultBrows /** * Ensures that the unmarshaller produces a warning when {@code <gco:CharacterString>} and - * {@code <gmx:FileName>} both exist inside the same {@code <gmd:MD_BrowseGraphic>}. + * {@code <gcx:FileName>} both exist inside the same {@code <gmd:MD_BrowseGraphic>}. * * @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}. */ @Test @DependsOnMethod("testStringSubstitution") public void testWarnings() throws JAXBException { - testWarnings("<gmx:FileName src=\"file:/catalog/image.png\">image.png</gmx:FileName>", + testWarnings("<gcx:FileName src=\"file:/catalog/image.png\">image.png</gcx:FileName>", "<gco:CharacterString>file:/catalog/image2.png</gco:CharacterString>"); /* * Test again with the same element value, but in reverse order. * We do that for ensuring that FileName still has precedence. */ testWarnings("<gco:CharacterString>file:/catalog/image2.png</gco:CharacterString>", - "<gmx:FileName src=\"file:/catalog/image.png\">image.png</gmx:FileName>"); + "<gcx:FileName src=\"file:/catalog/image.png\">image.png</gcx:FileName>"); } /** @@ -218,14 +271,14 @@ public final strictfp class DefaultBrows private void testWarnings(final String first, final String second) throws JAXBException { final Warning listener = new Warning(); final DefaultBrowseGraphic browse = listener.unmarshal( - "<gmd:MD_BrowseGraphic xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmx=\"" + Namespaces.GMX + '"' + + "<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + - " <gmd:fileName>\n" + + " <mcc:fileName>\n" + " " + first + "\n" + " " + second + "\n" + - " </gmd:fileName>\n" + - "</gmd:MD_BrowseGraphic>"); + " </mcc:fileName>\n" + + "</mcc:MD_BrowseGraphic>"); assertEquals(URI.create("file:/catalog/image.png"), browse.getFileName()); assertTrue("Expected a warning.", listener.receivedWarning); Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResourceTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResourceTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResourceTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResourceTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -37,7 +37,7 @@ import static org.junit.Assert.*; * Tests {@link DefaultCoupledResource}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.5 + * @version 1.0 * @since 0.5 * @module */ @@ -46,14 +46,13 @@ public final strictfp class DefaultCoupl /** * Creates the resource to use for testing purpose. */ - static DefaultCoupledResource create() { + static DefaultCoupledResource create(final NameFactory factory) { final DefaultOperationMetadata operation = new DefaultOperationMetadata("Get Map", DistributedComputingPlatform.WEB_SERVICES, null); operation.setParameters(singleton((ParameterDescriptor<?>) ServiceParameterTest.create())); operation.setConnectPoints(singleton(NilReason.MISSING.createNilObject(OnlineResource.class))); final DefaultCoupledResource resource = new DefaultCoupledResource(); - final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class); resource.setScopedName((ScopedName) factory.createGenericName(null, "mySpace", "ABC-123")); resource.setOperation(operation); return resource; @@ -64,7 +63,7 @@ public final strictfp class DefaultCoupl */ @Test public void testOperationNameResolve() { - final DefaultCoupledResource resource = DefaultCoupledResourceTest.create(); + final DefaultCoupledResource resource = create(DefaultFactories.forBuildin(NameFactory.class)); final OperationMetadata operation = resource.getOperation(); /* * Test OperationName replacement when the name matches. Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultDataIdentificationTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -43,7 +43,7 @@ import static org.apache.sis.test.Metada * Tests {@link DefaultDataIdentification}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.5 + * @version 1.0 * @since 0.3 * @module */ @@ -140,23 +140,23 @@ public final strictfp class DefaultDataI " │ │ └─Date type………………………………… Creation\n" + " │ └─Identifier………………………………………… SST_Global.nc\n" + " ├─Abstract………………………………………………………… NCEP SST Global 5.0 x 2.5 degree model data\n" + + " ├─Spatial representation type……… Grid\n" + + " ├─Extent……………………………………………………………… World\n" + + " │ └─Geographic element\n" + + " │ ├─West bound longitude…… 180°W\n" + + " │ ├─East bound longitude…… 180°E\n" + + " │ ├─South bound latitude…… 90°S\n" + + " │ ├─North bound latitude…… 90°N\n" + + " │ └─Extent type code……………… true\n" + " ├─Descriptive keywords\n" + " │ ├─Keyword………………………………………………… EARTH SCIENCE > Oceans > Ocean Temperature > Sea Surface Temperature\n" + " │ ├─Type………………………………………………………… Theme\n" + " │ └─Thesaurus name……………………………… GCMD Science Keywords\n" + " ├─Resource constraints\n" + " │ └─Use limitation……………………………… Freely available\n" + - " ├─Spatial representation type……… Grid\n" + " ├─Language (1 of 2)………………………………… en_US\n" + " ├─Language (2 of 2)………………………………… en\n" + - " ├─Character set…………………………………………… US-ASCII\n" + - " └─Extent……………………………………………………………… World\n" + - " └─Geographic element\n" + - " ├─West bound longitude…… 180°W\n" + - " ├─East bound longitude…… 180°E\n" + - " ├─South bound latitude…… 90°S\n" + - " ├─North bound latitude…… 90°N\n" + - " └─Extent type code……………… true\n", + " └─Character set…………………………………………… US-ASCII\n", TestUtilities.formatNameAndValue(create().asTreeTable())); } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFractionTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -17,10 +17,12 @@ package org.apache.sis.metadata.iso.identification; import javax.xml.bind.JAXBException; -import org.apache.sis.xml.XML; +import org.opengis.metadata.identification.RepresentativeFraction; import org.apache.sis.xml.Namespaces; import org.apache.sis.xml.IdentifierSpace; -import org.apache.sis.test.TestCase; +import org.apache.sis.util.Version; +import org.apache.sis.test.XMLTestCase; +import org.apache.sis.test.DependsOnMethod; import org.junit.Test; import static org.apache.sis.test.Assert.*; @@ -30,11 +32,36 @@ import static org.apache.sis.test.Assert * Tests {@link DefaultRepresentativeFraction}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.7 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.4 * @module */ -public final strictfp class DefaultRepresentativeFractionTest extends TestCase { +public final strictfp class DefaultRepresentativeFractionTest extends XMLTestCase { + /** + * {@code false} if testing ISO 19115-3 document, or {@code true} if testing ISO 19139:2007 document. + */ + private boolean legacy; + + /** + * Verifies that marshalling the given metadata produces the expected XML document, + * then verifies that unmarshalling that document gives back the original metadata object. + * If {@link #legacy} is {@code true}, then this method will use ISO 19139:2007 schema. + */ + private void roundtrip(final RepresentativeFraction browse, String expected) throws JAXBException { + final String actual; + final Version version; + if (legacy) { + expected = toLegacyXML(expected); + version = VERSION_2007; + } else { + version = VERSION_2014; + } + actual = marshal(browse, version); + assertXmlEquals(expected, actual, "xmlns:*"); + assertEquals(browse, unmarshal(RepresentativeFraction.class, actual)); + } + /** * Test {@link DefaultRepresentativeFraction#setScale(double)}. */ @@ -50,27 +77,36 @@ public final strictfp class DefaultRepre } /** - * Tests XML marshalling of identifiers. + * Tests XML marshalling using ISO 19115-3 schema. + * This XML fragment contains an identifier. * - * @throws JAXBException Should never happen. + * @throws JAXBException if an error occurred during marshalling. */ @Test - public void testIdentifiers() throws JAXBException { + public void testMarshalling() throws JAXBException { final DefaultRepresentativeFraction fraction = new DefaultRepresentativeFraction(8); fraction.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "scale"); - final String xml = XML.marshal(fraction); - assertXmlEquals( - "<gmd:MD_RepresentativeFraction xmlns:gmd=\"" + Namespaces.GMD + '"' + + roundtrip(fraction, + "<mri:MD_RepresentativeFraction xmlns:mri=\"" + Namespaces.MRI + '"' + " xmlns:gco=\"" + Namespaces.GCO + '"' + " id=\"scale\">\n" + - " <gmd:denominator>\n" + + " <mri:denominator>\n" + " <gco:Integer>8</gco:Integer>\n" + - " </gmd:denominator>\n" + - "</gmd:MD_RepresentativeFraction>", xml, "xmlns:*"); - /* - * Unmarshal the element back to a Java object and compare to the original. - */ - assertEquals(fraction, XML.unmarshal(xml)); + " </mri:denominator>\n" + + "</mri:MD_RepresentativeFraction>"); + } + + /** + * Tests XML marshalling using ISO 19139:2007 schema. + * This XML fragment contains an identifier. + * + * @throws JAXBException if an error occurred during marshalling. + */ + @Test + @DependsOnMethod("testMarshalling") + public void testMarshallingLegacy() throws JAXBException { + legacy = true; + testMarshalling(); } /** Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -18,13 +18,13 @@ package org.apache.sis.metadata.iso.iden import javax.xml.bind.JAXBException; import org.opengis.metadata.identification.RepresentativeFraction; -import org.apache.sis.xml.XML; import org.apache.sis.xml.Namespaces; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.internal.jaxb.Context; import org.apache.sis.internal.jaxb.Schemas; import org.apache.sis.test.LoggingWatcher; +import org.apache.sis.test.XMLTestCase; import org.apache.sis.test.DependsOn; -import org.apache.sis.test.TestCase; import org.junit.After; import org.junit.Rule; import org.junit.Test; @@ -36,12 +36,13 @@ import static org.apache.sis.test.Assert * Tests {@link DefaultResolution}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.7 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.3 * @module */ @DependsOn(DefaultRepresentativeFractionTest.class) -public final strictfp class DefaultResolutionTest extends TestCase { +public final strictfp class DefaultResolutionTest extends XMLTestCase { /** * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to * do so, but should be considered as an implementation details (it should have been a private field). @@ -107,9 +108,40 @@ public final strictfp class DefaultResol * instance which is expected to be marshalled as below (ignoring namespace declarations): * * {@preformat xml + * <mri:MD_Resolution> + * <mri:distance> + * <gco:Distance uom="http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])">1000.0</gco:Distance> + * </mri:distance> + * </mri:MD_Resolution> + * } + * + * @throws JAXBException if an error occurred while marshalling the element. + */ + @Test + public void testXML() throws JAXBException { + final DefaultResolution resolution = new DefaultResolution(); + resolution.setDistance(1000.0); + final String xml = marshal(resolution); + assertXmlEquals( + "<mri:MD_Resolution xmlns:mri=\"" + Namespaces.MRI + '"' + + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + + " <mri:distance>\n" + + " <gco:Distance uom=\"" + Schemas.METADATA_ROOT_LEGACY + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='m'])\">1000.0</gco:Distance>\n" + + " </mri:distance>\n" + + "</mri:MD_Resolution>", xml, "xmlns:*"); + + assertEquals(resolution, unmarshal(DefaultResolution.class, xml)); + } + + /** + * Tests XML (un)marshalling of a resolution element using legacy XML schema. + * This test creates a {@link DefaultResolution} instance which is expected to be marshalled as below + * (ignoring namespace declarations): + * + * {@preformat xml * <gmd:MD_Resolution> * <gmd:distance> - * <gco:Distance uom=\"http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])\">1000.0</gco:Distance> + * <gco:Distance uom="http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])">1000.0</gco:Distance> * </gmd:distance> * </gmd:MD_Resolution> * } @@ -117,28 +149,18 @@ public final strictfp class DefaultResol * @throws JAXBException if an error occurred while marshalling the element. */ @Test - public void testXML() throws JAXBException { + public void testLegacyXML() throws JAXBException { final DefaultResolution resolution = new DefaultResolution(); resolution.setDistance(1000.0); - final String xml = XML.marshal(resolution); - assertTrue("<gmd:distance> element is missing. If this test fails randomly, " - + "see DefaultResolutionTest.testXML() javadoc for more information", xml.contains("distance")); - /* - * Following test is done as a matter of principle, but should not be a problem. - * The real issue is the <gmd:distance> which happen to be randomly missing for - * an unknown reason. - */ + final String xml = marshal(resolution, VERSION_2007); assertXmlEquals( - "<gmd:MD_Resolution xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + + "<gmd:MD_Resolution xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' + + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + " <gmd:distance>\n" + - " <gco:Distance uom=\"" + Schemas.METADATA_ROOT + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='m'])\">1000.0</gco:Distance>\n" + + " <gco:Distance uom=\"" + Schemas.METADATA_ROOT_LEGACY + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='m'])\">1000.0</gco:Distance>\n" + " </gmd:distance>\n" + "</gmd:MD_Resolution>", xml, "xmlns:*"); - /* - * Unmarshal the element back to a Java object, as a safety. - * Should not be a problem neither. - */ - assertEquals(resolution, XML.unmarshal(xml)); + + assertEquals(resolution, unmarshal(DefaultResolution.class, xml)); } } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -18,24 +18,32 @@ package org.apache.sis.metadata.iso.iden import javax.xml.bind.JAXBException; import org.opengis.util.NameFactory; +import org.opengis.parameter.ParameterDirection; +import org.opengis.parameter.ParameterDescriptor; import org.opengis.metadata.citation.Citation; import org.opengis.metadata.identification.CouplingType; +import org.opengis.metadata.identification.CoupledResource; +import org.opengis.metadata.identification.OperationMetadata; +import org.opengis.metadata.identification.ServiceIdentification; +import org.opengis.metadata.identification.DistributedComputingPlatform; +import org.apache.sis.metadata.iso.citation.DefaultCitation; import org.apache.sis.internal.system.DefaultFactories; -import org.apache.sis.util.ComparisonMode; import org.apache.sis.xml.NilReason; import org.apache.sis.test.DependsOn; import org.apache.sis.test.XMLTestCase; import org.junit.Test; -import static org.apache.sis.test.Assert.*; import static java.util.Collections.singleton; +import static org.apache.sis.test.MetadataAssert.*; +import static org.apache.sis.test.TestUtilities.getSingleton; /** * Tests {@link DefaultServiceIdentification}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.5 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.5 * @module */ @@ -50,11 +58,17 @@ public final strictfp class DefaultServi private static final String XML_FILE = "ServiceIdentification.xml"; /** + * Same as {@link #XML_FILE} but using legacy ISO 19139:2007 schema. + */ + private static final String XML_FILE_LEGACY = "ServiceIdentification (legacy).xml"; + + /** * Creates the service identification to use for testing purpose. */ private static DefaultServiceIdentification create() { final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class); - final DefaultCoupledResource resource = DefaultCoupledResourceTest.create(); + final DefaultCoupledResource resource = DefaultCoupledResourceTest.create(factory); + resource.setResourceReferences(singleton(new DefaultCitation("WMS specification"))); final DefaultServiceIdentification id = new DefaultServiceIdentification( factory.createGenericName(null, "Web Map Server"), // serviceType NilReason.MISSING.createNilObject(Citation.class), // citation @@ -67,13 +81,31 @@ public final strictfp class DefaultServi } /** - * Tests the marshalling of a service metadata. - * - * @throws JAXBException if an error occurred during the during marshalling process. + * Compare values of the given service identifications against the value expected for the + * instance created by {@link #create()} method. */ - @Test - public void testMarshal() throws JAXBException { - assertMarshalEqualsFile(XML_FILE, create(), "xlmns:*", "xsi:schemaLocation"); + private static void verify(final ServiceIdentification id) { + assertEquals("serviceTypeVersion", "1.0", getSingleton(id.getServiceTypeVersions())); + assertEquals("serviceType", "Web Map Server", String.valueOf(id.getServiceType())); + assertEquals("abstract", "A dummy service for testing purpose.", String.valueOf(id.getAbstract())); + assertEquals("citation", NilReason.MISSING, NilReason.forObject(id.getCitation())); + assertEquals("couplingType", CouplingType.LOOSE, id.getCouplingType()); + + final CoupledResource resource = getSingleton(id.getCoupledResources()); +// assertEquals("scopedName", "mySpace:ABC-123", …) skipped because not present in new ISO 19115-3:2016. +// assertEquals("resourceReference", "WMS specification", …) skipped because not present in legacy ISO 19139:2007. + + final OperationMetadata op = resource.getOperation(); + assertNotNull("operation", op); + assertEquals("operationName", "Get Map", op.getOperationName()); + assertEquals("distributedComputingPlatform", DistributedComputingPlatform.WEB_SERVICES, getSingleton(op.getDistributedComputingPlatforms())); + assertEquals("connectPoints", NilReason.MISSING, NilReason.forObject(getSingleton(op.getConnectPoints()))); + + final ParameterDescriptor<?> param = getSingleton(op.getParameters()); + assertEquals("name", "Version", String.valueOf(param.getName())); + assertEquals("minimumOccurs", 0, param.getMinimumOccurs()); + assertEquals("maximumOccurs", 1, param.getMaximumOccurs()); + assertEquals("direction", ParameterDirection.IN, param.getDirection()); } /** @@ -86,6 +118,42 @@ public final strictfp class DefaultServi */ @Test public void testUnmarshal() throws JAXBException { - assertTrue(create().equals(unmarshalFile(DefaultServiceIdentification.class, XML_FILE), ComparisonMode.DEBUG)); + final ServiceIdentification id = unmarshalFile(ServiceIdentification.class, XML_FILE); + verify(id); + final CoupledResource resource = getSingleton(id.getCoupledResources()); + assertTitleEquals("resourceReference", "WMS specification", getSingleton(resource.getResourceReferences())); + } + + /** + * Tests the unmarshalling of a service metadata from legacy ISO 19139:2007 schema. + * + * @throws JAXBException if an error occurred during the during unmarshalling process. + */ + @Test + public void testUnmarshalLegacy() throws JAXBException { + final ServiceIdentification id = unmarshalFile(ServiceIdentification.class, XML_FILE_LEGACY); + verify(id); + final CoupledResource resource = getSingleton(id.getCoupledResources()); + assertEquals("scopedName", "mySpace:ABC-123", String.valueOf(resource.getScopedName())); + } + + /** + * Tests the marshalling of a service metadata. + * + * @throws JAXBException if an error occurred during the during marshalling process. + */ + @Test + public void testMarshal() throws JAXBException { + assertMarshalEqualsFile(XML_FILE, create(), "xmlns:*", "xsi:schemaLocation"); + } + + /** + * Tests the marshalling of a service metadata to legacy ISO 19139:2007 schema. + * + * @throws JAXBException if an error occurred during the during marshalling process. + */ + @Test + public void testMarshalLegacy() throws JAXBException { + assertMarshalEqualsFile(XML_FILE_LEGACY, create(), VERSION_2007, "xmlns:*", "xsi:schemaLocation"); } } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -16,13 +16,15 @@ */ package org.apache.sis.metadata.iso.lineage; -import java.util.Arrays; import javax.xml.bind.JAXBException; +import org.opengis.metadata.lineage.Source; +import org.apache.sis.xml.Namespaces; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.util.iso.SimpleInternationalString; import org.apache.sis.metadata.iso.DefaultIdentifier; +import org.apache.sis.test.DependsOnMethod; +import org.apache.sis.test.TestUtilities; import org.apache.sis.test.XMLTestCase; -import org.apache.sis.xml.Namespaces; -import org.apache.sis.xml.XML; import org.junit.Test; import static org.apache.sis.test.Assert.*; @@ -33,31 +35,74 @@ import static org.apache.sis.test.Assert * {@code "gmi"} namespace that GeoAPI merged with the object of same name in the {@code "gmd"} namespace. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.0 * @since 0.3 * @module */ public final strictfp class DefaultLineageTest extends XMLTestCase { /** - * Tests the marshalling of an {@code "gmd:LI_Source"} element, which shall become - * {@code "gmi:LE_Source"} when some ISO 19115-2 properties are defined. + * Create a lineage to marshal. If {@code extension} is {@code false}, then this method uses + * only properties defined in ISO 19115-1. If {@code extension} is {@code true}, then this + * method adds an ISO 19115-2 property. + */ + private static DefaultLineage create(final boolean extension) { + final DefaultLineage lineage = new DefaultLineage(); + final DefaultSource source = new DefaultSource(); + source.setDescription(new SimpleInternationalString("Description of source data level.")); + lineage.getSources().add(source); + if (extension) { + source.setProcessedLevel(new DefaultIdentifier("DummyLevel")); + } + return lineage; + } + + /** + * Verifies the unmarshalling result. + */ + private static void verify(final DefaultLineage lineage) { + final Source source = TestUtilities.getSingleton(lineage.getSources()); + assertEquals("source.description", "Description of source data level.", String.valueOf(source.getDescription())); + } + + /** + * Tests the marshalling of a {@code "mrl:LI_Source"} element. + * If this case, the test uses only ISO 19115-1 elements (no ISO 19115-2). + * Consequently the XML name shall be {@code "mrl:LI_Source"}. * * @throws JAXBException if an error occurred while marshalling the XML. */ @Test public void testSource() throws JAXBException { - final DefaultLineage lineage = new DefaultLineage(); - final DefaultSource source = new DefaultSource(); - source.setDescription(new SimpleInternationalString("Description of source data level.")); - lineage.setSources(Arrays.asList(source)); - /* - * If this simpler case, only ISO 19115 elements are defined (no ISO 19115-2). - * Consequently the XML name shall be "gmd:LI_Source". - */ - String actual = XML.marshal(lineage); + String actual = marshal(create(false)); assertXmlEquals( - "<gmd:LI_Lineage xmlns:gmd=\"" + Namespaces.GMD + '"' + + "<mrl:LI_Lineage xmlns:mrl=\"" + Namespaces.MRL + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + + " <mrl:source>\n" + + " <mrl:LI_Source>\n" + + " <mrl:description>\n" + + " <gco:CharacterString>Description of source data level.</gco:CharacterString>\n" + + " </mrl:description>\n" + + " </mrl:LI_Source>\n" + + " </mrl:source>\n" + + "</mrl:LI_Lineage>", actual, "xmlns:*"); + + verify(unmarshal(DefaultLineage.class, actual)); + } + + /** + * Tests the marshalling of a legacy {@code "gmd:LI_Source"} element. + * If this case, the test uses only ISO 19115-1 elements (no ISO 19115-2). + * Consequently the legacy XML name shall be {@code "gmd:LI_Source"}. + * + * @throws JAXBException if an error occurred while marshalling the XML. + */ + @Test + @DependsOnMethod("testSource") + public void testLegacySource() throws JAXBException { + String actual = marshal(create(false), VERSION_2007); + assertXmlEquals( + "<gmd:LI_Lineage xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' + + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + " <gmd:source>\n" + " <gmd:LI_Source>\n" + " <gmd:description>\n" + @@ -66,15 +111,61 @@ public final strictfp class DefaultLinea " </gmd:LI_Source>\n" + " </gmd:source>\n" + "</gmd:LI_Lineage>", actual, "xmlns:*"); - /* - * Now add a ISO 19115-2 specific property. The XML name shall become "gmi:LE_Source". - */ - source.setProcessedLevel(new DefaultIdentifier("DummyLevel")); - actual = XML.marshal(lineage); + + verify(unmarshal(DefaultLineage.class, actual)); + } + + /** + * Tests the marshalling of a {@code "mrl:LE_Source"} element. + * This test starts with the same metadata than {@link #testSource()} and adds an + * ISO 19115-2 specific property. Consequently the XML name, which was originally + * {@code "mrl:LI_Source"}, shall become {@code "mrl:LE_Source"}. + * + * @throws JAXBException if an error occurred while marshalling the XML. + */ + @Test + @DependsOnMethod("testSource") + public void testSourceImagery() throws JAXBException { + String actual = marshal(create(true)); assertXmlEquals( - "<gmd:LI_Lineage xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gmi=\"" + Namespaces.GMI + '"' + + "<mrl:LI_Lineage xmlns:mrl=\"" + Namespaces.MRL + '"' + + " xmlns:mcc=\"" + Namespaces.MCC + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + + " <mrl:source>\n" + + " <mrl:LE_Source>\n" + + " <mrl:description>\n" + + " <gco:CharacterString>Description of source data level.</gco:CharacterString>\n" + + " </mrl:description>\n" + + " <mrl:processedLevel>\n" + + " <mcc:MD_Identifier>\n" + + " <mcc:code>\n" + + " <gco:CharacterString>DummyLevel</gco:CharacterString>\n" + + " </mcc:code>\n" + + " </mcc:MD_Identifier>\n" + + " </mrl:processedLevel>\n" + + " </mrl:LE_Source>\n" + + " </mrl:source>\n" + + "</mrl:LI_Lineage>", actual, "xmlns:*"); + + verify(unmarshal(DefaultLineage.class, actual)); + } + + /** + * Tests the marshalling of a legacy {@code "gmi:LE_Source"} element. + * This test starts with the same metadata than {@link #testLegacySource()} and adds + * an ISO 19115-2 specific property. Consequently the XML name, which was originally + * {@code "gmd:LI_Source"}, shall become {@code "gmi:LE_Source"}. + * + * @throws JAXBException if an error occurred while marshalling the XML. + */ + @Test + @DependsOnMethod("testLegacySource") + public void testLegacySourceImagery() throws JAXBException { + String actual = marshal(create(true), VERSION_2007); + assertXmlEquals( + "<gmd:LI_Lineage xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' + + " xmlns:gmi=\"" + LegacyNamespaces.GMI + '"' + + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + " <gmd:source>\n" + " <gmi:LE_Source>\n" + " <gmd:description>\n" + @@ -90,5 +181,7 @@ public final strictfp class DefaultLinea " </gmi:LE_Source>\n" + " </gmd:source>\n" + "</gmd:LI_Lineage>", actual, "xmlns:*"); + + verify(unmarshal(DefaultLineage.class, actual)); } } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -19,7 +19,9 @@ package org.apache.sis.metadata.iso.line import javax.xml.bind.JAXBException; import org.apache.sis.util.iso.SimpleInternationalString; import org.apache.sis.internal.jaxb.gmi.LE_ProcessStep; +import org.apache.sis.metadata.iso.DefaultIdentifier; import org.apache.sis.test.XMLTestCase; +import org.apache.sis.util.Version; import org.junit.Test; import static org.opengis.test.Assert.*; @@ -30,17 +32,12 @@ import static org.opengis.test.Assert.*; * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.0 * @since 0.3 * @module */ public final strictfp class DefaultProcessStepTest extends XMLTestCase { /** - * An XML file in this package containing a process step definition. - */ - private static final String XML_FILE = "ProcessStep.xml"; - - /** * Tests the (un)marshalling of a metadata mixing elements from ISO 19115 and ISO 19115-2 standards. * * <p><b>XML test file:</b> @@ -50,21 +47,40 @@ public final strictfp class DefaultProce */ @Test public void testXML() throws JAXBException { + roundtrip("ProcessStep.xml", VERSION_2014); + } + + /** + * Tests the (un)marshalling of a metadata in legacy ISO 19139:2007 document. + * This test uses the same metadata than {@link #testXML()}. + * + * @throws JAXBException if an error occurred during the during marshalling / unmarshalling processes. + */ + @Test + public void testLegacyXML() throws JAXBException { + roundtrip("ProcessStep (legacy).xml", VERSION_2007); + } + + /** + * Tests (un)marshalling in the given version. + */ + private void roundtrip(final String filename, final Version version) throws JAXBException { final DefaultProcessing processing = new DefaultProcessing(); final DefaultProcessStep processStep = new DefaultProcessStep("Some process step."); processing.setProcedureDescription(new SimpleInternationalString("Some procedure.")); + processing.setIdentifier(new DefaultIdentifier("P4")); processStep.setProcessingInformation(processing); /* * XML marshalling, and compare with the content of "ProcessStep.xml" file. */ - assertMarshalEqualsFile(XML_FILE, processStep, "xlmns:*", "xsi:schemaLocation"); + assertMarshalEqualsFile(filename, processStep, version, "xmlns:*", "xsi:schemaLocation"); /* * XML unmarshalling: ensure that we didn't lost any information. * Note that since the XML uses the <gmi:…> namespace, we got an instance of LE_ProcessStep, which * in SIS implementation does not carry any useful information; it is just a consequence of the way * namespaces are managed. We will convert to the parent DefaultProcessStep type before comparison. */ - DefaultProcessStep step = unmarshalFile(DefaultProcessStep.class, XML_FILE); + DefaultProcessStep step = unmarshalFile(DefaultProcessStep.class, filename); assertInstanceOf("The unmarshalled object is expected to be in GMI namespace.", LE_ProcessStep.class, step); step = new DefaultProcessStep(step); assertEquals(processStep, step); Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -18,10 +18,13 @@ package org.apache.sis.metadata.iso.qual import java.util.Locale; import javax.xml.bind.JAXBException; +import org.opengis.metadata.quality.Result; import org.opengis.util.InternationalString; import org.apache.sis.xml.FreeTextMarshallingTest; +import org.apache.sis.util.Version; import org.apache.sis.test.XMLTestCase; import org.apache.sis.test.DependsOn; +import org.junit.Ignore; import org.junit.Test; import static org.opengis.test.Assert.*; @@ -33,18 +36,14 @@ import static org.apache.sis.test.TestUt * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.3 * @module */ @DependsOn(FreeTextMarshallingTest.class) public final strictfp class AbstractPositionalAccuracyTest extends XMLTestCase { /** - * An XML file in this package containing a positional accuracy definition. - */ - private static final String XML_FILE = "PositionalAccuracy.xml"; - - /** * 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. @@ -54,12 +53,34 @@ public final strictfp class AbstractPosi * * @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 <a href="https://issues.apache.org/jira/browse/SIS-394">Issue SIS-394</a> * @see FreeTextMarshallingTest */ @Test + @Ignore("Depends on SIS-394") public void testXML() throws JAXBException { - final AbstractElement metadata = unmarshalFile(AbstractElement.class, XML_FILE); + roundtrip("PositionalAccuracy.xml", VERSION_2014); + } + + /** + * Tests the (un)marshalling of a text group from/to legacy ISO 19139:2007 schema. + * + * @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 <a href="https://issues.apache.org/jira/browse/SIS-399">SIS-399</a> + */ + @Test + public void testLegacyXML() throws JAXBException { + roundtrip("PositionalAccuracy (legacy).xml", VERSION_2007); + } + + /** + * Unmarshals the given file and verify the content. + * Then marshals the object and verify that we get equivalent XML. + */ + private void roundtrip(final String filename, final Version version) throws JAXBException { + final AbstractElement metadata = unmarshalFile(AbstractElement.class, filename); final InternationalString nameOfMeasure = getSingleton(metadata.getNamesOfMeasure()); /* * Programmatic verification of the text group. @@ -72,11 +93,12 @@ public final strictfp class AbstractPosi * 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(metadata.getResults())); + final Result result = getSingleton(metadata.getResults()); + assertInstanceOf("Wrong value for <gmd:result>", DefaultConformanceResult.class, result); + assertEquals("result.pass", Boolean.TRUE, ((DefaultConformanceResult) result).pass()); /* * Marshalling: ensure that we didn't lost any information. */ - assertMarshalEqualsFile(XML_FILE, metadata, "xmlns:*", "xsi:schemaLocation", "xsi:type"); + assertMarshalEqualsFile(filename, metadata, version, "xmlns:*", "xsi:schemaLocation", "xsi:type"); } } Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -94,6 +94,7 @@ import org.junit.BeforeClass; org.apache.sis.metadata.iso.DefaultMetadataTest.class, org.apache.sis.metadata.iso.CustomMetadataTest.class, org.apache.sis.metadata.iso.AllMetadataTest.class, + org.apache.sis.metadata.iso.MarshallingTest.class, org.apache.sis.metadata.iso.APIVerifier.class, org.apache.sis.io.wkt.ConventionTest.class, Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java?rev=1825254&r1=1825253&r2=1825254&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java [UTF-8] Sat Feb 24 16:13:58 2018 @@ -22,6 +22,7 @@ import org.opengis.metadata.Identifier; import org.opengis.metadata.acquisition.Instrument; import org.opengis.metadata.identification.DataIdentification; import org.opengis.metadata.identification.InitiativeType; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.internal.metadata.SensorType; import org.apache.sis.util.iso.Types; import org.apache.sis.test.DependsOnMethod; @@ -35,24 +36,26 @@ import static org.apache.sis.test.Assert * Tests the XML marshalling of {@code Anchor} and {@code CodeList} as substitution of {@code <gco:CharacterSequence>}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.7 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.3 * @module */ public final strictfp class CharSequenceSubstitutionTest extends XMLTestCase { /** - * Tests unmarshalling of anchor in an identifier element. The {@code xlink:href} attribute - * is lost because the Java type of the {@code gmd:code} attribute is {@link String}. + * Tests unmarshalling of {@code "RS_Identifier"} element. This element was defined in legacy ISO 19139:2007 + * but has been removed in ISO 19115-3. That element is extensively used for Coordinate Reference Systems in + * GML 3.2. * * @throws JAXBException if the unmarshalling failed. */ @Test - @DependsOnMethod("testAnchor") - public void testAnchorForString() throws JAXBException { + @DependsOnMethod("testAnchorForString") + public void testLegacy() throws JAXBException { final String expected = - "<gmd:RS_Identifier xmlns:gmx=\"" + Namespaces.GMX + '"' + - " xmlns:gmd=\"" + Namespaces.GMD + '"' + - " xmlns:gco=\"" + Namespaces.GCO + '"' + + "<gmd:RS_Identifier xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' + + " xmlns:gmx=\"" + LegacyNamespaces.GMX + '"' + + " xmlns:gco=\"" + LegacyNamespaces.GCO + '"' + " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" + " <gmd:code>\n" + " <gmx:Anchor xlink:href=\"SDN:L101:2:4326\">EPSG:4326</gmx:Anchor>\n" + @@ -62,7 +65,34 @@ public final strictfp class CharSequence " </gmd:codeSpace>\n" + "</gmd:RS_Identifier>"; - final Identifier id = (Identifier) XML.unmarshal(expected); + final Identifier id = unmarshal(Identifier.class, expected); + assertEquals("codespace", "L101", id.getCodeSpace()); + assertEquals("code", "EPSG:4326", id.getCode()); + } + + /** + * Tests unmarshalling of anchor in an identifier element. The {@code xlink:href} attribute + * is lost because the Java type of the {@code gmd:code} attribute is {@link String}. + * + * @throws JAXBException if the unmarshalling failed. + */ + @Test + @DependsOnMethod("testAnchor") + public void testAnchorForString() throws JAXBException { + final String expected = + "<mdb:MD_Identifier xmlns:mdb=\"" + Namespaces.MDB + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + '"' + + " xmlns:gco=\"" + Namespaces.GCO + '"' + + " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" + + " <mdb:code>\n" + + " <gcx:Anchor xlink:href=\"SDN:L101:2:4326\">EPSG:4326</gcx:Anchor>\n" + + " </mdb:code>\n" + + " <mdb:codeSpace>\n" + + " <gco:CharacterString>L101</gco:CharacterString>\n" + + " </mdb:codeSpace>\n" + + "</mdb:MD_Identifier>"; + + final Identifier id = unmarshal(Identifier.class, expected); assertEquals("codespace", "L101", id.getCodeSpace()); assertEquals("code", "EPSG:4326", id.getCode()); } @@ -76,28 +106,28 @@ public final strictfp class CharSequence @Test public void testAnchor() throws JAXBException { final String expected = - "<gmd:CI_Address xmlns:gmx=\"" + Namespaces.GMX + '"' + - " xmlns:gmd=\"" + Namespaces.GMD + '"' + + "<cit:CI_Address xmlns:cit=\"" + Namespaces.CIT + '"' + + " xmlns:gcx=\"" + Namespaces.GCX + '"' + " xmlns:gco=\"" + Namespaces.GCO + '"' + " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" + - " <gmd:deliveryPoint>\n" + + " <cit:deliveryPoint>\n" + " <gco:CharacterString>Centre IFREMER de Brest BP 70</gco:CharacterString>\n" + - " </gmd:deliveryPoint>\n" + - " <gmd:city>\n" + + " </cit:deliveryPoint>\n" + + " <cit:city>\n" + " <gco:CharacterString>Plouzané</gco:CharacterString>\n" + - " </gmd:city>\n" + - " <gmd:postalCode>\n" + + " </cit:city>\n" + + " <cit:postalCode>\n" + " <gco:CharacterString>29280</gco:CharacterString>\n" + - " </gmd:postalCode>\n" + - " <gmd:country>\n" + - " <gmx:Anchor xlink:href=\"SDN:C320:2:FR\">France</gmx:Anchor>\n" + - " </gmd:country>\n" + - " <gmd:electronicMailAddress>\n" + + " </cit:postalCode>\n" + + " <cit:country>\n" + + " <gcx:Anchor xlink:href=\"SDN:C320:2:FR\">France</gcx:Anchor>\n" + + " </cit:country>\n" + + " <cit:electronicMailAddress>\n" + " <gco:CharacterString>(hiden)@ifremer.fr</gco:CharacterString>\n" + - " </gmd:electronicMailAddress>\n" + - "</gmd:CI_Address>"; + " </cit:electronicMailAddress>\n" + + "</cit:CI_Address>"; - final Address address = (Address) XML.unmarshal(expected); + final Address address = unmarshal(Address.class, expected); assertEquals("Plouzané", address.getCity().toString()); assertEquals("France", address.getCountry().toString()); assertEquals(1, address.getElectronicMailAddresses().size()); @@ -110,7 +140,7 @@ public final strictfp class CharSequence anchor.setType(XLink.Type.AUTO); assertEquals(XLink.Type.LOCATOR, anchor.getType()); - final String actual = XML.marshal(address); + final String actual = marshal(address); assertXmlEquals(expected, actual, "xmlns:*"); } @@ -124,19 +154,19 @@ public final strictfp class CharSequence @Test public void testCodeList() throws JAXBException { final String expected = - "<gmd:MD_DataIdentification xmlns:gmd=\"" + Namespaces.GMD + "\">\n" + - " <gmd:purpose>\n" + - " <gmd:DS_InitiativeTypeCode\n" + - " codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#DS_InitiativeTypeCode\"\n" + - " codeListValue=\"investigation\">Investigation</gmd:DS_InitiativeTypeCode>\n" + - " </gmd:purpose>\n" + - "</gmd:MD_DataIdentification>"; + "<mri:MD_DataIdentification xmlns:mri=\"" + Namespaces.MRI + "\">\n" + + " <mri:purpose>\n" + + " <mri:DS_InitiativeTypeCode\n" + + " codeList=\"http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#DS_InitiativeTypeCode\"\n" + + " codeListValue=\"investigation\">Investigation</mri:DS_InitiativeTypeCode>\n" + + " </mri:purpose>\n" + + "</mri:MD_DataIdentification>"; - final DataIdentification id = (DataIdentification) XML.unmarshal(expected); + final DataIdentification id = unmarshal(DataIdentification.class, expected); assertEquals("purpose", "Investigation", String.valueOf(id.getPurpose())); assertSame("purpose", InitiativeType.INVESTIGATION, Types.forCodeTitle(id.getPurpose())); - final String actual = XML.marshal(id); + final String actual = marshal(id); assertXmlEquals(expected, actual, "xmlns:*"); } @@ -160,7 +190,7 @@ public final strictfp class CharSequence " </gmi:type>\n" + "</gmi:MI_Instrument>"; - final Instrument instrument = (Instrument) XML.unmarshal(expected); + final Instrument instrument = unmarshal(Instrument.class, expected); assertEquals("type", "RADIOMETER", String.valueOf(instrument.getType())); assertInstanceOf("type", SensorType.class, Types.forCodeTitle(instrument.getType())); }
