Search in sources :

Example 6 with MarshallerPool

use of org.apache.sis.xml.MarshallerPool in project sis by apache.

the class DefaultPrimeMeridianTest method testUnarshallGML31.

/**
 * Tests marshalling in the GML 3.1 namespace.
 *
 * @throws JAXBException if an error occurred during unmarshalling.
 */
@Test
@DependsOnMethod("testUnmarshall")
public void testUnarshallGML31() throws JAXBException {
    final MarshallerPool pool = getMarshallerPool();
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    unmarshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);
    final DefaultPrimeMeridian pm = (DefaultPrimeMeridian) unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML));
    pool.recycle(unmarshaller);
    assertIsGreenwich(pm);
}
Also used : MarshallerPool(org.apache.sis.xml.MarshallerPool) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 7 with MarshallerPool

use of org.apache.sis.xml.MarshallerPool in project sis by apache.

the class DefaultVerticalDatumTest method testGML31.

/**
 * Tests (un)marshalling of an older version, GML 3.1.
 *
 * @throws JAXBException if an error occurred during unmarshalling.
 *
 * @see <a href="http://issues.apache.org/jira/browse/SIS-160">SIS-160: Need XSLT between GML 3.1 and 3.2</a>
 */
@Test
public void testGML31() throws JAXBException {
    final Version version = new Version("3.1");
    final MarshallerPool pool = getMarshallerPool();
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    unmarshaller.setProperty(XML.GML_VERSION, version);
    final DefaultVerticalDatum datum = (DefaultVerticalDatum) unmarshaller.unmarshal(getClass().getResource(GML31_FILE));
    pool.recycle(unmarshaller);
    /*
         * Following attribute exists in GML 3.1 only.
         */
    assertEquals("vertDatumType", VerticalDatumType.GEOIDAL, datum.getVerticalDatumType());
    /*
         * The name, anchor definition and domain of validity are lost because
         * those property does not have the same XML element name (SIS-160).
         * Below is all we have.
         */
    assertEquals("remarks", "Approximates geoid.", datum.getRemarks().toString());
    assertEquals("scope", "Hydrography.", datum.getScope().toString());
    /*
         * Test marshaling. We can not yet compare with the original XML file
         * because of all the information lost. This may be fixed in a future
         * SIS version (SIS-160).
         */
    final Marshaller marshaller = pool.acquireMarshaller();
    marshaller.setProperty(XML.GML_VERSION, version);
    final String xml = marshal(marshaller, datum);
    pool.recycle(marshaller);
    assertXmlEquals("<gml:VerticalDatum xmlns:gml=\"" + LegacyNamespaces.GML + "\">\n" + "  <gml:remarks>Approximates geoid.</gml:remarks>\n" + "  <gml:scope>Hydrography.</gml:scope>\n" + "  <gml:verticalDatumType>geoidal</gml:verticalDatumType>\n" + "</gml:VerticalDatum>", xml, "xmlns:*");
}
Also used : Marshaller(javax.xml.bind.Marshaller) Version(org.apache.sis.util.Version) MarshallerPool(org.apache.sis.xml.MarshallerPool) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 8 with MarshallerPool

use of org.apache.sis.xml.MarshallerPool in project sis by apache.

the class NameMarshallingTest method marshal.

/**
 * Returns the XML representation of the given name, wrapped
 * in a mock {@code <gml:IO_IdentifiedObject>} element.
 */
private String marshal(final GenericName name) throws JAXBException {
    if (pool == null) {
        pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), null);
    }
    final Marshaller marshaller = pool.acquireMarshaller();
    marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007);
    final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name));
    pool.recycle(marshaller);
    return xml;
}
Also used : IdentifiedObjectMock(org.apache.sis.test.mock.IdentifiedObjectMock) Marshaller(javax.xml.bind.Marshaller) MarshallerPool(org.apache.sis.xml.MarshallerPool)

Example 9 with MarshallerPool

use of org.apache.sis.xml.MarshallerPool in project sis by apache.

the class MetadataTest method testMarshalling.

/**
 * Tests marshalling of a XML document.
 *
 * @throws Exception if an error occurred during marshalling.
 */
