Search in sources :

Example 1 with BrowseGraphic

use of org.opengis.metadata.identification.BrowseGraphic in project sis by apache.

the class DefaultBrowseGraphicTest method testStringSubstitution.

/**
 * Tests XML marshalling of filename substituted by {@code <gco:CharacterString>}
 * 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 DefaultBrowseGraphic browse = new DefaultBrowseGraphic(URI.create("file:/catalog/image.png"));
    browse.setFileType("image/tiff");
    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("<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + "  <mcc:fileName>\n" + "    <gco:CharacterString>file:/catalog/image.png</gco:CharacterString>\n" + "  </mcc:fileName>\n" + "  <mcc:fileType>\n" + "    <gco:CharacterString>image/tiff</gco:CharacterString>\n" + "  </mcc:fileType>\n" + "</mcc:MD_BrowseGraphic>", xml, "xmlns:*");
    /*
         * Unmarshal the element back to a Java object and compare to the original.
         */
    assertEquals(browse, unmarshal(BrowseGraphic.class, xml));
}
Also used : Marshaller(javax.xml.bind.Marshaller) MarshallerPool(org.apache.sis.xml.MarshallerPool) BrowseGraphic(org.opengis.metadata.identification.BrowseGraphic) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with BrowseGraphic

use of org.opengis.metadata.identification.BrowseGraphic in project sis by apache.

the class DefaultBrowseGraphicTest method roundtrip.

/**
 * 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));
}
Also used : Version(org.apache.sis.util.Version) BrowseGraphic(org.opengis.metadata.identification.BrowseGraphic)

Aggregations

BrowseGraphic (org.opengis.metadata.identification.BrowseGraphic)2 Marshaller (javax.xml.bind.Marshaller)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Version (org.apache.sis.util.Version)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 Test (org.junit.Test)1