@Test
public void testMarshalling() throws Exception {
    final MarshallerPool pool = getMarshallerPool();
    final Marshaller ms = pool.acquireMarshaller();
    final StringWriter writer = new StringWriter(25000);
    ms.setProperty(XML.METADATA_VERSION, VERSION_2007);
    ms.marshal(createHardCoded(), writer);
    pool.recycle(ms);
    /*
         * Apache SIS can marshal CharSequence as Anchor only if the property type is InternationalString.
         * But the 'Metadata.hierarchyLevelName' and 'Identifier.code' properties are String, which we can
         * not subclass. Concequently SIS currently marshals them as plain string. Replace those strings
         * by the anchor version so we can compare the XML with the "Metadata.xml" file content.
         */
    final StringBuffer xml = writer.getBuffer();
    replace(xml, "<gcol:CharacterString>Common Data Index record</gcol:CharacterString>", "<gmx:Anchor xlink:href=\"SDN:L231:3:CDI\">Common Data Index record</gmx:Anchor>");
    replace(xml, "<gcol:CharacterString>EPSG:4326</gcol:CharacterString>", "<gmx:Anchor xlink:href=\"SDN:L101:2:4326\">EPSG:4326</gmx:Anchor>");
    replace(xml, "License", "Licence");
    /*
         * The <gmd:EX_TemporalExtent> block can not be marshalled yet, since it requires the sis-temporal module.
         * We need to instruct the XML comparator to ignore this block during the comparison. We also ignore for
         * now the "gml:id" attribute since SIS generates different values than the ones in oyr test XML file,
         * and those values may change in future SIS version.
         */
    final XMLComparator comparator = new XMLComparator(getResource(), xml.toString());
    comparator.ignoredNodes.add(LegacyNamespaces.GMD + ":temporalElement");
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.ignoredAttributes.add(Namespaces.XSI + ":schemaLocation");
    comparator.ignoredAttributes.add(Namespaces.GML + ":id");
    comparator.ignoreComments = true;
    comparator.compare();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) XMLComparator(org.apache.sis.test.XMLComparator) MarshallerPool(org.apache.sis.xml.MarshallerPool) Test(org.junit.Test)

Example 10 with MarshallerPool

use of org.apache.sis.xml.MarshallerPool in project sis by apache.

the class MetadataTest method testUnmarshalling.

/**
 * Tests unmarshalling of a XML document.
 *
 * @throws JAXBException if an error occurred during unmarshalling.
 */
@Test
public void testUnmarshalling() throws JAXBException {
    /*
         * Note: if this MetadataTest class is made final, then all following lines
         * until pool.recycle(…) can be replaced by a call to unmarshallFile("Metadata.xml").
         */
    final MarshallerPool pool = getMarshallerPool();
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final DefaultMetadata metadata = (DefaultMetadata) unmarshaller.unmarshal(getResource());
    pool.recycle(unmarshaller);
    if (REGRESSION) {
        assertTrue("Maybe SIS-402 has been fixed and this anti-regression hack can be removed?", metadata.getCharacterSets().add(StandardCharsets.UTF_8));
    }
    final DefaultMetadata expected = createHardCoded();
    assertTrue(metadata.equals(expected, ComparisonMode.DEBUG));
    loggings.skipNextLogIfContains("sis-temporal");
}
Also used : MarshallerPool(org.apache.sis.xml.MarshallerPool) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

MarshallerPool (org.apache.sis.xml.MarshallerPool)16 Marshaller (javax.xml.bind.Marshaller)9 Test (org.junit.Test)7 Unmarshaller (javax.xml.bind.Unmarshaller)5 HashMap (java.util.HashMap)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 BeforeClass (org.junit.BeforeClass)2 StringWriter (java.io.StringWriter)1 XMLComparator (org.apache.sis.test.XMLComparator)1 IdentifiedObjectMock (org.apache.sis.test.mock.IdentifiedObjectMock)1 Version (org.apache.sis.util.Version)1 CitationDate (org.opengis.metadata.citation.CitationDate)1 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)1 BrowseGraphic (org.opengis.metadata.identification.BrowseGraphic)1